KiCad PCB EDA Suite
Loading...
Searching...
No Matches
UTF8 Class Reference

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

#include <utf8.h>

Classes

class  uni_iter
 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
 Returns a uni_iter initialized to the start of "this" UTF8 byte sequence. More...
 
uni_iter uend () const
 Return 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=nullptr)
 Advance 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

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

Definition at line 70 of file utf8.h.

Constructor & Destructor Documentation

◆ UTF8() [1/5]

UTF8::UTF8 ( const wxString &  o)

Definition at line 39 of file utf8.cpp.

◆ UTF8() [2/5]

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 77 of file utf8.h.

References c_str(), and MAYBE_VERIFY_UTF8.

◆ UTF8() [3/5]

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.

Definition at line 207 of file utf8.cpp.

References m_s.

◆ UTF8() [4/5]

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

Definition at line 87 of file utf8.h.

References c_str(), and MAYBE_VERIFY_UTF8.

◆ UTF8() [5/5]

UTF8::UTF8 ( )
inline

Definition at line 93 of file utf8.h.

◆ ~UTF8()

UTF8::~UTF8 ( )
inline

Definition at line 97 of file utf8.h.

Member Function Documentation

◆ begin()

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

Definition at line 192 of file utf8.h.

References m_s.

Referenced by LIB_TABLE::FormatOptions().

◆ c_str()

◆ clear()

void UTF8::clear ( )
inline

Definition at line 108 of file utf8.h.

References m_s.

Referenced by LIB_ID::clear().

◆ compare()

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

Definition at line 111 of file utf8.h.

References m_s.

Referenced by LIB_ID::compare(), and SCH_REFERENCE::CompareLibName().

◆ empty()

◆ end()

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

Definition at line 193 of file utf8.h.

References m_s.

Referenced by LIB_TABLE::FormatOptions().

◆ find() [1/2]

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

Definition at line 105 of file utf8.h.

References m_s.

Referenced by LIB_ID::Parse().

◆ find() [2/2]

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

Definition at line 106 of file utf8.h.

References m_s.

◆ find_first_of()

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

Definition at line 117 of file utf8.h.

References m_s.

Referenced by okLogical().

◆ length()

std::string::size_type UTF8::length ( ) const
inline

Definition at line 109 of file utf8.h.

References m_s.

Referenced by PLACE_FILE_EXPORTER::GenPositionData().

◆ operator const std::string &()

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

Definition at line 183 of file utf8.h.

References m_s.

◆ operator wxString()

UTF8::operator wxString ( ) const

Definition at line 51 of file utf8.cpp.

◆ operator+=() [1/4]

UTF8 & UTF8::operator+= ( char  ch)
inline

Definition at line 130 of file utf8.h.

References c_str(), m_s, and MAYBE_VERIFY_UTF8.

◆ operator+=() [2/4]

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

Definition at line 137 of file utf8.h.

References c_str(), m_s, and MAYBE_VERIFY_UTF8.

◆ operator+=() [3/4]

UTF8 & UTF8::operator+= ( const UTF8 str)
inline

Definition at line 123 of file utf8.h.

References c_str(), m_s, and MAYBE_VERIFY_UTF8.

◆ operator+=() [4/4]

UTF8 & 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 sequence

Parameters
w_chis a UTF-16 value (can be a UTF-32 on Linux)

Definition at line 225 of file utf8.cpp.

References m_s, and substr().

◆ operator=() [1/4]

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

Definition at line 169 of file utf8.h.

References c_str(), m_s, and MAYBE_VERIFY_UTF8.

◆ operator=() [2/4]

UTF8 & UTF8::operator= ( const char *  s)
inline

Definition at line 162 of file utf8.h.

References c_str(), m_s, and MAYBE_VERIFY_UTF8.

◆ operator=() [3/4]

UTF8 & UTF8::operator= ( const std::string &  o)
inline

Definition at line 155 of file utf8.h.

References c_str(), m_s, and MAYBE_VERIFY_UTF8.

