25 #ifndef ACE_COMMON_KSTRING_H
26 #define ACE_COMMON_KSTRING_H
29 class __FlashStringHelper;
32 namespace ace_common {
34 class KStringIterator;
68 const char*
const* keywords,
74 numKeywords_(numKeywords > 0x20 ? 0x20 : numKeywords)
79 const __FlashStringHelper* fs,
80 const char*
const* keywords,
86 numKeywords_(numKeywords > 0x20 ? 0x20 : numKeywords)
108 static const uint8_t kTypeCstring = 0;
109 static const uint8_t kTypeFstring = 1;
113 const void*
const string_;
114 const char*
const*
const keywords_;
116 uint8_t
const numKeywords_;
132 firstType_(ks.type_),
133 secondType_(
KString::kTypeCstring),
134 firstPtr_((const char*) ks.string_),
150 char c = getInternal(firstType_, firstPtr_);
152 if (secondPtr_ !=
nullptr) {
154 firstType_ = secondType_;
155 firstPtr_ = secondPtr_;
156 secondPtr_ =
nullptr;
160 c = getInternal(firstType_, firstPtr_);
164 if (c !=
'\0' && c < 0x20) {
166 secondType_ = firstType_;
167 secondPtr_ = firstPtr_;
168 firstType_ = KString::kTypeCstring;
169 firstPtr_ = ks_.keywords_[(uint8_t) c];
170 c = getInternal(firstType_, firstPtr_);
179 static char getInternal(uint8_t type,
const char* p) {
180 return (type == KString::kTypeCstring) ? *p : pgm_read_byte(p);
188 const char* firstPtr_;
189 const char* secondPtr_;
An interator that points to a character inside a KString.
KStringIterator(const KString &ks)
Constructor.
void next()
Advance the iterator one character,.
char get()
Return the current character referenced by the iterator.
A wrapper class around a normal c-string or Arduino f-string which is encoded and compressed using ke...
void printTo(Print &printer)
Expand and print the current string to the given printer.
int compareTo(const char *s)
Compare this string against a c-string s and return <0, 0 or >0 if this string is <,...
KString(const char *s, const char *const *keywords, uint8_t numKeywords)
Constructor around a simple c-string.
KString(const __FlashStringHelper *fs, const char *const *keywords, uint8_t numKeywords)
Constructor around an Arduino Flash string.