AceCommon  1.5.2
Arduino library for low-level common functions and features with no external dependencies
Public Member Functions | Friends | List of all members
ace_common::KString Class Reference

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 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
 

Detailed Description

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.

Definition at line 53 of file KString.h.

Constructor & Destructor Documentation

◆ KString()

ace_common::KString::KString ( const char *  s,
const char *const *  keywords,
uint8_t  numKeywords 
)
inlineexplicit

Constructor around a simple c-string.

Parameters
sNUL terminated string or nullptr
keywordsan array of keywords, up to 32 slots. The first slot at index 0 should be nullptr since it cannot be used.
numKeywordsnumber of keywords, including the nullptr in the 0th position. If greater than 32, will be truncated to 32.

Definition at line 66 of file KString.h.

Member Function Documentation

◆ compareTo()

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.


The documentation for this class was generated from the following files: