AceCommon  1.4.6
Arduino library for low-level common functions and features with no external dependencies
Public Member Functions | 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 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.
 

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 51 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, cannot be nullptr
keywordsan array of keywords, with nullptr in index position 0
numKeywordsnumber of keywords, including the nullptr in the 0th position. If greater than 32, will be truncated to 32.

Definition at line 61 of file KString.h.


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