Audacity 3.2.0
Namespaces | Functions
StringUtils.h File Reference
#include <algorithm>
#include <cstring>
#include <cwchar>
#include <string>
#include <string_view>
#include <type_traits>
#include <numeric>
#include <wx/string.h>
Include dependency graph for StringUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  details
 

Functions

std::size_t StringLength (const char str)
 
std::size_t StringLength (const wchar_t str)
 
std::size_t StringLength (const char *str)
 
std::size_t StringLength (const wchar_t *str)
 
template<typename CharType , size_t N>
std::size_t StringLength (const CharType(&)[N])
 
template<typename StringType >
std::size_t StringLength (const StringType &str)
 
template<template< typename, typename... > typename ContainerType, typename ResultType , typename SeparatorType , typename... Rest>
ResultType Join (const ContainerType< ResultType, Rest... > &container, const SeparatorType &separator)
 
STRING_UTILS_API std::string ToLower (const std::string &str)
 
STRING_UTILS_API std::string ToLower (const std::string_view &str)
 
STRING_UTILS_API std::string ToLower (const char *str)
 
STRING_UTILS_API std::wstring ToLower (const std::wstring &str)
 
STRING_UTILS_API std::wstring ToLower (const std::wstring_view &str)
 
STRING_UTILS_API std::wstring ToLower (const wchar_t *str)
 
STRING_UTILS_API wxString ToLower (const wxString &str)
 
STRING_UTILS_API std::string ToUpper (const std::string &str)
 
STRING_UTILS_API std::string ToUpper (const std::string_view &str)
 
STRING_UTILS_API std::string ToUpper (const char *str)
 
STRING_UTILS_API std::wstring ToUpper (const std::wstring &str)
 
STRING_UTILS_API std::wstring ToUpper (const std::wstring_view &str)
 
STRING_UTILS_API std::wstring ToUpper (const wchar_t *str)
 
STRING_UTILS_API wxString ToUpper (const wxString &str)
 
const char * details::begin (const char *str) noexcept
 
const char * details::end (const char *str) noexcept
 
const wchar_t * details::begin (const wchar_t *str) noexcept
 
const wchar_t * details::end (const wchar_t *str) noexcept
 
template<typename HayType , typename PrefixType >
bool IsPrefixed (const HayType &hay, const PrefixType &prefix)
 
template<typename HayType , typename PrefixType >
bool IsPrefixedInsensitive (const HayType &hay, const PrefixType &prefix)
 

Function Documentation

◆ IsPrefixed()

template<typename HayType , typename PrefixType >
bool IsPrefixed ( const HayType &  hay,
const PrefixType &  prefix 
)

Definition at line 129 of file StringUtils.h.

131{
132 if (StringLength(hay) < StringLength(prefix))
133 return false;
134
135 using namespace std;
136 using namespace details;
137
138 const auto prefixBegin = begin(prefix);
139 const auto prefixEnd = end(prefix);
140 const auto hayBegin = begin(hay);
141
142 return std::mismatch(prefixBegin, prefixEnd, hayBegin).first == prefixEnd;
143}
std::size_t StringLength(const char str)
Definition: StringUtils.h:19
const wchar_t * end(const wchar_t *str) noexcept
Definition: StringUtils.h:119
const wchar_t * begin(const wchar_t *str) noexcept
Definition: StringUtils.h:114
STL namespace.

References details::begin(), details::end(), and StringLength().

