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) { j = s.str (); }
57 friend void from_json (
const nlohmann::json &j, Utf8String &s)
62 static Utf8String from_path (
const fs::path &path)
64 return Utf8String{ path.generic_u8string () };
66 static Utf8String from_qstring (
const QString &str)
69 ret.str_ = str.toUtf8 ().toStdString ();
72 static Utf8String from_qurl (
const QUrl &url)
74 return from_qstring (url.toLocalFile ());
76 static Utf8String from_juce_string (
const juce::String &str);
92 std::string_view view () const noexcept {
return str_; }
93 const std::string &str () const noexcept {
return str_; }
94 const char * c_str () const noexcept {
return str_.c_str (); }
95 auto empty () const noexcept {
return str_.empty (); }
98 fs::path to_path ()
const {
return { to_u8_string () }; }
99 std::u8string to_u8_string ()
const {
return { str_.begin (), str_.end () }; }
100 QString to_qstring ()
const {
return QString::fromUtf8 (c_str ()); }
101 juce::String to_juce_string ()
const;
102 juce::File to_juce_file ()
const;
105 explicit operator std::string_view () const noexcept {
return view (); }
106 bool operator== (std::string_view other)
const noexcept
108 return view () == other;
110 Utf8String &operator+= (
const Utf8String &other)
115 Utf8String operator+ (
const Utf8String &other)
const
120 operator fs::path ()
const {
return to_path (); }
121 operator QString ()
const {
return to_qstring (); }
122 friend std::ostream &operator<< (std::ostream &os,
const Utf8String &str)
124 return os << str.view ();
128 Utf8String escape_html ()
const;
129 bool is_ascii ()
const;
130 bool contains_substr (
const Utf8String &substr)
const;
131 bool contains_substr_case_insensitive (
const Utf8String &substr)
const;
132 bool is_equal_ignore_case (
const Utf8String &other)
const;
133 Utf8String to_upper ()
const;
134 Utf8String to_lower ()
const;
156 Utf8String replace (
const Utf8String &from,
const Utf8String &to)
const;
204 std::views::transform (strings, &Utf8String::view),
205 delimiter.view ())));
211 return a.str_ <=> b.str_;
213 friend bool operator== (
const Utf8String &a,
const Utf8String &b)
noexcept
215 return a.str_ == b.str_;
231 CStringRAII (
char * str) noexcept : str_ (str) { }
234 ~CStringRAII () { free (str_); }
237 CStringRAII (
const CStringRAII &) =
delete;
238 CStringRAII &operator= (
const CStringRAII &) =
delete;
241 CStringRAII (CStringRAII &&other) noexcept
242 : str_ (std::exchange (other.str_,
nullptr))
247 CStringRAII &operator= (CStringRAII &&other)
noexcept
252 str_ = std::exchange (other.str_,
nullptr);
258 [[nodiscard]]
const char * c_str ()
const noexcept {
return str_; }
260 bool empty ()
const noexcept {
return !str_ || strlen (str_) == 0; }