AceCommon
1.4.5
Arduino library for low-level common functions and features with no external dependencies
|
A wrapper class around a normal c-string or Arduino f-string which is encoded and compressed using keyword substitution. More...
#include <KString.h>
Public Member Functions | |
KString (const char *s, const char *const *keywords, uint8_t numKeywords) | |
Constructor around a simple c-string. More... | |
KString (const __FlashStringHelper *fs, const char *const *keywords, uint8_t numKeywords) | |
Constructor around an Arduino Flash string. | |
int | compareTo (const char *s) |
Compare this string against s and return <0 , 0 or >0 if this string is less than, equal to, or greater than the target string s . | |
void | printTo (Print &printer) |
Expand and print the current string to the given printer. | |
A wrapper class around a normal c-string or Arduino f-string which is encoded and compressed using keyword substitution.
The keywords are encoded as non-printable ASCII characters between 0x01 and 0x1f (all below the space character 0x20). The 0x00 character cannot be used since it is the NUL character that terminates the string. The list of keywords are given in the keywords
array.
The number of keywords is obviously limited to 31, which happens to be sufficient for my needs. An alternative implementation is to use the high bit characters (0x80 - 0xff) which gives us 128 keywords, but I don't need that right now.
This class is expected to have a short lifetype. In normal usage, it is created on the stack, the compareTo() or printTo() is function called, then it is auto-destroyed at the end of its scope.
|
inlineexplicit |
Constructor around a simple c-string.
s | NUL terminated string, cannot be nullptr |
keywords | an array of keywords, with nullptr in index position 0 |
numKeywords | number of keywords, including the nullptr in the 0th position. If greater than 32, will be truncated to 32. |