|
NetBurner 3.5.6
PDF Version |
A wrapper for NBString::Interpolate() ideal for easy access to ephemeral values. More...
#include <nbstring.h>
Inherits NBString.
Public Member Functions | |
| NBInterpolatedString () | |
| Construct a NBInterpolatedString object. | |
| NBInterpolatedString (const NBString &str) | |
| Construct a new NBInterpolatedString object from an existing NBInterpolatedString object. | |
| NBInterpolatedString (const NBString &str, size_t pos, size_t len=npos) | |
| Construct a new NBInterpolatedString object from a substring of an existing NBInterpolatedString object. | |
| NBInterpolatedString (const char *s) | |
| Construct a NBInterpolatedString object from a character string (null terminated array of characters) | |
| NBInterpolatedString (const char *s, size_t n) | |
| Construct a NBInterpolatedString object from a character string up to the specified amount. | |
| ~NBInterpolatedString () | |
| NBInterpolatedString destructor. | |
| NBString & | Append (const char *str, size_t len) |
| Append a string to an existing NBString object. | |
| NBString & | FdAppend (int fd, size_t len) |
| Append from a file descriptor to an existing NBString object. | |
| NBInterpolatedString & | Interpolate () |
| Perform a string interpolation in-place. This allows NBStrings to easily access the NetBurner Config System, as in: | |
Public Member Functions inherited from NBString | |
| NBString () | |
| Construct a NBString object. | |
| NBString (const NBString &str) | |
| Construct a new NBString object from an existing NBString object. | |
| NBString (const NBString &str, size_t pos, size_t len=npos) | |
| Construct a new NBString object from a substring of an existing NBString object. | |
| NBString (const char *s) | |
| Construct a NBString object from a character string (null terminated array of characters) | |
| NBString (const char *s, size_t n) | |
| Construct a NBString object from a character string up to the specified amount. | |
| NBString (const JsonRef &jr) | |
| Construct a NBString object using the current string referenced by a JsonRef. This allows for using Large Strings without an intermediate malloc in the JsonParser. | |
| ~NBString () | |
| NBString destructor. | |
| const char * | c_str () const |
| Method to pass a NBString as a constant char *. | |
| NBString | substr (size_t pos=0, size_t len=npos) const |
| Creates a new NBString object from a substring of the existing NBString object. | |
| int | compare (const NBString &str) const |
| Compares two NBString objects. | |
| int | compare (const char *s) const |
| Compares the NBString object to a character string. | |
| size_t | find (const NBString str, size_t pos=0) const |
| Find a substring within a NBString object. | |
| size_t | find (const char *str, size_t pos=0) const |
| Find a substring within a character string. | |
| size_t | find (const char *s, size_t pos, size_t n) const |
| Find a substring within a character string. | |
| size_t | find (char c, size_t pos=0) const |
| Find the first occurence of a character within the NBString object. | |
| size_t | replace (const char *findStr, char rep, size_t startPos=0, size_t end=0) |
| Replace all occurrences of all "<findStr>" characters within the NBString object. | |
| size_t | replace (char c, char rep, size_t startPos=0, size_t end=0) |
| Replace all occurrences of all "<findStr>" characters within the NBString object. | |
| void | shrink (int n) |
| Reduces the length of the string by n. | |
| size_t | size () const |
| Returns the current size of memory allocated for the string. | |
| size_t | length () const |
| Returns the length of the string. | |
| void | clear () |
| Clear a NBString object and free allocated memory. | |
| bool | empty () const |
| Check if a string is empty. | |
| NBString & | Append (const char *str, size_t len) |
| Append a string to an existing NBString object. | |
| NBString & | FdAppend (int fd, size_t len) |
| Append from a file descriptor to an existing NBString object. | |
| NBString & | Reserve (size_t len) |
| Reserve an additional buffer amount. | |
| int | vsiprintf (const char *format, va_list &vl) |
| Print to a string with formatting. | |
| int | sprintf (const char *format,...) |
| sprintf to a string with formatting to a character array | |
| int | sprintf (NBString const format,...) |
| sprintf to a string with formatting as a NBString object | |
| int | siprintf (const char *format,...) |
| isprintf (integer) to a string with formatting to a character array | |
| int | siprintf (NBString const format,...) |
| isprintf (integer) to a string with formatting to a NBString object | |
| int | stoi () const |
| Parse the string and convert to an integer number. | |
| long | stol () const |
| Parse the string value and convert to a long integer number. | |
| unsigned int | stoui () const |
| Parse the string value and convert to a const integer number. | |
| unsigned long | stoul () const |
| Parse the string value and convert to a const unsigned long integer number. | |
| double | stod () const |
| Parse the string value and convert to a const double float number. | |
| IPADDR | to_ipaddr () const |
| Parse the string value and convert to an IPADDR IP address. | |
| size_t | copy (char *s, size_t len, size_t pos=0) const |
| Copy a substring, does not null terminate. | |
| size_t | strcopy (char *s, size_t len, size_t pos=0) const |
| Copy a substring, with null termination. | |
| bool | Interpolate (NBString &dest) |
| Perform a string interpolation and place the finished interpolation in the Destination string. This allows NBStrings to easily access the NetBurner Config System, as in: | |
| bool | Interpolate () |
| Perform an in-place string interpolation. This allows NBStrings to easily access the NetBurner Config System, as in: | |
A wrapper for NBString::Interpolate() ideal for easy access to ephemeral values.
The NetBurner string interpolation system is a powerful and easy way to read system data and should be used carefully. For example, it would be unwise to allow untrusted user input to affect these interpolation commands, in case there is any information in the Config system that you don't want public. Normal sanity checking of regular user input is also advisable.
Syntax is similar to vim or ex commands, but simplified. There are currently two commands:
d deletes matching substringss replaces matching substrings{ and } surround the interpolation command including any Config system variable name/path. Colons separate names, commands, and arguments. Semicolons allow command chaining. {{ or }} are escaped curly braces. \: can escape colons (actually "\\:" when writing C++ code, since \ is also a C++ escape character)
For example, if the config variable AppData.foo is "a_b_c_d", then
Would result in example equalling "abcd".
Commands can be chained with ; – if the config variable AppData.foo is "2_3_4_5es", then
Would result in example equalling "potatoes".
Commands are processed from left to right. If the config same variable AppData.foo of "2_3_4_5es" is interpolated like this:
It would instead would yield "2345es".
In our PubSub, Config, and SubHandler MQTT examples, we remove the first three octets of a known MAC address as well as the remaining semicolons with an interpolator like this: {Sys.NetIf.Ethernet0.MAC:d:00\\:03\\:F4\\:;d:\\:}
In order, this is does the following:
Sys.NetIf.Ethernet0.MAC obtains the matching Config string (visible at http://<your device ip or hostname>:20034/UI.html): separates commands from config variable pathd: delete the following literal substring:00\\:03\\:F4\\: "00:03:F4:"; end command, begin new command with previous command's output as inputd: delete the following literal substring:\\: any/all colons remaining in the stringThus a MAC address like 00:03:F4:12:34:56 will become 123456 in the resulting output.
| NBInterpolatedString::NBInterpolatedString | ( | const NBString & | str | ) |
Construct a new NBInterpolatedString object from an existing NBInterpolatedString object.
| str | Existing NBInterpolatedString object |
| NBInterpolatedString::NBInterpolatedString | ( | const NBString & | str, |
| size_t | pos, | ||
| size_t | len = npos ) |
Construct a new NBInterpolatedString object from a substring of an existing NBInterpolatedString object.
| str | Existing NBInterpolatedString object |
| pos | Starting position to copy |
| len | Ending position to copy |
| NBInterpolatedString::NBInterpolatedString | ( | const char * | s | ) |
Construct a NBInterpolatedString object from a character string (null terminated array of characters)
| s | String to initialize object |
| NBInterpolatedString::NBInterpolatedString | ( | const char * | s, |
| size_t | n ) |
Construct a NBInterpolatedString object from a character string up to the specified amount.
| s | String to initialize object |
| n | Number of characters to copy |
| NBString & NBInterpolatedString::Append | ( | const char * | str, |
| size_t | len ) |
| NBString & NBInterpolatedString::FdAppend | ( | int | fd, |
| size_t | len ) |
| NBInterpolatedString & NBInterpolatedString::Interpolate | ( | ) |
Perform a string interpolation in-place. This allows NBStrings to easily access the NetBurner Config System, as in: