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

Go to the source code of this file.

Classes

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

Macros

#define MAYBE_VERIFY_UTF8(x)
 

Functions

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 next(), and UTF8::uni_forward().

171 {
172  int len = strlen( aString );
173 
174  if( len )
175  {
176  const unsigned char* next = (unsigned char*) aString;
177  const unsigned char* end = next + len;
178 
179  try
180  {
181  while( next < end )
182  {
183  next += UTF8::uni_forward( next, NULL );
184  }
185 
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& ioe )
191  {
192  return false;
193  }
194  }
195 
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:47