AceCommon
1.6.0
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 __FlashStringHelper *const *keywords, uint8_t numKeywords) | |
Constructor around an Arduino Flash string. More... | |
int | compareTo (const char *s) |
Compare this string against a c-string s and return <0 , 0 or >0 if this string is < , == , or > compared to the target string s . More... | |
int | compareTo (const KString &s) |
Compare this string against another KString s and return <0 , 0 or >0 if this string is < , == , or > compared to the target string s . | |
void | printTo (Print &printer) |
Expand and print the current string to the given printer. | |
Friends | |
class | KStringIterator |
class | KStringKeywords |
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 or nullptr |
keywords | an array of keywords, up to 32 slots. The first slot at index 0 should be nullptr since it cannot be used. |
numKeywords | number of keywords, including the nullptr in the 0th position. If greater than 32, will be truncated to 32. |
|
inlineexplicit |
Constructor around an Arduino Flash string.
The Arduino type system does not have a way to properly represent keywords
. This parameter points to a location in flash memory, which contains an array of pointers to strings also in flash memory. With the current type system, keywords
looks like a pointer to normal memory, which contains an array of flash memory strings.
int ace_common::KString::compareTo | ( | const char * | s | ) |
Compare this string against a c-string s
and return <0
, 0
or >0
if this string is <
, ==
, or >
compared to the target string s
.
A nullptr is considered to be smaller than any non-null string, including the empty string.
Definition at line 7 of file KString.cpp.