40 constexpr Utf8String ()
noexcept =
default;
41 constexpr Utf8String (
const char8_t * str)
42 : Utf8String (std::u8string_view{ str })
45 constexpr Utf8String (std::u8string_view str)
46 : str_ (str.begin (), str.end ())
50 Utf8String (
const Utf8String &) =
default;
51 Utf8String (Utf8String &&) =
default;
52 Utf8String &operator= (
const Utf8String &) =
default;
53 Utf8String &operator= (Utf8String &&) =
default;
54 ~Utf8String () =
default;
56 friend void to_json (nlohmann::json &j,
const Utf8String &s);
57 friend void from_json (
const nlohmann::json &j, Utf8String &s);
59 static Utf8String from_path (
const fs::path &path)
61 return Utf8String{ path.generic_u8string () };
63 static Utf8String from_qstring (
const QString &str)
66 ret.str_ = str.toUtf8 ().toStdString ();
69 static Utf8String from_qurl (
const QUrl &url)
71 return from_qstring (url.toLocalFile ());
73 static Utf8String from_juce_string (
const juce::String &str);
89 std::string_view view () const noexcept {
return str_; }
90 const std::string &str () const noexcept {
return str_; }
91 const char * c_str () const noexcept {
return str_.c_str (); }
92 auto empty () const noexcept {
return str_.empty (); }
95 fs::path to_path ()
const {
return { to_u8_string () }; }
96 std::u8string to_u8_string ()
const {
return { str_.begin (), str_.end () }; }
97 QString to_qstring ()
const {
return QString::fromUtf8 (c_str ()); }
98 juce::String to_juce_string ()
const;
99 juce::File to_juce_file ()
const;
102 explicit operator std::string_view () const noexcept {
return view (); }
103 bool operator== (std::string_view other)
const noexcept
105 return view () == other;
107 Utf8String &operator+= (
const Utf8String &other)
112 Utf8String operator+ (
const Utf8String &other)
const
117 operator fs::path ()
const {
return to_path (); }
118 operator QString ()
const {
return to_qstring (); }
119 friend std::ostream &operator<< (std::ostream &os,
const Utf8String &str)
121 return os << str.view ();
125 Utf8String escape_html ()
const;
126 bool is_ascii ()
const;
127 bool contains_substr (
const Utf8String &substr)
const;
128 bool contains_substr_case_insensitive (
const Utf8String &substr)
const;
129 bool is_equal_ignore_case (
const Utf8String &other)
const;
130 Utf8String to_upper ()
const;
131 Utf8String to_lower ()
const;
153 Utf8String replace (
const Utf8String &from,
const Utf8String &to)
const;
201 std::views::transform (strings, &Utf8String::view),
202 delimiter.view ())));
208 return a.str_ <=> b.str_;
210 friend bool operator== (
const Utf8String &a,
const Utf8String &b)
noexcept
212 return a.str_ == b.str_;
228 CStringRAII (
char * str) noexcept : str_ (str) { }
231 ~CStringRAII () { free (str_); }
234 CStringRAII (
const CStringRAII &) =
delete;
235 CStringRAII &operator= (
const CStringRAII &) =
delete;
238 CStringRAII (CStringRAII &&other) noexcept
239 : str_ (std::exchange (other.str_,
nullptr))
244 CStringRAII &operator= (CStringRAII &&other)
noexcept
249 str_ = std::exchange (other.str_,
nullptr);
255 [[nodiscard]]
const char * c_str ()
const noexcept {
return str_; }
257 bool empty ()
const noexcept {
return !str_ || strlen (str_) == 0; }