diff --git a/ZRCola/zrcolachrcatpnl.cpp b/ZRCola/zrcolachrcatpnl.cpp index 8c4fcc2..2fd0210 100644 --- a/ZRCola/zrcolachrcatpnl.cpp +++ b/ZRCola/zrcolachrcatpnl.cpp @@ -148,7 +148,7 @@ void wxZRColaCharacterCatalogPanel::Update() wxArrayShort(reinterpret_cast(cg.chrshow()), reinterpret_cast(cg.chrshow_end()))); } else { // Select frequently used characters only. - const wchar_t *src = cg.chrlst(); + const auto *src = cg.chrlst(); const uint16_t *shown = cg.chrshow(); wxArrayString chars; for (size_t i = 0, i_end = cg.chrlst_len(), j = 0; i < i_end; j++) { diff --git a/ZRCola/zrcolachrgrid.cpp b/ZRCola/zrcolachrgrid.cpp index d543a93..e4079fe 100644 --- a/ZRCola/zrcolachrgrid.cpp +++ b/ZRCola/zrcolachrgrid.cpp @@ -110,7 +110,7 @@ wxString wxZRColaCharGrid::GetToolTipText(int idx) const auto &chr = m_chars[idx]; // See if this character has a key sequence registered. - std::unique_ptr ks((ZRCola::keyseq_db::keyseq*)new char[sizeof(ZRCola::keyseq_db::keyseq) + sizeof(wchar_t)*chr.length()]); + std::unique_ptr ks((ZRCola::keyseq_db::keyseq*)new char[sizeof(ZRCola::keyseq_db::keyseq) + sizeof(ZRCola::char_t)*chr.length()]); ks->ZRCola::keyseq_db::keyseq::keyseq(NULL, 0, chr.data(), chr.length()); ZRCola::keyseq_db::indexKey::size_type start; if (app->m_ks_db.idxChr.find(*ks, start)) { diff --git a/ZRCola/zrcolachrslct.cpp b/ZRCola/zrcolachrslct.cpp index 611610d..d89b680 100644 --- a/ZRCola/zrcolachrslct.cpp +++ b/ZRCola/zrcolachrslct.cpp @@ -13,7 +13,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxZRColaUTF16CharValidator, wxValidator); -wxZRColaUTF16CharValidator::wxZRColaUTF16CharValidator(wchar_t *val) : +wxZRColaUTF16CharValidator::wxZRColaUTF16CharValidator(ZRCola::char_t *val) : m_val(val), wxValidator() { @@ -58,11 +58,11 @@ bool wxZRColaUTF16CharValidator::TransferFromWindow() } -bool wxZRColaUTF16CharValidator::Parse(const wxString &val_in, size_t i_start, size_t i_end, wxTextCtrl *ctrl, wxWindow *parent, wchar_t *val_out) +bool wxZRColaUTF16CharValidator::Parse(const wxString &val_in, size_t i_start, size_t i_end, wxTextCtrl *ctrl, wxWindow *parent, ZRCola::char_t *val_out) { const wxStringCharType *buf = val_in; - wchar_t chr = 0; + ZRCola::char_t chr = 0; for (size_t i = i_start;;) { if (i >= i_end) { // End of Unicode found. @@ -156,7 +156,7 @@ bool wxZRColaUnicodeDumpValidator::Parse(const wxString &val_in, size_t i_start, wxString str; for (size_t i = i_start;;) { const wxStringCharType *buf_next; - wchar_t chr; + ZRCola::char_t chr; if ((buf_next = wmemchr(buf + i, L'+', i_end - i)) != NULL) { // Unicode dump separator found. if (!wxZRColaUTF16CharValidator::Parse(val_in, i, buf_next - buf, ctrl, parent, &chr)) @@ -242,7 +242,7 @@ void wxZRColaCharSelect::OnIdle(wxIdleEvent& event) m_gridPreview->SetCellValue(0, 0, m_char); - std::unique_ptr ch((ZRCola::character_db::character*)new char[sizeof(ZRCola::character_db::character) + sizeof(wchar_t)*m_char.length()]); + std::unique_ptr ch((ZRCola::character_db::character*)new char[sizeof(ZRCola::character_db::character) + sizeof(ZRCola::char_t)*m_char.length()]); ch->ZRCola::character_db::character::character(m_char.data(), m_char.length()); ZRCola::character_db::indexChr::size_type ch_start; if (app->m_chr_db.idxChr.find(*ch, ch_start)) { @@ -251,7 +251,7 @@ void wxZRColaCharSelect::OnIdle(wxIdleEvent& event) m_description->SetValue(wxString(chr.desc(), chr.desc_len())); { // See if this character has a key sequence registered. - std::unique_ptr ks((ZRCola::keyseq_db::keyseq*)new char[sizeof(ZRCola::keyseq_db::keyseq) + sizeof(wchar_t)*m_char.length()]); + std::unique_ptr ks((ZRCola::keyseq_db::keyseq*)new char[sizeof(ZRCola::keyseq_db::keyseq) + sizeof(ZRCola::char_t)*m_char.length()]); ks->ZRCola::keyseq_db::keyseq::keyseq(NULL, 0, m_char.data(), m_char.length()); ZRCola::keyseq_db::indexKey::size_type ks_start; if (app->m_ks_db.idxChr.find(*ks, ks_start)) { @@ -284,7 +284,7 @@ void wxZRColaCharSelect::OnIdle(wxIdleEvent& event) // Find character tags. std::list tag_names; - std::unique_ptr ct((ZRCola::chrtag_db::chrtag*)new char[sizeof(ZRCola::chrtag_db::chrtag) + sizeof(wchar_t)*m_char.length()]); + std::unique_ptr ct((ZRCola::chrtag_db::chrtag*)new char[sizeof(ZRCola::chrtag_db::chrtag) + sizeof(ZRCola::char_t)*m_char.length()]); ct->ZRCola::chrtag_db::chrtag::chrtag(m_char.data(), m_char.length()); ZRCola::chrtag_db::indexChr::size_type ct_start, ct_end; if (app->m_ct_db.idxChr.find(*ct, ct_start, ct_end)) { @@ -766,14 +766,14 @@ wxThread::ExitCode wxZRColaCharSelect::SearchThread::Entry() int __cdecl wxZRColaCharSelect::SearchThread::CompareHits(const void *a, const void *b) { - const std::pair *_a = (const std::pair*)a; - const std::pair *_b = (const std::pair*)b; + const std::pair *_a = (const std::pair*)a; + const std::pair *_b = (const std::pair*)b; - if (_a->first > _b->first) return -1; - else if (_a->first < _b->first) return 1; + if (_a->first > _b->first) return -1; + if (_a->first < _b->first) return 1; - if (_a->second < _b->second) return -1; - else if (_a->second > _b->second) return 1; + if (_a->second < _b->second) return -1; + if (_a->second > _b->second) return 1; return 0; } @@ -843,7 +843,7 @@ bool wxPersistentZRColaCharSelect::Restore() for (wxStringTokenizer tok(str, wxT("|")); tok.HasMoreTokens(); ) { wxString chr; for (wxStringTokenizer tok_chr(tok.GetNextToken(), wxT("+")); tok_chr.HasMoreTokens(); ) - chr += (wchar_t)_tcstoul(tok_chr.GetNextToken().c_str(), NULL, 16); + chr += (ZRCola::char_t)_tcstoul(tok_chr.GetNextToken().c_str(), NULL, 16); val.Add(chr); } wnd->m_gridRecent->SetCharacters(val); diff --git a/ZRCola/zrcolachrslct.h b/ZRCola/zrcolachrslct.h index 58c4e81..a6b0d59 100644 --- a/ZRCola/zrcolachrslct.h +++ b/ZRCola/zrcolachrslct.h @@ -40,7 +40,7 @@ public: /// /// Construct the validator with a value to store data /// - wxZRColaUTF16CharValidator(wchar_t *val = NULL); + wxZRColaUTF16CharValidator(ZRCola::char_t *val = NULL); /// /// Copies this validator diff --git a/lib/libZRCola/include/zrcola/character.h b/lib/libZRCola/include/zrcola/character.h index 5be913f..3092cff 100644 --- a/lib/libZRCola/include/zrcola/character.h +++ b/lib/libZRCola/include/zrcola/character.h @@ -29,14 +29,14 @@ namespace ZRCola { /// typedef double charrank_t; - inline bool ispua(_In_ char16_t c) + inline bool ispua(_In_ char_t c) { return u'\ue000' <= c && c <= u'\uf8ff'; } #ifndef _WIN32 - size_t wcslen(_In_z_ const char16_t *str); - size_t wcsnlen(_In_z_count_(count) const char16_t *str, _In_ size_t count); + size_t wcslen(_In_z_ const char_t* str); + size_t wcsnlen(_In_z_count_(count) const char_t* str, _In_ size_t count); #endif #pragma pack(push) @@ -188,7 +188,7 @@ namespace ZRCola { uint16_t chr_to; ///< Character end in \c data uint16_t desc_to; ///< Character description end in \c data uint16_t rel_to; ///< Related characters end in \c data - char16_t data[]; ///< Character, character description + char_t data[]; ///< Character, character description private: inline character(_In_ const character &other); @@ -207,40 +207,40 @@ namespace ZRCola { /// \param[in] rel_len Number of UTF-16 characters in \p rel (including zero delimiters) /// inline character( - _In_opt_z_count_(chr_len) const char16_t *chr = NULL, + _In_opt_z_count_(chr_len) const char_t *chr = NULL, _In_opt_ size_t chr_len = 0, _In_opt_ chrcatid_t cat = chrcatid_t::blank, - _In_opt_z_count_(desc_len) const char16_t *desc = NULL, + _In_opt_z_count_(desc_len) const char_t *desc = NULL, _In_opt_ size_t desc_len = 0, - _In_opt_z_count_(rel_len) const char16_t *rel = NULL, + _In_opt_z_count_(rel_len) const char_t *rel = NULL, _In_opt_ size_t rel_len = 0) { this->cat = cat; this->chr_to = static_cast(chr_len); - if (chr && chr_len) memcpy(this->data, chr, sizeof(char16_t)*chr_len); + if (chr && chr_len) memcpy(this->data, chr, sizeof(char_t)*chr_len); this->desc_to = static_cast(this->chr_to + desc_len); - if (desc && desc_len) memcpy(this->data + this->chr_to, desc, sizeof(char16_t)*desc_len); + if (desc && desc_len) memcpy(this->data + this->chr_to, desc, sizeof(char_t)*desc_len); this->rel_to = static_cast(this->desc_to + rel_len); - if (rel && rel_len) memcpy(this->data + this->desc_to, rel, sizeof(char16_t)*rel_len); + if (rel && rel_len) memcpy(this->data + this->desc_to, rel, sizeof(char_t)*rel_len); } - inline const char16_t* chr () const { return data; }; - inline char16_t* chr () { return data; }; - inline const char16_t* chr_end() const { return data + chr_to; }; - inline char16_t* chr_end() { return data + chr_to; }; - inline uint16_t chr_len() const { return chr_to; }; + inline const char_t* chr () const { return data; }; + inline char_t* chr () { return data; }; + inline const char_t* chr_end() const { return data + chr_to; }; + inline char_t* chr_end() { return data + chr_to; }; + inline uint16_t chr_len() const { return chr_to; }; - inline const char16_t* desc () const { return data + chr_to; }; - inline char16_t* desc () { return data + chr_to; }; - inline const char16_t* desc_end() const { return data + desc_to; }; - inline char16_t* desc_end() { return data + desc_to; }; - inline uint16_t desc_len() const { return desc_to - chr_to; }; + inline const char_t* desc () const { return data + chr_to; }; + inline char_t* desc () { return data + chr_to; }; + inline const char_t* desc_end() const { return data + desc_to; }; + inline char_t* desc_end() { return data + desc_to; }; + inline uint16_t desc_len() const { return desc_to - chr_to; }; - inline const char16_t* rel () const { return data + desc_to; }; - inline char16_t* rel () { return data + desc_to; }; - inline const char16_t* rel_end() const { return data + rel_to; }; - inline char16_t* rel_end() { return data + rel_to; }; - inline uint16_t rel_len() const { return rel_to - desc_to; }; + inline const char_t* rel () const { return data + desc_to; }; + inline char_t* rel () { return data + desc_to; }; + inline const char_t* rel_end() const { return data + rel_to; }; + inline char_t* rel_end() { return data + rel_to; }; + inline uint16_t rel_len() const { return rel_to - desc_to; }; }; #pragma pack(pop) @@ -277,9 +277,9 @@ namespace ZRCola { } } idxChr; ///< Character index - textindex idxDsc; ///< Description index - textindex idxDscSub; ///< Description index (sub-terms) - std::vector data; ///< Character data + textindex idxDsc; ///< Description index + textindex idxDscSub; ///< Description index (sub-terms) + std::vector data; ///< Character data public: /// @@ -308,7 +308,7 @@ namespace ZRCola { /// \param[in ] fn_abort Pointer to function to periodically test for search cancellation /// \param[in ] cookie Cookie for \p fn_abort call /// - bool Search(_In_z_ const char16_t *str, _In_ const std::set &cats, _Inout_ std::map &hits, _Inout_ std::map &hits_sub, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; + bool Search(_In_z_ const char_t *str, _In_ const std::set &cats, _Inout_ std::map &hits, _Inout_ std::map &hits_sub, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; /// /// Get character category @@ -320,10 +320,10 @@ namespace ZRCola { /// - Character category if character found /// - `ZRCola::chrcatid_t::blank` otherwise /// - inline chrcatid_t GetCharCat(_In_z_count_(len) const char16_t *chr, _In_ const size_t len) const + inline chrcatid_t GetCharCat(_In_z_count_(len) const char_t *chr, _In_ const size_t len) const { assert(len <= 0xffff); - std::unique_ptr c((character*)new char[sizeof(character) + sizeof(char16_t)*len]); + std::unique_ptr c((character*)new char[sizeof(character) + sizeof(char_t)*len]); new (c.get()) character(chr, len); indexChr::size_type start; return idxChr.find(*c, start) ? idxChr[start].cat : chrcatid_t::blank; @@ -348,7 +348,7 @@ namespace ZRCola { protected: uint16_t name_to; ///< Character category name end in \c data - char16_t data[]; ///< Character category name + char_t data[]; ///< Character category name private: inline chrcat(_In_ const chrcat &other); @@ -364,22 +364,22 @@ namespace ZRCola { /// \param[in] name_len Number of UTF-16 characters in \p name /// inline chrcat( - _In_opt_ chrcatid_t cat = chrcatid_t::blank, - _In_opt_ uint16_t rank = 0, - _In_opt_z_count_(name_len) const char16_t *name = NULL, - _In_opt_ size_t name_len = 0) + _In_opt_ chrcatid_t cat = chrcatid_t::blank, + _In_opt_ uint16_t rank = 0, + _In_opt_z_count_(name_len) const char_t *name = NULL, + _In_opt_ size_t name_len = 0) { this->cat = cat; this->rank = rank; this->name_to = static_cast(name_len); - if (name && name_len) memcpy(this->data, name, sizeof(char16_t)*name_len); + if (name && name_len) memcpy(this->data, name, sizeof(char_t)*name_len); } - inline const char16_t* name () const { return data; }; - inline char16_t* name () { return data; }; - inline const char16_t* name_end() const { return data + name_to; }; - inline char16_t* name_end() { return data + name_to; }; - inline uint16_t name_len() const { return name_to; }; + inline const char_t* name () const { return data; }; + inline char_t* name () { return data; }; + inline const char_t* name_end() const { return data + name_to; }; + inline char_t* name_end() { return data + name_to; }; + inline uint16_t name_len() const { return name_to; }; }; #pragma pack(pop) @@ -464,7 +464,7 @@ namespace ZRCola { if (a.rank < b.rank) return -1; else if (a.rank > b.rank) return +1; - auto &coll = std::use_facet>(std::locale()); + auto &coll = std::use_facet>(std::locale()); return coll.compare(a.name(), a.name_end(), b.name(), b.name_end()); } } idxRank; ///< Rank index diff --git a/lib/libZRCola/include/zrcola/common.h b/lib/libZRCola/include/zrcola/common.h index 6dbfb1e..214688c 100644 --- a/lib/libZRCola/include/zrcola/common.h +++ b/lib/libZRCola/include/zrcola/common.h @@ -49,6 +49,26 @@ namespace ZRCola { typedef uint32_t recordsize_t; + /// + /// ZRCola database character type + /// +#ifdef _WIN32 + typedef wchar_t char_t; +#else + typedef char16_t char_t; +#endif + + + /// + /// ZRCola database string type + /// +#ifdef _WIN32 + typedef std::wstring string_t; +#else + typedef std::u16string string_t; +#endif + + #pragma pack(push) #pragma pack(2) /// @@ -571,7 +591,7 @@ namespace ZRCola { /// The function does not treat \\0 characters as terminators for performance reasons. /// Therefore \p count_a and \p count_b must represent exact string lengths. /// - int CompareString(_In_ const char16_t* str_a, _In_ size_t count_a, _In_ const char16_t* str_b, _In_ size_t count_b); + int CompareString(_In_ const char_t* str_a, _In_ size_t count_a, _In_ const char_t* str_b, _In_ size_t count_b); /// /// Generates and returns Unicode representation of the string using hexadecimal codes. @@ -580,7 +600,7 @@ namespace ZRCola { /// \param[in] count Number of characters in string \p str /// \param[in] sep Separator /// - std::string GetUnicodeDumpA(_In_z_count_(count) const char16_t* str, _In_ size_t count, _In_z_ const char* sep = "+"); + std::string GetUnicodeDumpA(_In_z_count_(count) const char_t* str, _In_ size_t count, _In_z_ const char* sep = "+"); /// /// Generates and returns Unicode representation of the string using hexadecimal codes. @@ -589,7 +609,7 @@ namespace ZRCola { /// \param[in] count Number of characters in string \p str /// \param[in] sep Separator /// - std::wstring GetUnicodeDumpW(_In_z_count_(count) const char16_t* str, _In_ size_t count, _In_z_ const wchar_t* sep = L"+"); + std::wstring GetUnicodeDumpW(_In_z_count_(count) const char_t* str, _In_ size_t count, _In_z_ const wchar_t* sep = L"+"); #ifdef _UNICODE #define GetUnicodeDump GetUnicodeDumpW diff --git a/lib/libZRCola/include/zrcola/highlight.h b/lib/libZRCola/include/zrcola/highlight.h index d67ea3e..e968921 100644 --- a/lib/libZRCola/include/zrcola/highlight.h +++ b/lib/libZRCola/include/zrcola/highlight.h @@ -45,7 +45,7 @@ namespace ZRCola { protected: uint16_t chr_to; ///< Character end in \c data - char16_t data[]; ///< Character + char_t data[]; ///< Character private: inline highlight(_In_ const highlight &other); @@ -61,21 +61,21 @@ namespace ZRCola { /// inline highlight( _In_opt_ hlghtsetid_t set = 0, - _In_opt_z_count_(chr_len) const char16_t *chr = NULL, + _In_opt_z_count_(chr_len) const char_t *chr = NULL, _In_opt_ size_t chr_len = 0) { this->set = set; this->chr_to = static_cast(chr_len); - if (chr && chr_len) memcpy(this->data, chr, sizeof(char16_t)*chr_len); + if (chr && chr_len) memcpy(this->data, chr, sizeof(char_t)*chr_len); } - inline const char16_t* chr () const { return data; }; - inline char16_t* chr () { return data; }; - inline const char16_t* chr_end() const { return data + chr_to; }; - inline char16_t* chr_end() { return data + chr_to; }; - inline uint16_t chr_len() const { return chr_to; }; + inline const char_t* chr () const { return data; }; + inline char_t* chr () { return data; }; + inline const char_t* chr_end() const { return data + chr_to; }; + inline char_t* chr_end() { return data + chr_to; }; + inline uint16_t chr_len() const { return chr_to; }; - inline char16_t chr_at(_In_ size_t i) const + inline char_t chr_at(_In_ size_t i) const { return i < chr_to ? data[i] : 0; } @@ -160,7 +160,7 @@ namespace ZRCola { /// \param[in] inputMax Length of the input string in characters. Can be (size_t)-1 if \p input is zero terminated. /// \param[in] callback Function to be called on highlight switch /// - void Highlight(_In_z_count_(inputMax) const char16_t* input, _In_ size_t inputMax, _In_ std::function callback) const; + void Highlight(_In_z_count_(inputMax) const char_t* input, _In_ size_t inputMax, _In_ std::function callback) const; }; }; diff --git a/lib/libZRCola/include/zrcola/language.h b/lib/libZRCola/include/zrcola/language.h index 6cd60fe..168efd7 100644 --- a/lib/libZRCola/include/zrcola/language.h +++ b/lib/libZRCola/include/zrcola/language.h @@ -35,7 +35,7 @@ namespace ZRCola { protected: uint16_t chr_to; ///< Character end in \c data - char16_t data[]; ///< Character + char_t data[]; ///< Character private: inline langchar(_In_ const langchar &other); @@ -51,19 +51,19 @@ namespace ZRCola { /// inline langchar( _In_opt_ langid_t lang = langid_t::blank, - _In_opt_z_count_(chr_len) const char16_t *chr = NULL, + _In_opt_z_count_(chr_len) const char_t *chr = NULL, _In_opt_ size_t chr_len = 0) { this->lang = lang; this->chr_to = static_cast(chr_len); - if (chr && chr_len) memcpy(this->data, chr, sizeof(char16_t)*chr_len); + if (chr && chr_len) memcpy(this->data, chr, sizeof(char_t)*chr_len); } - inline const char16_t* chr () const { return data; }; - inline char16_t* chr () { return data; }; - inline const char16_t* chr_end() const { return data + chr_to; }; - inline char16_t* chr_end() { return data + chr_to; }; - inline uint16_t chr_len() const { return chr_to; }; + inline const char_t* chr () const { return data; }; + inline char_t* chr () { return data; }; + inline const char_t* chr_end() const { return data + chr_to; }; + inline char_t* chr_end() { return data + chr_to; }; + inline uint16_t chr_len() const { return chr_to; }; }; #pragma pack(pop) @@ -176,7 +176,7 @@ namespace ZRCola { /// \returns /// - \c true when character is used in language /// - \c false otherwise - bool IsLocalCharacter(_In_ const char16_t *chr, _In_ const char16_t *chr_end, _In_ langid_t lang) const; + bool IsLocalCharacter(_In_ const char_t *chr, _In_ const char_t *chr_end, _In_ langid_t lang) const; }; @@ -196,7 +196,7 @@ namespace ZRCola { protected: uint16_t name_to; ///< Language name end in \c data - char16_t data[]; ///< Language name + char_t data[]; ///< Language name private: inline language(_In_ const language &other); @@ -212,19 +212,19 @@ namespace ZRCola { /// inline language( _In_opt_ langid_t lang = langid_t::blank, - _In_opt_z_count_(name_len) const char16_t *name = NULL, + _In_opt_z_count_(name_len) const char_t *name = NULL, _In_opt_ size_t name_len = 0) { this->lang = lang; this->name_to = static_cast(name_len); - if (name && name_len) memcpy(this->data, name, sizeof(char16_t)*name_len); + if (name && name_len) memcpy(this->data, name, sizeof(char_t)*name_len); } - inline const char16_t* name () const { return data; }; - inline char16_t* name () { return data; }; - inline const char16_t* name_end() const { return data + name_to; }; - inline char16_t* name_end() { return data + name_to; }; - inline uint16_t name_len() const { return name_to; }; + inline const char_t* name () const { return data; }; + inline char_t* name () { return data; }; + inline const char_t* name_end() const { return data + name_to; }; + inline char_t* name_end() { return data + name_to; }; + inline uint16_t name_len() const { return name_to; }; }; #pragma pack(pop) diff --git a/lib/libZRCola/include/zrcola/tag.h b/lib/libZRCola/include/zrcola/tag.h index e6d450d..4f39800 100644 --- a/lib/libZRCola/include/zrcola/tag.h +++ b/lib/libZRCola/include/zrcola/tag.h @@ -38,7 +38,7 @@ namespace ZRCola { protected: uint16_t chr_to; ///< Character end in \c data - char16_t data[]; ///< Character + char_t data[]; ///< Character private: inline chrtag(_In_ const chrtag &other); @@ -53,20 +53,20 @@ namespace ZRCola { /// \param[in] tag Tag /// inline chrtag( - _In_opt_z_count_(chr_len) const char16_t *chr = NULL, - _In_opt_ size_t chr_len = 0, - _In_opt_ tagid_t tag = 0) + _In_opt_z_count_(chr_len) const char_t *chr = NULL, + _In_opt_ size_t chr_len = 0, + _In_opt_ tagid_t tag = 0) { this->tag = tag; this->chr_to = static_cast(chr_len); - if (chr && chr_len) memcpy(this->data, chr, sizeof(char16_t)*chr_len); + if (chr && chr_len) memcpy(this->data, chr, sizeof(char_t)*chr_len); } - inline const char16_t* chr () const { return data; }; - inline char16_t* chr () { return data; }; - inline const char16_t* chr_end() const { return data + chr_to; }; - inline char16_t* chr_end() { return data + chr_to; }; - inline uint16_t chr_len() const { return chr_to; }; + inline const char_t* chr () const { return data; }; + inline char_t* chr () { return data; }; + inline const char_t* chr_end() const { return data + chr_to; }; + inline char_t* chr_end() { return data + chr_to; }; + inline uint16_t chr_len() const { return chr_to; }; }; #pragma pack(pop) @@ -209,7 +209,7 @@ namespace ZRCola { /// \param[in ] fn_abort Pointer to function to periodically test for search cancellation /// \param[in ] cookie Cookie for \p fn_abort call /// - bool Search(_In_ const std::map &tags, _In_ const character_db &ch_db, _In_ const std::set &cats, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; + bool Search(_In_ const std::map &tags, _In_ const character_db &ch_db, _In_ const std::set &cats, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; }; @@ -230,7 +230,7 @@ namespace ZRCola { protected: uint16_t name_to; ///< Tag name end in \c data - char16_t data[]; ///< Tag name + char_t data[]; ///< Tag name private: inline tagname(_In_ const tagname &other); @@ -246,22 +246,22 @@ namespace ZRCola { /// \param[in] name_len Number of UTF-16 characters in \p name /// inline tagname( - _In_opt_ tagid_t tag = 0, - _In_opt_ uint32_t locale = 0, - _In_opt_z_count_(name_len) const char16_t *name = NULL, - _In_opt_ size_t name_len = 0) + _In_opt_ tagid_t tag = 0, + _In_opt_ uint32_t locale = 0, + _In_opt_z_count_(name_len) const char_t *name = NULL, + _In_opt_ size_t name_len = 0) { this->tag = tag; this->locale = locale; this->name_to = static_cast(name_len); - if (name && name_len) memcpy(this->data, name, sizeof(char16_t)*name_len); + if (name && name_len) memcpy(this->data, name, sizeof(char_t)*name_len); } - inline const char16_t* name () const { return data; }; - inline char16_t* name () { return data; }; - inline const char16_t* name_end() const { return data + name_to; }; - inline char16_t* name_end() { return data + name_to; }; - inline uint16_t name_len() const { return name_to; }; + inline const char_t* name () const { return data; }; + inline char_t* name () { return data; }; + inline const char_t* name_end() const { return data + name_to; }; + inline char_t* name_end() { return data + name_to; }; + inline uint16_t name_len() const { return name_to; }; /// /// Compares two names @@ -281,7 +281,7 @@ namespace ZRCola { /// The function does not treat \\0 characters as terminators for performance reasons. /// Therefore \p count_a and \p count_b must represent exact string lengths. /// - static inline int CompareName(_In_ uint32_t locale, _In_z_count_(count_a) const char16_t *str_a, _In_ uint16_t count_a, _In_z_count_(count_b) const char16_t *str_b, _In_ uint16_t count_b) + static inline int CompareName(_In_ uint32_t locale, _In_z_count_(count_a) const char_t *str_a, _In_ uint16_t count_a, _In_z_count_(count_b) const char_t *str_b, _In_ uint16_t count_b) { #ifdef _WIN32 switch (::CompareString(locale, SORT_STRINGSORT | NORM_IGNORECASE, str_a, count_a, str_b, count_b)) { @@ -292,13 +292,13 @@ namespace ZRCola { } #else assert(0); // TODO: 1. Should honour locale. 2. Should use ICU for lowercase conversion. 3. Should be UTF-16-aware. - std::u16string + string_t a(str_a, count_a), b(str_b, count_b); - auto tolower = [](char16_t c){ return std::towlower(c); }; + auto tolower = [](char_t c){ return std::towlower(c); }; std::transform(a.begin(), a.end(), a.begin(), tolower); std::transform(b.begin(), b.end(), b.begin(), tolower); - auto &coll = std::use_facet>(std::locale()); + auto &coll = std::use_facet>(std::locale()); return coll.compare(&*a.cbegin(), &*a.cend(), &*b.cbegin(), &*b.cend()); #endif } @@ -431,7 +431,7 @@ namespace ZRCola { /// \param[in ] fn_abort Pointer to function to periodically test for search cancellation /// \param[in ] cookie Cookie for \p fn_abort call /// - bool Search(_In_z_ const char16_t *str, _In_ uint32_t locale, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; + bool Search(_In_z_ const char_t *str, _In_ uint32_t locale, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; }; }; diff --git a/lib/libZRCola/include/zrcola/translate.h b/lib/libZRCola/include/zrcola/translate.h index dce035a..1422397 100644 --- a/lib/libZRCola/include/zrcola/translate.h +++ b/lib/libZRCola/include/zrcola/translate.h @@ -84,7 +84,7 @@ namespace ZRCola { protected: uint16_t dst_to; ///< Destination character end in \c data uint16_t src_to; ///< Source string end in \c data - char16_t data[]; ///< Destination string and source character + char_t data[]; ///< Destination string and source character private: inline translation(_In_ const translation &other); @@ -105,39 +105,39 @@ namespace ZRCola { inline translation( _In_opt_ transetid_t set = 0, _In_opt_ uint16_t dst_rank = 0, - _In_opt_z_count_(dst_len) const char16_t *dst = NULL, + _In_opt_z_count_(dst_len) const char_t *dst = NULL, _In_opt_ size_t dst_len = 0, _In_opt_ uint16_t src_rank = 0, - _In_opt_z_count_(src_len) const char16_t *src = NULL, + _In_opt_z_count_(src_len) const char_t *src = NULL, _In_opt_ size_t src_len = 0) { this->set = set; this->dst_rank = dst_rank; this->src_rank = src_rank; this->dst_to = static_cast(dst_len); - if (dst && dst_len) memcpy(this->data, dst, sizeof(char16_t)*dst_len); + if (dst && dst_len) memcpy(this->data, dst, sizeof(char_t)*dst_len); this->src_to = static_cast(this->dst_to + src_len); - if (src && src_len) memcpy(this->data + this->dst_to, src, sizeof(char16_t)*src_len); + if (src && src_len) memcpy(this->data + this->dst_to, src, sizeof(char_t)*src_len); } - inline const char16_t* dst () const { return data; }; - inline char16_t* dst () { return data; }; - inline const char16_t* dst_end() const { return data + dst_to; }; - inline char16_t* dst_end() { return data + dst_to; }; - inline uint16_t dst_len() const { return dst_to; }; + inline const char_t* dst () const { return data; }; + inline char_t* dst () { return data; }; + inline const char_t* dst_end() const { return data + dst_to; }; + inline char_t* dst_end() { return data + dst_to; }; + inline uint16_t dst_len() const { return dst_to; }; - inline char16_t dst_at(_In_ size_t i) const + inline char_t dst_at(_In_ size_t i) const { return i < dst_to ? data[i] : 0; } - inline const char16_t* src () const { return data + dst_to; }; - inline char16_t* src () { return data + dst_to; }; - inline const char16_t* src_end() const { return data + src_to; }; - inline char16_t* src_end() { return data + src_to; }; - inline uint16_t src_len() const { return src_to - dst_to; }; + inline const char_t* src () const { return data + dst_to; }; + inline char_t* src () { return data + dst_to; }; + inline const char_t* src_end() const { return data + src_to; }; + inline char_t* src_end() { return data + src_to; }; + inline uint16_t src_len() const { return src_to - dst_to; }; - inline char16_t src_at(_In_ size_t i) const + inline char_t src_at(_In_ size_t i) const { size_t ii = i + dst_to; // absolute index return ii < src_to ? data[ii] : 0; @@ -302,7 +302,7 @@ namespace ZRCola { /// \param[out] output Output string (UTF-16) /// \param[out] map The vector of source to destination index mappings (optional) /// - void Translate(_In_ transetid_t set, _In_z_count_(inputMax) const char16_t* input, _In_ size_t inputMax, _Out_ std::u16string &output, _Out_opt_ std::vector* map = NULL) const; + void Translate(_In_ transetid_t set, _In_z_count_(inputMax) const char_t* input, _In_ size_t inputMax, _Out_ string_t &output, _Out_opt_ std::vector* map = NULL) const; /// /// Inverse translates string @@ -313,7 +313,7 @@ namespace ZRCola { /// \param[out] output Output string (UTF-16) /// \param[out] map The vector of source to destination index mappings (optional) /// - inline void TranslateInv(_In_ transetid_t set, _In_z_count_(inputMax) const char16_t* input, _In_ size_t inputMax, _Out_ std::u16string &output, _Out_opt_ std::vector* map = NULL) const + inline void TranslateInv(_In_ transetid_t set, _In_z_count_(inputMax) const char_t* input, _In_ size_t inputMax, _Out_ string_t &output, _Out_opt_ std::vector* map = NULL) const { TranslateInv(set, input, inputMax, NULL, langid_t::blank, output, map); } @@ -329,7 +329,7 @@ namespace ZRCola { /// \param[out] output Output string (UTF-16) /// \param[out] map The vector of source to destination index mappings (optional) /// - void TranslateInv(_In_ transetid_t set, _In_z_count_(inputMax) const char16_t* input, _In_ size_t inputMax, _In_opt_ const langchar_db *lc_db, _In_opt_ langid_t lang, _Out_ std::u16string &output, _Out_opt_ std::vector* map = NULL) const; + void TranslateInv(_In_ transetid_t set, _In_z_count_(inputMax) const char_t* input, _In_ size_t inputMax, _In_opt_ const langchar_db *lc_db, _In_opt_ langid_t lang, _Out_ string_t &output, _Out_opt_ std::vector* map = NULL) const; }; @@ -350,7 +350,7 @@ namespace ZRCola { protected: uint16_t src_to; ///< Source name end in \c data uint16_t dst_to; ///< Sestination name end in \c data - char16_t data[]; ///< Source and destination names + char_t data[]; ///< Source and destination names private: inline transet(_In_ const transet &other); @@ -368,29 +368,29 @@ namespace ZRCola { /// inline transet( _In_opt_ transetid_t set = 0, - _In_opt_z_count_(src_len) const char16_t *src = NULL, + _In_opt_z_count_(src_len) const char_t *src = NULL, _In_opt_ size_t src_len = 0, - _In_opt_z_count_(dst_len) const char16_t *dst = NULL, + _In_opt_z_count_(dst_len) const char_t *dst = NULL, _In_opt_ size_t dst_len = 0) { this->set = set; this->src_to = static_cast(src_len); - if (src && src_len) memcpy(this->data, src, sizeof(char16_t)*src_len); + if (src && src_len) memcpy(this->data, src, sizeof(char_t)*src_len); this->dst_to = static_cast(this->src_to + dst_len); - if (dst && dst_len) memcpy(this->data + this->src_to, dst, sizeof(char16_t)*dst_len); + if (dst && dst_len) memcpy(this->data + this->src_to, dst, sizeof(char_t)*dst_len); } - inline const char16_t* src () const { return data; }; - inline char16_t* src () { return data; }; - inline const char16_t* src_end() const { return data + src_to; }; - inline char16_t* src_end() { return data + src_to; }; - inline uint16_t src_len() const { return src_to; }; + inline const char_t* src () const { return data; }; + inline char_t* src () { return data; }; + inline const char_t* src_end() const { return data + src_to; }; + inline char_t* src_end() { return data + src_to; }; + inline uint16_t src_len() const { return src_to; }; - inline const char16_t* dst () const { return data + src_to; }; - inline char16_t* dst () { return data + src_to; }; - inline const char16_t* dst_end() const { return data + dst_to; }; - inline char16_t* dst_end() { return data + dst_to; }; - inline uint16_t dst_len() const { return dst_to - src_to; }; + inline const char_t* dst () const { return data + src_to; }; + inline char_t* dst () { return data + src_to; }; + inline const char_t* dst_end() const { return data + dst_to; }; + inline char_t* dst_end() { return data + dst_to; }; + inline uint16_t dst_len() const { return dst_to - src_to; }; }; #pragma pack(pop) @@ -464,7 +464,7 @@ namespace ZRCola { protected: uint16_t name_to; ///< Translation sequence name end in \c data uint16_t sets_to; ///< Translation sequence sets end in \c data - char16_t data[]; ///< Translation sequence name and sets + char_t data[]; ///< Translation sequence name and sets private: inline transeq(_In_ const transeq &other); @@ -484,7 +484,7 @@ namespace ZRCola { inline transeq( _In_opt_ transeqid_t seq = 0, _In_opt_ uint16_t rank = 0, - _In_opt_z_count_(name_len) const char16_t *name = NULL, + _In_opt_z_count_(name_len) const char_t *name = NULL, _In_opt_ size_t name_len = 0, _In_opt_count_ (sets_len) const transetid_t *sets = NULL, _In_opt_ size_t sets_len = 0) @@ -492,16 +492,16 @@ namespace ZRCola { this->seq = seq; this->rank = rank; this->name_to = static_cast(name_len); - if (name && name_len) memcpy(this->data, name, sizeof(char16_t)*name_len); + if (name && name_len) memcpy(this->data, name, sizeof(char_t)*name_len); this->sets_to = static_cast(this->name_to + sets_len); if (sets && sets_len) memcpy(this->data + this->name_to, sets, sizeof(transetid_t)*sets_len); } - inline const char16_t* name () const { return data; }; - inline char16_t* name () { return data; }; - inline const char16_t* name_end() const { return data + name_to; }; - inline char16_t* name_end() { return data + name_to; }; - inline uint16_t name_len() const { return name_to; }; + inline const char_t* name () const { return data; }; + inline char_t* name () { return data; }; + inline const char_t* name_end() const { return data + name_to; }; + inline char_t* name_end() { return data + name_to; }; + inline uint16_t name_len() const { return name_to; }; inline const transetid_t* sets () const { return reinterpret_cast(data + name_to); }; inline transetid_t* sets () { return reinterpret_cast< transetid_t*>(data + name_to); }; @@ -592,7 +592,7 @@ namespace ZRCola { if (a.rank < b.rank) return -1; else if (a.rank > b.rank) return +1; - auto &coll = std::use_facet>(std::locale()); + auto &coll = std::use_facet>(std::locale()); return coll.compare(a.name(), a.name_end(), b.name(), b.name_end()); } } idxRank; ///< Rank index diff --git a/lib/libZRCola/src/character.cpp b/lib/libZRCola/src/character.cpp index 01dfbb7..a410d2c 100644 --- a/lib/libZRCola/src/character.cpp +++ b/lib/libZRCola/src/character.cpp @@ -12,7 +12,7 @@ const ZRCola::chrcatid_t ZRCola::chrcatid_t::blank = {}; #ifndef _WIN32 _Use_decl_annotations_ -size_t ZRCola::wcslen(const char16_t *str) +size_t ZRCola::wcslen(const char_t *str) { for (size_t i = 0; ; ++i) if (!str[i]) @@ -20,7 +20,7 @@ size_t ZRCola::wcslen(const char16_t *str) } _Use_decl_annotations_ -size_t ZRCola::wcsnlen(const char16_t *str, size_t count) +size_t ZRCola::wcsnlen(const char_t *str, size_t count) { for (size_t i = 0; ; ++i) if (i >= count || !str[i]) @@ -31,7 +31,7 @@ size_t ZRCola::wcsnlen(const char16_t *str, size_t count) _Use_decl_annotations_ -bool ZRCola::character_db::Search(const char16_t *str, const std::set &cats, std::map &hits, std::map &hits_sub, bool (__cdecl *fn_abort)(void *cookie), void *cookie) const +bool ZRCola::character_db::Search(const char_t *str, const std::set &cats, std::map &hits, std::map &hits_sub, bool (__cdecl *fn_abort)(void *cookie), void *cookie) const { assert(str); @@ -49,9 +49,9 @@ bool ZRCola::character_db::Search(const char16_t *str, const std::set= count_a && i >= count_b) return 0; @@ -23,7 +23,7 @@ int ZRCola::CompareString(const char16_t* str_a, size_t count_a, const char16_t* _Use_decl_annotations_ -inline std::string ZRCola::GetUnicodeDumpA(const char16_t* str, size_t count, const char* sep) +inline std::string ZRCola::GetUnicodeDumpA(const char_t* str, size_t count, const char* sep) { std::string out; size_t sep_len = strlen(sep); @@ -54,7 +54,7 @@ inline std::string ZRCola::GetUnicodeDumpA(const char16_t* str, size_t count, co _Use_decl_annotations_ -std::wstring ZRCola::GetUnicodeDumpW(const char16_t* str, size_t count, const wchar_t* sep) +std::wstring ZRCola::GetUnicodeDumpW(const char_t* str, size_t count, const wchar_t* sep) { std::wstring out; size_t sep_len = ::wcslen(sep); diff --git a/lib/libZRCola/src/highlight.cpp b/lib/libZRCola/src/highlight.cpp index 7685ccb..e2e93b3 100644 --- a/lib/libZRCola/src/highlight.cpp +++ b/lib/libZRCola/src/highlight.cpp @@ -6,7 +6,7 @@ #include "pch.h" _Use_decl_annotations_ -void ZRCola::highlight_db::Highlight(const char16_t* input, size_t inputMax, std::function callback) const +void ZRCola::highlight_db::Highlight(const char_t* input, size_t inputMax, std::function callback) const { size_t start = 0; hlghtsetid_t set = ZRCOLA_HLGHTSETID_DEFAULT; @@ -15,7 +15,7 @@ void ZRCola::highlight_db::Highlight(const char16_t* input, size_t inputMax, std // Find the longest matching highlight at i-th character. size_t l_match = (size_t)-1; for (size_t l = 0, r = idxChr.size(), ii = i, j = 0; ii < inputMax && l < r; ii++, j++) { - char16_t c = input[ii]; + auto c = input[ii]; while (l < r) { // Test the highlight in the middle of the search area. size_t m = (l + r) / 2; @@ -23,7 +23,7 @@ void ZRCola::highlight_db::Highlight(const char16_t* input, size_t inputMax, std // Get the j-th character of the highlight. // All highlights that get short on characters are lexically ordered before. // Thus the j-th character is considered 0. - char16_t s = idxChr[m].chr_at(j); + auto s = idxChr[m].chr_at(j); // Do the bisection test. if (c < s) r = m; diff --git a/lib/libZRCola/src/language.cpp b/lib/libZRCola/src/language.cpp index eb13409..ec11b04 100644 --- a/lib/libZRCola/src/language.cpp +++ b/lib/libZRCola/src/language.cpp @@ -57,11 +57,11 @@ void ZRCola::LangConvert(_In_ LANGID lang_win, _Inout_ ZRCola::langid_t &lang) #endif -bool ZRCola::langchar_db::IsLocalCharacter(_In_ const char16_t *chr, _In_ const char16_t *chr_end, _In_ ZRCola::langid_t lang) const +bool ZRCola::langchar_db::IsLocalCharacter(_In_ const char_t *chr, _In_ const char_t *chr_end, _In_ ZRCola::langid_t lang) const { size_t n = chr_end - chr; assert(n <= 0xffff); - std::unique_ptr lc((langchar*)new char[sizeof(langchar) + sizeof(char16_t)*n]); + std::unique_ptr lc((langchar*)new char[sizeof(langchar) + sizeof(char_t)*n]); new (lc.get()) langchar(lang, chr, n); indexChr::size_type start; return idxChr.find(*lc, start); diff --git a/lib/libZRCola/src/tag.cpp b/lib/libZRCola/src/tag.cpp index 8584335..78f8728 100644 --- a/lib/libZRCola/src/tag.cpp +++ b/lib/libZRCola/src/tag.cpp @@ -6,7 +6,7 @@ #include "pch.h" -bool ZRCola::chrtag_db::Search(_In_ const std::map &tags, _In_ const character_db &ch_db, _In_ const std::set &cats, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const +bool ZRCola::chrtag_db::Search(_In_ const std::map &tags, _In_ const character_db &ch_db, _In_ const std::set &cats, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const { for (auto tag = tags.cbegin(), tag_end = tags.cend(); tag != tag_end; ++tag) { if (fn_abort && fn_abort(cookie)) return false; @@ -19,7 +19,7 @@ bool ZRCola::chrtag_db::Search(_In_ const std::map &tags, _In const chrtag &ct = idxTag[i]; uint16_t len = ct.chr_len(); if (cats.find(ch_db.GetCharCat(ct.chr(), len)) != cats.end()) { - std::u16string chr(ct.chr(), len); + string_t chr(ct.chr(), len); auto idx = hits.find(chr); if (idx == hits.end()) { // New character. @@ -37,7 +37,7 @@ bool ZRCola::chrtag_db::Search(_In_ const std::map &tags, _In } -bool ZRCola::tagname_db::Search(_In_z_ const char16_t *str, _In_ uint32_t locale, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const +bool ZRCola::tagname_db::Search(_In_z_ const char_t *str, _In_ uint32_t locale, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const { assert(str); @@ -55,9 +55,9 @@ bool ZRCola::tagname_db::Search(_In_z_ const char16_t *str, _In_ uint32_t locale } // Get name. - std::u16string name; + string_t name; if (*str == u'"') { - const char16_t *str_end = ++str; + const auto *str_end = ++str; for (;;) { if (*str_end == 0) { name.assign(str, str_end); @@ -71,7 +71,7 @@ bool ZRCola::tagname_db::Search(_In_z_ const char16_t *str, _In_ uint32_t locale } str = str_end; } else { - const char16_t *str_end = str + 1; + const auto *str_end = str + 1; for (; *str_end && !iswspace(*str_end); str_end++); name.assign(str, str_end); str = str_end; @@ -81,7 +81,7 @@ bool ZRCola::tagname_db::Search(_In_z_ const char16_t *str, _In_ uint32_t locale if (fn_abort && fn_abort(cookie)) return false; // Find the name. - std::unique_ptr tn(reinterpret_cast(new char[sizeof(tagname) + sizeof(char16_t)*name.length()])); + std::unique_ptr tn(reinterpret_cast(new char[sizeof(tagname) + sizeof(char_t)*name.length()])); new (tn.get()) tagname(0, locale, name.data(), name.length()); size_t start, end; if (idxName.find(*tn, start, end)) { diff --git a/lib/libZRCola/src/translate.cpp b/lib/libZRCola/src/translate.cpp index f6abee4..36e0ad2 100644 --- a/lib/libZRCola/src/translate.cpp +++ b/lib/libZRCola/src/translate.cpp @@ -6,7 +6,7 @@ #include "pch.h" -void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputMax) const char16_t* input, _In_ size_t inputMax, _Out_ std::u16string &output, _Out_opt_ std::vector* map) const +void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputMax) const char_t* input, _In_ size_t inputMax, _Out_ string_t &output, _Out_opt_ std::vector* map) const { assert(input || inputMax == 0); @@ -28,7 +28,7 @@ void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputM // Find the longest matching translation at i-th character. size_t l_match = (size_t)-1; for (size_t l = l_set, r = r_set, ii = i, j = 0; ii < inputMax && l < r; ii++, j++) { - char16_t c = input[ii]; + auto c = input[ii]; while (l < r) { // Test the translation in the middle of the search area. size_t m = (l + r) / 2; @@ -36,7 +36,7 @@ void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputM // Get the j-th character of the translation. // All translations that get short on characters are lexically ordered before. // Thus the j-th character is considered 0. - char16_t s = idxSrc[m].src_at(j); + auto s = idxSrc[m].src_at(j); // Do the bisection test. if (c < s) r = m; @@ -84,7 +84,7 @@ void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputM } -void ZRCola::translation_db::TranslateInv(_In_ transetid_t set, _In_z_count_(inputMax) const char16_t* input, _In_ size_t inputMax, _In_opt_ const langchar_db *lc_db, _In_opt_ langid_t lang, _Out_ std::u16string &output, _Out_opt_ std::vector* map) const +void ZRCola::translation_db::TranslateInv(_In_ transetid_t set, _In_z_count_(inputMax) const char_t* input, _In_ size_t inputMax, _In_opt_ const langchar_db *lc_db, _In_opt_ langid_t lang, _Out_ string_t &output, _Out_opt_ std::vector* map) const { assert(input || inputMax == 0); @@ -106,7 +106,7 @@ void ZRCola::translation_db::TranslateInv(_In_ transetid_t set, _In_z_count_(inp // Find the longest matching inverse translation at i-th character. size_t l_match = (size_t)-1; for (size_t l = l_set, r = r_set, ii = i, j = 0; ii < inputMax && l < r; ii++, j++) { - char16_t c = input[ii]; + auto c = input[ii]; while (l < r) { // Test the inverse translation in the middle of the search area. size_t m = (l + r) / 2; @@ -114,7 +114,7 @@ void ZRCola::translation_db::TranslateInv(_In_ transetid_t set, _In_z_count_(inp // Get the j-th character of the inverse translation. // All inverse translations that get short on characters are lexically ordered before. // Thus the j-th character is considered 0. - char16_t s = idxDst[m].dst_at(j); + auto s = idxDst[m].dst_at(j); // Do the bisection test. if (c < s) r = m; diff --git a/lib/libZRColaUI/include/zrcolaui/chargroup.h b/lib/libZRColaUI/include/zrcolaui/chargroup.h index 5dc8bd2..bd27fc8 100644 --- a/lib/libZRColaUI/include/zrcolaui/chargroup.h +++ b/lib/libZRColaUI/include/zrcolaui/chargroup.h @@ -46,7 +46,7 @@ namespace ZRCola { protected: uint16_t name_to; ///< Character group name end in \c data uint16_t chrlst_to; ///< Character list end in \c data - wchar_t data[]; ///< Character group name, character list, bit vector if particular character is displayed initially + char_t data[]; ///< Character group name, character list, bit vector if particular character is displayed initially public: /// @@ -63,33 +63,33 @@ namespace ZRCola { inline chrgrp( _In_opt_ chrgrpid_t grp = 0, _In_opt_ uint16_t rank = 0, - _In_opt_z_count_(name_len) const wchar_t *name = NULL, + _In_opt_z_count_(name_len) const char_t *name = NULL, _In_opt_ size_t name_len = 0, - _In_opt_z_count_(chrlst_len) const wchar_t *chrlst = NULL, + _In_opt_z_count_(chrlst_len) const char_t *chrlst = NULL, _In_opt_ size_t chrlst_len = 0, _In_opt_count_x_((chrlst_len + 15)/16) const uint16_t *chrshow = NULL) { this->grp = grp; this->rank = rank; this->name_to = static_cast(name_len); - if (name && name_len) memcpy(this->data, name, sizeof(wchar_t)*name_len); + if (name && name_len) memcpy(this->data, name, sizeof(char_t)*name_len); this->chrlst_to = static_cast(this->name_to + chrlst_len); if (chrlst && chrshow && chrlst_len) { - memcpy(this->data + this->name_to, chrlst, sizeof(wchar_t)*chrlst_len); + memcpy(this->data + this->name_to, chrlst, sizeof(char_t)*chrlst_len); memcpy(this->data + this->chrlst_to, chrshow, (chrlst_len + sizeof(*data)*8 - 1)/8); } } - inline const wchar_t* name () const { return data; }; - inline wchar_t* name () { return data; }; - inline const wchar_t* name_end() const { return data + name_to; }; - inline wchar_t* name_end() { return data + name_to; }; + inline const char_t* name () const { return data; }; + inline char_t* name () { return data; }; + inline const char_t* name_end() const { return data + name_to; }; + inline char_t* name_end() { return data + name_to; }; inline uint16_t name_len() const { return name_to; }; - inline const wchar_t* chrlst () const { return data + name_to; }; - inline wchar_t* chrlst () { return data + name_to; }; - inline const wchar_t* chrlst_end() const { return data + chrlst_to; }; - inline wchar_t* chrlst_end() { return data + chrlst_to; }; + inline const char_t* chrlst () const { return data + name_to; }; + inline char_t* chrlst () { return data + name_to; }; + inline const char_t* chrlst_end() const { return data + chrlst_to; }; + inline char_t* chrlst_end() { return data + chrlst_to; }; inline uint16_t chrlst_len() const { return chrlst_to - name_to; }; inline const uint16_t* chrshow () const { return reinterpret_cast(data + chrlst_to ); }; @@ -148,7 +148,7 @@ namespace ZRCola { if (a.rank < b.rank) return -1; else if (a.rank > b.rank) return +1; - auto &coll = std::use_facet>(std::locale()); + auto &coll = std::use_facet>(std::locale()); return coll.compare(a.name(), a.name_end(), b.name(), b.name_end()); } } idxRank; ///< Rank index diff --git a/lib/libZRColaUI/include/zrcolaui/keyboard.h b/lib/libZRColaUI/include/zrcolaui/keyboard.h index 6c5630c..d996712 100644 --- a/lib/libZRColaUI/include/zrcolaui/keyboard.h +++ b/lib/libZRColaUI/include/zrcolaui/keyboard.h @@ -45,14 +45,14 @@ namespace ZRCola { }; struct key_t { - wchar_t key; ///< Key + char_t key; ///< Key uint16_t modifiers; ///< Modifiers (bitwise combination of SHIFT, CTRL and ALT) }; protected: uint16_t chr_to; ///< Character end in \c data uint16_t seq_to; ///< Key sequence end in \c data - wchar_t data[]; ///< Character and key sequence + char_t data[]; ///< Character and key sequence public: /// @@ -64,21 +64,21 @@ namespace ZRCola { /// \param[in] chr_len Number of UTF-16 characters in \p chr /// inline keyseq( - _In_opt_count_(seq_count) const key_t *seq = NULL, - _In_opt_ size_t seq_count = 0, - _In_opt_z_count_(chr_len) const wchar_t *chr = NULL, - _In_opt_ size_t chr_len = 0) + _In_opt_count_(seq_count) const key_t *seq = NULL, + _In_opt_ size_t seq_count = 0, + _In_opt_z_count_(chr_len) const char_t *chr = NULL, + _In_opt_ size_t chr_len = 0) { this->chr_to = static_cast(chr_len); - if (chr && chr_len) memcpy(this->data, chr, sizeof(wchar_t)*chr_len); + if (chr && chr_len) memcpy(this->data, chr, sizeof(char_t)*chr_len); this->seq_to = static_cast(this->chr_to + seq_count * sizeof(key_t) / sizeof(*data)); if (seq && seq_count) memcpy(this->data + this->chr_to, seq, sizeof(key_t)*seq_count); } - inline const wchar_t* chr () const { return data; }; - inline wchar_t* chr () { return data; }; - inline const wchar_t* chr_end() const { return data + chr_to; }; - inline wchar_t* chr_end() { return data + chr_to; }; + inline const char_t* chr () const { return data; }; + inline char_t* chr () { return data; }; + inline const char_t* chr_end() const { return data + chr_to; }; + inline char_t* chr_end() { return data + chr_to; }; inline uint16_t chr_len() const { return chr_to; }; inline const key_t* seq () const { return reinterpret_cast(data + chr_to); };