Referenced by audacity::cloud::audiocom::OAuthService::HandleLinkURI(), IsPrefixedInsensitive(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsPrefixedInsensitive()

template<typename HayType , typename PrefixType >
bool IsPrefixedInsensitive ( const HayType &  hay,
const PrefixType &  prefix 
)

Definition at line 146 of file StringUtils.h.

147{
148 return IsPrefixed(ToLower(hay), ToLower(prefix));
149}
STRING_UTILS_API std::string ToLower(const std::string &str)
Definition: StringUtils.cpp:11
bool IsPrefixed(const HayType &hay, const PrefixType &prefix)
Definition: StringUtils.h:129

References IsPrefixed(), and ToLower().

Referenced by audacity::cloud::audiocom::OAuthService::HandleLinkURI(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Join()

template<template< typename, typename... > typename ContainerType, typename ResultType , typename SeparatorType , typename... Rest>
ResultType Join ( const ContainerType< ResultType, Rest... > &  container,
const SeparatorType &  separator 
)

Definition at line 52 of file StringUtils.h.

55{
56 if (container.empty())
57 return ResultType {};
58
59 const auto sepratorLength = StringLength(separator);
60 const auto totalSeparatorLength = sepratorLength * (container.size() - 1);
61
62 ResultType result;
63
64 const auto size = std::accumulate(
65 container.begin(), container.end(), totalSeparatorLength,
66 [](size_t size, const ResultType& item)
67 { return size + StringLength(item); });
68
69 result.reserve(size);
70
71 bool first = true;
72 for (const auto& item : container)
73 {
74 if (!first)
75 result += separator;
76 result += item;
77 first = false;
78 }
79
80 return result;
81}

References size, and StringLength().

Referenced by TranslatableString::operator+=(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StringLength() [1/6]

std::size_t StringLength ( const char *  str)
inline

Definition at line 29 of file StringUtils.h.

30{
31 return std::strlen(str);
32}
#define str(a)

References str.

◆ StringLength() [2/6]

std::size_t StringLength ( const char  str)
inline

Definition at line 19 of file StringUtils.h.

20{
21 return 1;
22}

Referenced by details::end(), IsPrefixed(), and Join().

Here is the caller graph for this function:

◆ StringLength() [3/6]

template<typename CharType , size_t N>
std::size_t StringLength ( const   CharType(&)[N])

Definition at line 40 of file StringUtils.h.

41{
42 return N - 1;
43}

◆ StringLength() [4/6]

template<typename StringType >
std::size_t StringLength ( const StringType &  str)

Definition at line 46 of file StringUtils.h.

47{
48 return str.length();
49}

References str.

◆ StringLength() [5/6]

std::size_t StringLength ( const wchar_t *  str)
inline

Definition at line 34 of file StringUtils.h.

35{
36 return std::wcslen(str);
37}

References str.

◆ StringLength() [6/6]

std::size_t StringLength ( const wchar_t  str)
inline

Definition at line 24 of file StringUtils.h.

25{
26 return 1;
27}

◆ ToLower() [1/7]

STRING_UTILS_API std::string ToLower ( const char *  str)

Definition at line 21 of file StringUtils.cpp.

22{
24}
std::string ToLower(const std::string &str)
Definition: StringUtils.cpp:11
std::string ToUTF8(const std::wstring &wstr)
wxString ToWXString(const std::string &str)

References str, ToLower(), audacity::ToUTF8(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToLower() [2/7]

STRING_UTILS_API std::string ToLower ( const std::string &  str)

Definition at line 11 of file StringUtils.cpp.

References str, ToLower(), audacity::ToUTF8(), and audacity::ToWXString().

Referenced by IsPrefixedInsensitive(), and ToLower().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToLower() [3/7]

STRING_UTILS_API std::string ToLower ( const std::string_view &  str)

Definition at line 16 of file StringUtils.cpp.

References str, ToLower(), audacity::ToUTF8(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToLower() [4/7]

STRING_UTILS_API std::wstring ToLower ( const std::wstring &  str)

Definition at line 26 of file StringUtils.cpp.

27{
29}
std::wstring ToWString(const std::string &str)

References str, ToLower(), audacity::ToWString(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToLower() [5/7]

STRING_UTILS_API std::wstring ToLower ( const std::wstring_view &  str)

Definition at line 31 of file StringUtils.cpp.

References str, ToLower(), audacity::ToWString(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToLower() [6/7]

STRING_UTILS_API std::wstring ToLower ( const wchar_t *  str)

Definition at line 36 of file StringUtils.cpp.

References str, ToLower(), audacity::ToWString(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToLower() [7/7]

STRING_UTILS_API wxString ToLower ( const wxString &  str)

Definition at line 41 of file StringUtils.cpp.

42{
43 return str.Lower();
44}

References str.

◆ ToUpper() [1/7]

STRING_UTILS_API std::string ToUpper ( const char *  str)

Definition at line 56 of file StringUtils.cpp.

57{
59}
std::string ToUpper(const std::string &str)
Definition: StringUtils.cpp:46

References str, ToUpper(), audacity::ToUTF8(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToUpper() [2/7]

STRING_UTILS_API std::string ToUpper ( const std::string &  str)

Definition at line 46 of file StringUtils.cpp.

References str, ToUpper(), audacity::ToUTF8(), and audacity::ToWXString().

Referenced by audacity::cloud::audiocom::sync::RemoteProjectSnapshot::CalculateKnownBlocks(), audacity::cloud::audiocom::sync::RemoteProjectSnapshot::CleanupOrphanBlocks(), audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::FillMissingBlocks(), audacity::cloud::audiocom::sync::RemoteProjectSnapshot::RemoteProjectSnapshot(), and ToUpper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToUpper() [3/7]

STRING_UTILS_API std::string ToUpper ( const std::string_view &  str)

Definition at line 51 of file StringUtils.cpp.

References str, ToUpper(), audacity::ToUTF8(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToUpper() [4/7]

STRING_UTILS_API std::wstring ToUpper ( const std::wstring &  str)

Definition at line 61 of file StringUtils.cpp.

References str, ToUpper(), audacity::ToWString(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToUpper() [5/7]

STRING_UTILS_API std::wstring ToUpper ( const std::wstring_view &  str)

Definition at line 66 of file StringUtils.cpp.

References str, ToUpper(), audacity::ToWString(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToUpper() [6/7]

STRING_UTILS_API std::wstring ToUpper ( const wchar_t *  str)

Definition at line 71 of file StringUtils.cpp.

References str, ToUpper(), audacity::ToWString(), and audacity::ToWXString().

Here is the call graph for this function:

◆ ToUpper() [7/7]

STRING_UTILS_API wxString ToUpper ( const wxString &  str)

Definition at line 76 of file StringUtils.cpp.

77{
78 return str.Upper();
79}

References str.