KiCad PCB EDA Suite
utf8.h File Reference
#include <string>
#include <wx/string.h>

Go to the source code of this file.


class  UTF8
 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...
class  UTF8::uni_iter
 class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string. More...


#define MAYBE_VERIFY_UTF8(x)


bool IsUTF8 (const char *aString)
 Function IsUTF8 tests a c-string to see if it is UTF8 encoded. More...

Macro Definition Documentation

#define MAYBE_VERIFY_UTF8 (   x)

Definition at line 47 of file utf8.h.

Referenced by UTF8::operator+=(), UTF8::operator=(), and UTF8::UTF8().

Function Documentation

bool IsUTF8 ( const char *  aString)

Function IsUTF8 tests a c-string to see if it is UTF8 encoded.

BTW an ASCII string is a valid UTF8 string.

Definition at line 170 of file utf8.cpp.

References UTF8::end(), next(), and UTF8::uni_forward().

171 {
172  int len = strlen( aString );
174  if( len )
175  {
176  const unsigned char* next = (unsigned char*) aString;
177  const unsigned char* end = next + len;
179  try
180  {
181  while( next < end )
182  {
183  next += UTF8::uni_forward( next, NULL );
184  }
186  // uni_forward() should find the exact end if it is truly UTF8
187  if( next > end )
188  return false;
189  }
190  catch( const IO_ERROR& )
191  {
192  return false;
193  }
194  }
196  return true;
197 }
CITER next(CITER it)
Definition: ptree.cpp:130
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 c...
Definition: utf8.cpp:70
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76