Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils::Utf8String Class Reference

Lightweight UTF-8 string wrapper with safe conversions. More...

#include <src/utils/string.h>

Public Member Functions

constexpr Utf8String (const char8_t *str)
 
constexpr Utf8String (std::u8string_view str)
 
 Utf8String (const Utf8String &)=default
 
 Utf8String (Utf8String &&)=default
 
Utf8Stringoperator= (const Utf8String &)=default
 
Utf8Stringoperator= (Utf8String &&)=default
 
std::string_view view () const noexcept
 
const std::string & str () const noexcept
 
const char * c_str () const noexcept
 
auto empty () const noexcept
 
fs::path to_path () const
 
std::u8string to_u8_string () const
 
QString to_qstring () const
 
juce::String to_juce_string () const
 
juce::File to_juce_file () const
 
 operator std::string_view () const noexcept
 
bool operator== (std::string_view other) const noexcept
 
Utf8Stringoperator+= (const Utf8String &other)
 
Utf8String operator+ (const Utf8String &other) const
 
 operator fs::path () const
 
 operator QString () const
 
Utf8String escape_html () const
 
bool is_ascii () const
 
bool contains_substr (const Utf8String &substr) const
 
bool contains_substr_case_insensitive (const Utf8String &substr) const
 
bool is_equal_ignore_case (const Utf8String &other) const
 
Utf8String to_upper () const
 
Utf8String to_lower () const
 
Utf8String convert_to_filename () const
 Returns a filename-safe version of the given string.
 
Utf8String get_substr_before_suffix (const Utf8String &suffix) const
 Removes the suffix starting from suffix from full_str and returns a newly allocated string.
 
Utf8String remove_until_after_first_match (const Utf8String &match) const
 Removes everything up to and including the first match of match from the start of the string.
 
Utf8String replace (const Utf8String &from, const Utf8String &to) const
 
Utf8String get_regex_group (const Utf8String &regex, int group) const
 Gets the string in the given regex group.
 
int get_regex_group_as_int (const Utf8String &regex, int group, int def) const
 Gets the string in the given regex group as an integer.
 
std::pair< int, Utf8Stringget_int_after_last_space () const
 Returns the integer found at the end of a string like "My String 3" -> 3, or -1 if no number is found.
 
Utf8String symbolify () const
 Returns a new string with only ASCII alphanumeric characters and replaces the rest with underscore.
 
Utf8String expand_env_vars () const
 Expands environment variables enclosed in ${} in the given string.
 

Static Public Member Functions

static Utf8String from_path (const fs::path &path)
 
static Utf8String from_qstring (const QString &str)
 
static Utf8String from_qurl (const QUrl &url)
 
static Utf8String from_juce_string (const juce::String &str)
 
static constexpr Utf8String from_utf8_encoded_string (std::string_view str)
 Construct from a std::string_view that we are 100% sure is UTF8-encoded.
 
static Utf8String join (const RangeOf< Utf8String > auto &strings, const Utf8String &delimiter)
 

Friends

void to_json (nlohmann::json &j, const Utf8String &s)
 
void from_json (const nlohmann::json &j, Utf8String &s)
 
std::ostream & operator<< (std::ostream &os, const Utf8String &str)
 
auto operator<=> (const Utf8String &a, const Utf8String &b) noexcept
 
bool operator== (const Utf8String &a, const Utf8String &b) noexcept
 

Detailed Description

Lightweight UTF-8 string wrapper with safe conversions.

Guarantees valid UTF-8 storage and explicit encoding handling.

Definition at line 38 of file string.h.

Constructor & Destructor Documentation

◆ Utf8String() [1/2]

zrythm::utils::Utf8String::Utf8String ( const char8_t * str)
inlineconstexpr

Definition at line 42 of file string.h.

◆ Utf8String() [2/2]

zrythm::utils::Utf8String::Utf8String ( std::u8string_view str)
inlineconstexpr

Definition at line 46 of file string.h.

Member Function Documentation

◆ c_str()

const char * zrythm::utils::Utf8String::c_str ( ) const
inlinenoexcept

Definition at line 95 of file string.h.

◆ convert_to_filename()

Utf8String zrythm::utils::Utf8String::convert_to_filename ( ) const

Returns a filename-safe version of the given string.

Example: "MIDI Region #1" -> "MIDI_Region_1".

