rspamd_text
This module provides access to opaque text structures used widely to prevent copying between Lua and C for various concerns: performance, security etc…
You can convert rspamd_text into string but it will copy data.
Functions:
Function | Description |
---|---|
rspamd_text.fromstring(str) |
Creates rspamd_text from Lua string (copied to the text). |
rspamd_text.null() |
Creates rspamd_text with NULL pointer for testing purposes. |
rspamd_text.randombytes(nbytes) |
Creates rspamd_text with random bytes inside (raw bytes). |
rspamd_text.fromtable(tbl[, delim]) |
Same as table.concat but generates rspamd_text instead of the Lua string. |
Methods:
Method | Description |
---|---|
rspamd_text:byte(pos[, pos2]) |
Returns a byte at the position pos or bytes from pos to pos2 if specified. |
rspamd_text:len() |
Returns length of a string. |
rspamd_text:str() |
Converts text to string by copying its content. |
rspamd_text:ptr() |
Converts text to lightuserdata. |
rspamd_text:save_in_file(fname[, mode]) |
Saves text in file. |
rspamd_text:span(start[, len]) |
Returns a span for lua_text starting at pos [start] (1 indexed) and with. |
rspamd_text:sub(start[, len]) |
Returns a substring for lua_text similar to string.sub from Lua. |
rspamd_text:lines([stringify]) |
Returns an iter over all lines as rspamd_text objects or as strings if stringify is true. |
rspamd_text:split(regexp, [stringify]) |
Returns an iter over all encounters of the specific regexp as rspamd_text objects or as strings if stringify is true. |
rspamd_text:at(pos) |
Returns a byte at the position pos . |
rspamd_text:memchr(chr, [reverse]) |
Returns the first or the last position of the character chr in the text or. |
rspamd_text:bytes() |
Converts text to an array of bytes. |
rspamd_text:lower([is_utf, [inplace]]) |
Return a new text with lowercased characters, if is_utf is true then Rspamd applies utf8 lowercase. |
rspamd_text:exclude_chars(set_to_exclude, [always_copy]) |
Returns a text (if owned, then the original text is modified, if not, then it is copied and owned). |
rspamd_text:oneline([always_copy]) |
Returns a text (if owned, then the original text is modified, if not, then it is copied and owned). |
rspamd_text:base32([b32type]) |
Returns a text encoded in base32 (new rspamd_text is allocated). |
rspamd_text:base64([line_length, [nline, [fold]]]) |
Returns a text encoded in base64 (new rspamd_text is allocated). |
rspamd_text:hex() |
Returns a text encoded in hex (new rspamd_text is allocated). |
rspamd_text:find(pattern [, init]) |
Looks for the first match of pattern in the string s. |
The module rspamd_text
defines the following functions.
rspamd_text.fromstring(str)
Creates rspamd_text from Lua string (copied to the text)
Parameters:
str {string}
: string to useReturns:
{rspamd_text}
: resulting textBack to module description.
rspamd_text.null()
Creates rspamd_text with NULL pointer for testing purposes
Parameters:
str {string}
: string to useReturns:
{rspamd_text}
: resulting textBack to module description.
rspamd_text.randombytes(nbytes)
Creates rspamd_text with random bytes inside (raw bytes)
Parameters:
nbytes {number}
: number of random bytes generatedReturns:
{rspamd_text}
: random bytes textBack to module description.
rspamd_text.fromtable(tbl[, delim])
Same as table.concat
but generates rspamd_text instead of the Lua string
Parameters:
tbl {table}
: table to usedelim {string}
: optional delimiterReturns:
{rspamd_text}
: resulting textBack to module description.
The module rspamd_text
defines the following methods.
rspamd_text:byte(pos[, pos2])
Returns a byte at the position pos
or bytes from pos
to pos2
if specified
Parameters:
pos {integer}
: indexpos2 {integer}
: indexReturns:
{integer}
: byte at the position pos
or varargs of bytesBack to module description.
rspamd_text:len()
Returns length of a string
Parameters:
No parameters
Returns:
{number}
: length of string in bytesBack to module description.
rspamd_text:str()
Converts text to string by copying its content
Parameters:
No parameters
Returns:
{string}
: copy of text as Lua stringBack to module description.
rspamd_text:ptr()
Converts text to lightuserdata
Parameters:
No parameters
Returns:
{lightuserdata}
: pointer value of rspamd_textBack to module description.
rspamd_text:save_in_file(fname[, mode])
Saves text in file
Parameters:
No parameters
Returns:
{boolean}
: true if save has been completedBack to module description.
rspamd_text:span(start[, len])
Returns a span for lua_text starting at pos [start] (1 indexed) and with
length len
(or to the end of the text)
Parameters:
start {integer}
: start indexlen {integer}
: length of spanReturns:
{rspamd_text}
: new rspamd_text with span (must be careful when using with owned texts…)Back to module description.
rspamd_text:sub(start[, len])
Returns a substring for lua_text similar to string.sub from Lua
Parameters:
No parameters
Returns:
{rspamd_text}
: new rspamd_text with span (must be careful when using with owned texts…)Back to module description.
rspamd_text:lines([stringify])
Returns an iter over all lines as rspamd_text objects or as strings if stringify
is true
Parameters:
stringify {boolean}
: stringify linesReturns:
{iterator}
: iterator tripletBack to module description.
rspamd_text:split(regexp, [stringify])
Returns an iter over all encounters of the specific regexp as rspamd_text objects or as strings if stringify
is true
Parameters:
regexp {rspamd_regexp}
: regexp (pcre syntax) used for splittingstringify {boolean}
: stringify linesReturns:
{iterator}
: iterator tripletBack to module description.
rspamd_text:at(pos)
Returns a byte at the position pos
Parameters:
pos {integer}
: indexReturns:
{integer}
: byte at the position pos
or nil if pos out of boundBack to module description.
rspamd_text:memchr(chr, [reverse])
Returns the first or the last position of the character chr
in the text or
-1 in case if a character has not been found. Indexes start from 1
Parameters:
chr {string/number}
: character or a character code to findreverse {boolean}
: last character if true
Returns:
{integer}
: position of the character or -1
Back to module description.
rspamd_text:bytes()
Converts text to an array of bytes
Parameters:
No parameters
Returns:
{table|integer}
: bytes in the array (as unsigned char)Back to module description.
rspamd_text:lower([is_utf, [inplace]])
Return a new text with lowercased characters, if is_utf is true then Rspamd applies utf8 lowercase
Parameters:
is_utf {boolean}
: apply utf8 lowercaseinplace {boolean}
: lowercase the original textReturns:
{rspamd_text}
: new rspamd_text (or the original text if inplace) with lowercased lettersBack to module description.
rspamd_text:exclude_chars(set_to_exclude, [always_copy])
Returns a text (if owned, then the original text is modified, if not, then it is copied and owned)
where all chars from set_to_exclude
are removed
Patterns supported:
Parameters:
set_to_exclude {string}
: characters to excludealways_copy {boolean}
: always copy the source textReturns:
{rspamd_text}
: modified or copied textBack to module description.
rspamd_text:oneline([always_copy])
Returns a text (if owned, then the original text is modified, if not, then it is copied and owned) where the following transformations are made:
Parameters:
always_copy {boolean}
: always copy the source textReturns:
{rspamd_text}
: modified or copied textBack to module description.
rspamd_text:base32([b32type])
Returns a text encoded in base32 (new rspamd_text is allocated)
Parameters:
b32type {string}
: base32 type (default, bleach, rfc)Returns:
{rspamd_text}
: new text encoded in base32Back to module description.
rspamd_text:base64([line_length, [nline, [fold]]])
Returns a text encoded in base64 (new rspamd_text is allocated)
Parameters:
line_length {number}
: return text split with newlines up to this attributenline {string}
: newline type: cr
, lf
, crlf
fold {boolean}
: use folding when splitting into lines (false by default)Returns:
{rspamd_text}
: new text encoded in base64Back to module description.
rspamd_text:hex()
Returns a text encoded in hex (new rspamd_text is allocated)
Parameters:
No parameters
Returns:
{rspamd_text}
: new text encoded in hexBack to module description.
rspamd_text:find(pattern [, init])
Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. This method currently supports merely a plain search, no patterns.
Parameters:
pattern {string}
: pattern to findinit {number}
: specifies where to start the search (1 default)Returns:
{number,number/nil}
: If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nilBack to module description.
Back to top.