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.
 
 UTF8 (const wchar_t *txt)
 For use with _() function on wx 2.8.
 
 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
 
bool operator!= (const UTF8 &rhs) const
 
bool operator< (const UTF8 &rhs) const
 
bool operator> (const UTF8 &rhs) 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.
 
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.
 
uni_iter uend () const
 Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
 

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.
 

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 71 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 78 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 88 of file utf8.h.

References c_str(), and MAYBE_VERIFY_UTF8.

◆ UTF8() [5/5]

UTF8::UTF8 ( )
inline

Definition at line 94 of file utf8.h.

◆ ~UTF8()

UTF8::~UTF8 ( )
inline

Definition at line 98 of file utf8.h.

Member Function Documentation

◆ begin()

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

Definition at line 197 of file utf8.h.

References m_s.

Referenced by LIB_TABLE::FormatOptions().

◆ c_str()

◆ clear()

void UTF8::clear ( )
inline

Definition at line 109 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 112 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 198 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 106 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 107 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 122 of file utf8.h.

References m_s.

Referenced by checkLibNickname().

◆ length()

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

Definition at line 110 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 188 of file utf8.h.

References m_s.

◆ operator wxString()

UTF8::operator wxString ( ) const

Definition at line 51 of file utf8.cpp.

◆ operator!=()

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

Definition at line 118 of file utf8.h.

References operator==().

◆ operator+=() [1/4]

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

Definition at line 135 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 142 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 128 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<()

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

Definition at line 119 of file utf8.h.

References m_s.

◆ operator=() [1/4]

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

Definition at line 174 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 167 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 160 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 116 of file utf8.h.

References m_s.

◆ operator==() [2/3]

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

Definition at line 115 of file utf8.h.

References m_s.

◆ operator==() [3/3]

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

Definition at line 114 of file utf8.h.

References m_s.

Referenced by operator!=().

◆ operator>()

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

Definition at line 120 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 183 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 284 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 292 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 COMPONENTS_MANAGER::AddComponent(), SCH_SCREEN::AddLibSymbol(), BOARD_NETLIST_UPDATER::addNewFootprint(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_MAINFRAME::AssociateFootprint(), BASIC_FOOTPRINT_INFO::BASIC_FOOTPRINT_INFO(), PANEL_DESIGN_BLOCK_LIB_TABLE::browseLibrariesHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), SCH_SCREENS::ChangeSymbolLibNickname(), CADSTAR_SCH_ARCHIVE_LOADER::CreateLibName(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), PCBNEW_JOBS_HANDLER::doFpExportSvg(), SYMBOL_SAVE_AS_HANDLER::DoSave(), PCB_EDIT_FRAME::ExchangeFootprint(), LIB_TREE_MODEL_ADAPTER::FindItem(), SYMBOL_LIBS::FindLibSymbol(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SYMBOL_LIB::FindSymbol(), PCB_IO_KICAD_SEXPR::FootprintSave(), SCH_IO_KICAD_SEXPR::Format(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), DESIGN_BLOCK_TREE_MODEL_ADAPTER::GenerateInfo(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), LIB_ID::GetFullLibraryName(), SCH_IO_ALTIUM::getLibName(), SCH_IO_EAGLE::getLibName(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), PCBNEW_JOBS_HANDLER::JobExportFpSvg(), PCB_IO_KICAD_LEGACY::loadFOOTPRINT(), PCB_EDIT_FRAME::LoadFootprints(), PCB_IO_KICAD_LEGACY::loadFP_SHAPE(), PCB_IO_KICAD_LEGACY::loadPAD(), 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(), SYMBOL_EDIT_FRAME::Revert(), SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol(), SCH_IO_KICAD_SEXPR::saveSymbol(), SchGetDesignBlock(), 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 156 of file utf8.h.

Referenced by LIB_ID::Parse().


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