◆ operator=() [4/4]

UTF8 & UTF8::operator= ( const wxString &  o)

Definition at line 57 of file utf8.cpp.

References m_s.

◆ operator==() [1/3]

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

Definition at line 115 of file utf8.h.

References m_s.

◆ operator==() [2/3]

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

Definition at line 114 of file utf8.h.

References m_s.

◆ operator==() [3/3]

bool UTF8::operator== ( const UTF8 rhs) const
inline

Definition at line 113 of file utf8.h.

References m_s.

◆ size()

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

◆ substr()

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

Definition at line 178 of file utf8.h.

References m_s.

Referenced by operator+=(), and LIB_ID::Parse().

◆ ubegin()

uni_iter UTF8::ubegin ( ) const
inline

Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.

Definition at line 279 of file utf8.h.

References m_s.

Referenced by KIGFX::OPENGL_GAL::computeBitmapTextSize(), and LIB_ID::FixIllegalChars().

◆ uend()

uni_iter UTF8::uend ( ) const
inline

Return a uni_iter initialized to the end of "this" UTF8 byte sequence.

Definition at line 287 of file utf8.h.

References m_s.

Referenced by KIGFX::OPENGL_GAL::computeBitmapTextSize(), and LIB_ID::FixIllegalChars().

◆ uni_forward()

int UTF8::uni_forward ( const unsigned char *  aSequence,
unsigned *  aResult = nullptr 
)
static

Advance 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
the count of bytes consumed.

Definition at line 67 of file utf8.cpp.

Referenced by IsUTF8(), UTF8::uni_iter::operator*(), UTF8::uni_iter::operator++(), and UTF8::uni_iter::operator->().

◆ wx_str()

wxString UTF8::wx_str ( ) const

Definition at line 45 of file utf8.cpp.

References c_str().

Referenced by SCH_SCREEN::AddLibSymbol(), BOARD_NETLIST_UPDATER::addNewFootprint(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_MAINFRAME::AssociateFootprint(), BASIC_FOOTPRINT_INFO::BASIC_FOOTPRINT_INFO(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), PCBNEW_JOBS_HANDLER::doFpExportSvg(), SYMBOL_LIBS::FindLibSymbol(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SYMBOL_LIB::FindSymbol(), SCH_SEXPR_PLUGIN::Format(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), LIB_ID::GetFullLibraryName(), SCH_ALTIUM_PLUGIN::getLibName(), SCH_EAGLE_PLUGIN::getLibName(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), PCBNEW_JOBS_HANDLER::JobExportFpSvg(), LEGACY_PLUGIN::loadFOOTPRINT(), PCB_EDIT_FRAME::LoadFootprints(), LEGACY_PLUGIN::loadFP_SHAPE(), LEGACY_PLUGIN::loadPAD(), CADSTAR_SCH_ARCHIVE_PLUGIN::LoadSchematicFile(), PANEL_SYMBOL_CHOOSER::populateFootprintSelector(), CVPCB_MAINFRAME::readNetListAndFpFiles(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), BOARD_NETLIST_UPDATER::replaceFootprint(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), SCH_SEXPR_PLUGIN::saveSymbol(), SchGetLibSymbol(), PCB_BASE_FRAME::SelectFootprintFromLibrary(), DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser(), setLibNickname(), FOOTPRINTS_LISTBOX::SetSelectedFootprint(), SYMBOL_VIEWER_FRAME::SetSelectedLibrary(), PANEL_SYMBOL_CHOOSER::showFootprintFor(), SYMBOL_CANDIDATE::SYMBOL_CANDIDATE(), BOARD_NETLIST_UPDATER::testConnectivity(), DIALOG_PLUGIN_OPTIONS::TransferDataFromWindow(), and BOARD_NETLIST_UPDATER::UpdateNetlist().

Member Data Documentation

◆ m_s

◆ npos

constexpr std::string::size_type UTF8::npos = -1
staticconstexpr

Definition at line 151 of file utf8.h.

Referenced by LIB_ID::Parse().


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