◆ empty()

auto zrythm::utils::Utf8String::empty ( ) const
inlinenoexcept

Definition at line 96 of file string.h.

◆ from_path()

static Utf8String zrythm::utils::Utf8String::from_path ( const fs::path & path)
inlinestatic

Definition at line 63 of file string.h.

◆ from_qstring()

static Utf8String zrythm::utils::Utf8String::from_qstring ( const QString & str)
inlinestatic

Definition at line 67 of file string.h.

◆ from_qurl()

static Utf8String zrythm::utils::Utf8String::from_qurl ( const QUrl & url)
inlinestatic

Definition at line 73 of file string.h.

◆ from_utf8_encoded_string()

static constexpr Utf8String zrythm::utils::Utf8String::from_utf8_encoded_string ( std::string_view str)
inlinestaticconstexpr

Construct from a std::string_view that we are 100% sure is UTF8-encoded.

Warning
This is not checked, so use with caution.

Definition at line 85 of file string.h.

◆ get_int_after_last_space()

std::pair< int, Utf8String > zrythm::utils::Utf8String::get_int_after_last_space ( ) const

Returns the integer found at the end of a string like "My String 3" -> 3, or -1 if no number is found.

See https://www.debuggex.com/cheatsheet/regex/pcre for more info.

Returns
The integer found at the end of the string, or -1 if no number is found, and the string without the number (including the space).

◆ get_regex_group()

Utf8String zrythm::utils::Utf8String::get_regex_group ( const Utf8String & regex,
int group ) const

Gets the string in the given regex group.

Returns
The string, or an empty string if nothing found.

◆ get_regex_group_as_int()

int zrythm::utils::Utf8String::get_regex_group_as_int ( const Utf8String & regex,
int group,
int def ) const

Gets the string in the given regex group as an integer.

Parameters
defDefault.
Returns
The int, or default.

◆ join()

static Utf8String zrythm::utils::Utf8String::join ( const RangeOf< Utf8String > auto & strings,
const Utf8String & delimiter )
inlinestatic

Definition at line 199 of file string.h.

◆ operator fs::path()

zrythm::utils::Utf8String::operator fs::path ( ) const
inline

Definition at line 121 of file string.h.

◆ operator QString()

zrythm::utils::Utf8String::operator QString ( ) const
inline

Definition at line 122 of file string.h.

◆ operator std::string_view()

zrythm::utils::Utf8String::operator std::string_view ( ) const
inlineexplicitnoexcept

Definition at line 106 of file string.h.

◆ operator+()

Utf8String zrythm::utils::Utf8String::operator+ ( const Utf8String & other) const
inline

Definition at line 116 of file string.h.

◆ operator+=()

Utf8String & zrythm::utils::Utf8String::operator+= ( const Utf8String & other)
inline

Definition at line 111 of file string.h.

◆ operator==()

bool zrythm::utils::Utf8String::operator== ( std::string_view other) const
inlinenoexcept

Definition at line 107 of file string.h.

◆ str()

const std::string & zrythm::utils::Utf8String::str ( ) const
inlinenoexcept

Definition at line 94 of file string.h.

◆ to_path()

fs::path zrythm::utils::Utf8String::to_path ( ) const
inline

Definition at line 99 of file string.h.

◆ to_qstring()

QString zrythm::utils::Utf8String::to_qstring ( ) const
inline

Definition at line 101 of file string.h.

◆ to_u8_string()

std::u8string zrythm::utils::Utf8String::to_u8_string ( ) const
inline

Definition at line 100 of file string.h.

◆ view()

std::string_view zrythm::utils::Utf8String::view ( ) const
inlinenoexcept

Definition at line 93 of file string.h.

Friends And Related Symbol Documentation

◆ from_json

void from_json ( const nlohmann::json & j,
Utf8String & s )
friend

Definition at line 58 of file string.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Utf8String & str )
friend

Definition at line 123 of file string.h.

◆ operator<=>

auto operator<=> ( const Utf8String & a,
const Utf8String & b )
friend

Definition at line 210 of file string.h.

◆ operator==

bool operator== ( const Utf8String & a,
const Utf8String & b )
friend

Definition at line 214 of file string.h.

◆ to_json

void to_json ( nlohmann::json & j,
const Utf8String & s )
friend

Definition at line 57 of file string.h.


The documentation for this class was generated from the following file: