KiCad PCB EDA Suite
numEval::UTF8 Class Reference

Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and from wxString, to and from std::string, and has non-mutating iteration over unicode characters. More...

Classes

class  uni_iter
 class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string. More...
 

Public Member Functions

 UTF8 (const wxString &o)
 
 UTF8 (const char *txt)
 This is a constructor for which you could end up with non-UTF8 encoding, but that would be your fault. More...
 
 UTF8 (const wchar_t *txt)
 For use with _() function on wx 2.8. More...
 
 UTF8 (const std::string &o)
 
 UTF8 ()
 
 ~UTF8 ()
 
const char * c_str () const
 
bool empty () const
 
std::string::size_type find (char c) const
 
std::string::size_type find (char c, size_t &s) const
 
void clear ()
 
std::string::size_type length () const
 
std::string::size_type size () const
 
int compare (const std::string &s) const
 
bool operator== (const UTF8 &rhs) const
 
bool operator== (const std::string &rhs) const
 
bool operator== (const char *s) const
 
std::string::size_type find_first_of (const std::string &str, std::string::size_type pos=0) const
 
UTF8operator+= (const UTF8 &str)
 
UTF8operator+= (char ch)
 
UTF8operator+= (const char *s)
 
UTF8operator+= (unsigned w_ch)
 Append a wide (unicode) char to the UTF8 string. More...
 
UTF8operator= (const wxString &o)
 
UTF8operator= (const std::string &o)
 
UTF8operator= (const char *s)
 
UTF8operator= (char c)
 
std::string substr (size_t pos=0, size_t len=npos) const
 
 operator const std::string & () const
 
wxString wx_str () const
 
 operator wxString () const
 
std::string::const_iterator begin () const
 
std::string::const_iterator end () const
 
uni_iter ubegin () const
 Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence. More...
 
uni_iter uend () const
 Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence. More...
 

Static Public Member Functions

static int uni_forward (const unsigned char *aSequence, unsigned *aResult=NULL)
 Function uni_forward advances over a single UTF8 encoded multibyte character, capturing the unicode character as it goes, and returning the number of bytes consumed. More...
 

Static Public Attributes

static constexpr std::string::size_type npos = -1
 

Protected Attributes

std::string m_s
 

Detailed Description

Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and from wxString, to and from std::string, and has non-mutating iteration over unicode characters.

I've been careful to supply only conversion facilities and not try and duplicate wxString() with many member functions. There are multiple ways to create text into a std::string without the need of too many member functions:

Because this class used no virtuals, it should be possible to cast any std::string into a UTF8 using this kind of cast: (UTF8 &) without construction or copying being the effect of the cast. Be sure the source std::string holds UTF8 encoded text before you do that.

Author
Dick Hollenbeck

Definition at line 74 of file numeric_evaluator.cpp.

Constructor & Destructor Documentation

numEval::UTF8::UTF8 ( const wxString &  o)
numEval::UTF8::UTF8 ( const char *  txt)
inline

This is a constructor for which you could end up with non-UTF8 encoding, but that would be your fault.

Definition at line 82 of file numeric_evaluator.cpp.

86 {
numEval::UTF8::UTF8 ( const wchar_t *  txt)

For use with _() function on wx 2.8.

BTW _() on wx >= 2.9 returns wxString, not wchar_t* like on 2.8.

numEval::UTF8::UTF8 ( const std::string &  o)
inline

Definition at line 92 of file numeric_evaluator.cpp.

97 {
numEval::UTF8::UTF8 ( )
inline

Definition at line 98 of file numeric_evaluator.cpp.

numEval::UTF8::~UTF8 ( )
inline

Definition at line 102 of file numeric_evaluator.cpp.

Member Function Documentation

std::string::const_iterator numEval::UTF8::begin ( ) const
inline

Definition at line 197 of file numeric_evaluator.cpp.

200 {
const char* numEval::UTF8::c_str ( ) const
inline

Definition at line 108 of file numeric_evaluator.cpp.

void numEval::UTF8::clear ( )
inline

Definition at line 114 of file numeric_evaluator.cpp.

int numEval::UTF8::compare ( const std::string &  s) const
inline

Definition at line 117 of file numeric_evaluator.cpp.

bool numEval::UTF8::empty ( ) const
inline

Definition at line 109 of file numeric_evaluator.cpp.

std::string::const_iterator numEval::UTF8::end ( ) const
inline

Definition at line 198 of file numeric_evaluator.cpp.

200 {
std::string::size_type numEval::UTF8::find ( char  c) const
inline

Definition at line 111 of file numeric_evaluator.cpp.

std::string::size_type numEval::UTF8::find ( char  c,
size_t &  s 
) const
inline

Definition at line 112 of file numeric_evaluator.cpp.

113 {
std::string::size_type numEval::UTF8::find_first_of ( const std::string &  str,
std::string::size_type  pos = 0 
) const
inline

Definition at line 123 of file numeric_evaluator.cpp.

125 {
126  return m_originalText;
std::string::size_type numEval::UTF8::length ( ) const
inline

Definition at line 115 of file numeric_evaluator.cpp.

numEval::UTF8::operator const std::string & ( ) const
inline

Definition at line 188 of file numeric_evaluator.cpp.

195 {
numEval::UTF8::operator wxString ( ) const
UTF8& numEval::UTF8::operator+= ( const UTF8 str)
inline

Definition at line 128 of file numeric_evaluator.cpp.

131 {
132  // Feed parser token after token until end of input.
133 
UTF8& numEval::UTF8::operator+= ( char  ch)
inline

Definition at line 135 of file numeric_evaluator.cpp.

140  {
UTF8& numEval::UTF8::operator+= ( const char *  s)
inline

Definition at line 142 of file numeric_evaluator.cpp.

146  {
147  tok = getToken();
UTF8& numEval::UTF8::operator+= ( unsigned  w_ch)

Append a wide (unicode) char to the UTF8 string.

if this wide char is not a ASCII7 char, it will be added as a UTF8 multibyte seqence

Parameters
w_chis a UTF-16 value (can be a UTF-32 on Linux)
UTF8& numEval::UTF8::operator= ( const wxString &  o)
UTF8& numEval::UTF8::operator= ( const std::string &  o)
inline

Definition at line 160 of file numeric_evaluator.cpp.

163 {
164  Clear();
165 
UTF8& numEval::UTF8::operator= ( const char *  s)
inline

Definition at line 167 of file numeric_evaluator.cpp.

UTF8& numEval::UTF8::operator= ( char  c)
inline

Definition at line 174 of file numeric_evaluator.cpp.

179 {
bool numEval::UTF8::operator== ( const UTF8 rhs) const
inline

Definition at line 119 of file numeric_evaluator.cpp.

119 {
bool numEval::UTF8::operator== ( const std::string &  rhs) const
inline

Definition at line 120 of file numeric_evaluator.cpp.

bool numEval::UTF8::operator== ( const char *  s) const
inline

Definition at line 121 of file numeric_evaluator.cpp.

std::string::size_type numEval::UTF8::size ( ) const
inline

Definition at line 116 of file numeric_evaluator.cpp.

std::string numEval::UTF8::substr ( size_t  pos = 0,
size_t  len = npos 
) const
inline

Definition at line 183 of file numeric_evaluator.cpp.

195  {
uni_iter numEval::UTF8::ubegin ( ) const
inline

Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.

Definition at line 286 of file numeric_evaluator.cpp.

288  {
289  // VALUE
uni_iter numEval::UTF8::uend ( ) const
inline

Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.

Definition at line 295 of file numeric_evaluator.cpp.

295  {
296  // UNIT
297  // Units are appended to a VALUE.
298  // Determine factor to default unit if unit for value is given.
static int numEval::UTF8::uni_forward ( const unsigned char *  aSequence,
unsigned *  aResult = NULL 
)
static

Function uni_forward advances over a single UTF8 encoded multibyte character, capturing the unicode character as it goes, and returning the number of bytes consumed.

Parameters
aSequenceis the UTF8 byte sequence, must be aligned on start of character.
aResultis where to put the unicode character, and may be NULL if no interest.
Returns
int - the count of bytes consumed.
wxString numEval::UTF8::wx_str ( ) const

Member Data Documentation

std::string numEval::UTF8::m_s
protected

Definition at line 313 of file numeric_evaluator.cpp.

constexpr std::string::size_type numEval::UTF8::npos = -1
static

Definition at line 156 of file numeric_evaluator.cpp.


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