39 constexpr Utf8String ()
noexcept =
default;
40 constexpr Utf8String (
const char8_t * str)
41 : Utf8String (std::u8string_view{ str })
44 constexpr Utf8String (std::u8string_view str)
45 : str_ (str.begin (), str.end ())
49 Utf8String (
const Utf8String &) =
default;
50 Utf8String (Utf8String &&) =
default;
51 Utf8String &operator= (
const Utf8String &) =
default;
52 Utf8String &operator= (Utf8String &&) =
default;
53 ~Utf8String () =
default;
55 friend void to_json (nlohmann::json &j,
const Utf8String &s);
56 friend void from_json (
const nlohmann::json &j, Utf8String &s);
58 static Utf8String from_path (
const std::filesystem::path &path)
60 return Utf8String{ path.generic_u8string () };
62 static Utf8String from_qstring (
const QString &str)
65 ret.str_ = str.toUtf8 ().toStdString ();
68 static Utf8String from_qurl (
const QUrl &url)
70 return from_qstring (url.toLocalFile ());
72 static Utf8String from_juce_string (
const juce::String &str);
88 std::string_view view () const noexcept {
return str_; }
89 const std::string &str () const noexcept {
return str_; }
90 const char * c_str () const noexcept {
return str_.c_str (); }
91 auto empty () const noexcept {
return str_.empty (); }
94 std::filesystem::path to_path ()
const {
return { to_u8_string () }; }
95 std::u8string to_u8_string ()
const {
return { str_.begin (), str_.end () }; }
96 QString to_qstring ()
const {
return QString::fromUtf8 (c_str ()); }
97 juce::String to_juce_string ()
const;
98 juce::File to_juce_file ()
const;
101 explicit operator std::string_view () const noexcept {
return view (); }
102 bool operator== (std::string_view other)
const noexcept
104 return view () == other;
106 Utf8String &operator+= (
const Utf8String &other)
111 Utf8String operator+ (
const Utf8String &other)
const
116 operator std::filesystem::path ()
const {
return to_path (); }
117 operator QString ()
const {
return to_qstring (); }
118 friend std::ostream &operator<< (std::ostream &os,
const Utf8String &str)
120 return os << str.view ();
124 Utf8String escape_html ()
const;
125 bool is_ascii ()
const;
126 bool contains_substr (
const Utf8String &substr)
const;
127 bool contains_substr_case_insensitive (
const Utf8String &substr)
const;
128 bool is_equal_ignore_case (
const Utf8String &other)
const;
129 Utf8String to_upper ()
const;
130 Utf8String to_lower ()
const;
152 Utf8String replace (
const Utf8String &from,
const Utf8String &to)
const;
196 auto it = std::ranges::begin (strings);
197 auto end = std::ranges::end (strings);
201 for (++it; it != end; ++it)
210 friend auto operator<=> (
const Utf8String &,
const Utf8String &) =
default;
211 friend bool operator== (
const Utf8String &,
const Utf8String &) =
default;
226 CStringRAII (
char * str) noexcept : str_ (str) { }
229 ~CStringRAII () { free (str_); }
232 CStringRAII (
const CStringRAII &) =
delete;
233 CStringRAII &operator= (
const CStringRAII &) =
delete;
236 CStringRAII (CStringRAII &&other) noexcept
237 : str_ (std::exchange (other.str_,
nullptr))
242 CStringRAII &operator= (CStringRAII &&other)
noexcept
247 str_ = std::exchange (other.str_,
nullptr);
253 [[nodiscard]]
const char * c_str ()
const noexcept {
return str_; }
255 bool empty ()
const noexcept {
return !str_ || strlen (str_) == 0; }