// ***************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 * // * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * // ***************************************************************************** #ifndef ZSTRING_H_73425873425789 #define ZSTRING_H_73425873425789 #include //not used by this header, but the "rest of the world" needs it! #include "utf.h" // #include "string_base.h" using Zchar = char; #define Zstr(x) x //"The reason for all the fuss above" - Loki/SmartPtr //a high-performance string for interfacing with native OS APIs in multithreaded contexts using Zstring = zen::Zbase; //for special UI-contexts: guaranteed exponential growth + ref-counting + COW + no SSO overhead using Zstringc = zen::Zbase; //using Zstringw = zen::Zbase; //Windows, Linux: precomposed //macOS: decomposed Zstring getUnicodeNormalForm(const Zstring& str); /* "In fact, Unicode declares that there is an equivalence relationship between decomposed and composed sequences, and conformant software should not treat canonically equivalent sequences, whether composed or decomposed or something in between, as different." https://www.win.tue.nl/~aeb/linux/uc/nfc_vs_nfd.html */ /* Caveat: don't expect input/output string sizes to match: - different UTF-8 encoding length of upper-case chars - different number of upper case chars (e.g. ß => "SS" on macOS) - output is Unicode-normalized */ Zstring getUpperCase(const Zstring& str); //------------------------------------------------------------------------------------------ struct ZstringNorm //use as STL container key: avoid needless Unicode normalizations during std::map<>::find() { /*explicit*/ ZstringNorm(const Zstring& str) : normStr(getUnicodeNormalForm(str)) {} Zstring normStr; std::strong_ordering operator<=>(const ZstringNorm&) const = default; }; template<> struct std::hash { size_t operator()(const ZstringNorm& str) const { return std::hash()(str.normStr); } }; //struct LessUnicodeNormal { bool operator()(const Zstring& lhs, const Zstring& rhs) const { return getUnicodeNormalForm(lhs) < getUnicodeNormalForm(rhs); } }; //------------------------------------------------------------------------------------------ struct ZstringNoCase //use as STL container key: avoid needless upper-case conversions during std::map<>::find() { /*explicit*/ ZstringNoCase(const Zstring& str) : upperCase(getUpperCase(str)) {} Zstring upperCase; std::strong_ordering operator<=>(const ZstringNoCase&) const = default; }; template<> struct std::hash { size_t operator()(const ZstringNoCase& str) const { return std::hash()(str.upperCase); } }; inline bool equalNoCase(const Zstring& lhs, const Zstring& rhs) { return getUpperCase(lhs) == getUpperCase(rhs); } //------------------------------------------------------------------------------------------ std::weak_ordering compareNatural(const Zstring& lhs, const Zstring& rhs); struct LessNaturalSort { bool operator()(const Zstring& lhs, const Zstring& rhs) const { return std::is_lt(compareNatural(lhs, rhs)); } }; //------------------------------------------------------------------------------------------ //common Unicode characters const wchar_t EN_DASH = L'\u2013'; const wchar_t EM_DASH = L'\u2014'; const wchar_t* const SPACED_DASH = L" \u2014 "; //using 'EM DASH' const wchar_t LTR_MARK = L'\u200E'; //UTF-8: E2 80 8E const wchar_t* const ELLIPSIS = L"\u2026"; //"..." const wchar_t MULT_SIGN = L'\u00D7'; //fancy "x" //const wchar_t NOBREAK_SPACE = L'\u00A0'; const wchar_t ZERO_WIDTH_SPACE = L'\u200B'; const wchar_t RTL_MARK = L'\u200F'; //UTF-8: E2 80 8F https://www.w3.org/International/questions/qa-bidi-unicode-controls const wchar_t BIDI_DIR_ISOLATE_RTL = L'\u2067'; //UTF-8: E2 81 A7 => not working on Win 10 const wchar_t BIDI_POP_DIR_ISOLATE = L'\u2069'; //UTF-8: E2 81 A9 => not working on Win 10 const wchar_t BIDI_DIR_EMBEDDING_RTL = L'\u202B'; //UTF-8: E2 80 AB => not working on Win 10 const wchar_t BIDI_POP_DIR_FORMATTING = L'\u202C'; //UTF-8: E2 80 AC => not working on Win 10 #endif //ZSTRING_H_73425873425789