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

Go to the source code of this file.

Functions

bool IsUTF8 (const char *aString)
 Test a C string to see if it is UTF8 encoded. More...
 

Function Documentation

◆ IsUTF8()

bool IsUTF8 ( const char *  aString)

Test a C string to see if it is UTF8 encoded.

An ASCII string is a valid UTF8 string.

Definition at line 180 of file utf8.cpp.

181 {
182  int len = strlen( aString );
183 
184  if( len )
185  {
186  const unsigned char* next = (unsigned char*) aString;
187  const unsigned char* end = next + len;
188 
189  while( next < end )
190  {
191  int charLen = UTF8::uni_forward( next, nullptr );
192 
193  if( charLen == 0 )
194  return false;
195 
196  next += charLen;
197  }
198 
199  // uni_forward() should find the exact end if it is truly UTF8
200  if( next > end )
201  return false;
202  }
203 
204  return true;
205 }
CITER next(CITER it)
Definition: ptree.cpp:126
static int uni_forward(const unsigned char *aSequence, unsigned *aResult=nullptr)
Advance over a single UTF8 encoded multibyte character, capturing the Unicode character as it goes,...
Definition: utf8.cpp:68

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