KiCad PCB EDA Suite
utf8.cpp File Reference
#include <utf8.h>
#include <ki_exception.h>
#include <wx/strconv.h>
#include <wx/buffer.h>
#include <vector>
#include <assert.h>

Go to the source code of this file.

Functions

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

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 173 of file utf8.cpp.

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

174 {
175  int len = strlen( aString );
176 
177  if( len )
178  {
179  const unsigned char* next = (unsigned char*) aString;
180  const unsigned char* end = next + len;
181 
182  try
183  {
184  while( next < end )
185  {
186  next += UTF8::uni_forward( next, NULL );
187  }
188 
189  // uni_forward() should find the exact end if it is truly UTF8
190  if( next > end )
191  return false;
192  }
193  catch( const IO_ERROR& )
194  {
195  return false;
196  }
197  }
198 
199  return true;
200 }
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:73
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