![]() |
libfilezilla
|
String types and assorted functions. More...
#include "libfilezilla.hpp"#include <algorithm>#include <cstdint>#include <limits>#include <optional>#include <string>#include <string_view>#include <vector>

Go to the source code of this file.
Classes | |
| class | traits_cloner< CharT, BaseT > |
| class | char_traits< uint8_t > |
| struct | string_value_type< T, std::void_t< typename T::value_type > > |
| struct | string_value_type< CharT * > |
| struct | string_value_type< CharT(&)[N]> |
| struct | string_value_type< CharT[N]> |
| struct | less_insensitive_ascii |
| Comparator to be used for std::map for case-insensitive keys. More... | |
| class | strtokenizer< String, Delims > |
| Container-like class that can be used to iterate over tokens in a string. More... | |
| struct | strtokenizer< String, Delims >::sentinel |
| struct | strtokenizer< String, Delims >::iterator |
Namespaces | |
| namespace | fz |
| The namespace used by libfilezilla. | |
Macros | |
| #define | fzT(x) |
| Macro for a string literal in system-native character type. Note: Macro definition changes depending on platform! | |
| #define | fzS(Char, s) |
| Macro to get const pointer to a string of the corresponding type. | |
Typedefs | |
| typedef std::wstring | native_string |
| A string in the system's native character type and encoding. Note: This typedef changes depending on platform! | |
| typedef std::wstring_view | native_string_view |
| template<typename T> | |
| using | string_value_type_t = typename string_value_type<T>::type |
Functions | |
| native_string | to_native (std::string_view const &in) |
| Converts std::string to native_string. | |
| native_string | to_native (std::wstring_view const &in) |
| Convert std::wstring to native_string. | |
| template<typename T, typename std::enable_if_t< std::is_same_v< native_string, typename std::decay_t< T > >, int > = 0> | |
| native_string | to_native (T const &in) |
| Avoid converting native_string to native_string_view and back to native_string. | |
| int | stricmp (std::string_view const &a, std::string_view const &b) |
| Locale-sensitive stricmp. | |
| int | stricmp (std::wstring_view const &a, std::wstring_view const &b) |
| template<typename Char> | |
| Char | tolower_ascii (Char c) |
| Converts ASCII uppercase characters to lowercase as if C-locale is used. | |
| template<> | |
| std::wstring::value_type | tolower_ascii (std::wstring::value_type c) |
| template<typename Char> | |
| Char | toupper_ascii (Char c) |
| Converts ASCII lowercase characters to uppercase as if C-locale is used. | |
| template<> | |
| std::wstring::value_type | toupper_ascii (std::wstring::value_type c) |
| std::string | str_tolower_ascii (std::string_view const &s) |
| tr_tolower_ascii does for strings what tolower_ascii does for individual characters | |
| std::wstring | str_tolower_ascii (std::wstring_view const &s) |
| std::string | str_toupper_ascii (std::string_view const &s) |
| std::wstring | str_toupper_ascii (std::wstring_view const &s) |
| template<typename A, typename B, std::enable_if_t< std::is_same_v< string_value_type_t< A >, string_value_type_t< B > > > * = nullptr> | |
| bool | equal_insensitive_ascii (A const &a, B const &b) |
| Locale-insensitive stricmp. | |
| std::wstring | to_wstring (std::string_view const &in) |
| Converts from std::string in system encoding into std::wstring. | |
| template<typename T> | |
| auto | to_wstring (T &&in) -> decltype(std::wstring(std::forward< T >(in))) |
| Returns identity, that way to_wstring can be called with native_string. | |
| template<typename Arg> | |
| std::enable_if< std::is_arithmetic_v< std::decay_t< Arg > >, std::wstring >::type | to_wstring (Arg &&arg) |
| Converts from arithmetic type to std::wstring. | |
| std::wstring | to_wstring_from_utf8 (std::string_view const &in) |
| Converts from std::string in UTF-8 into std::wstring. | |
| std::wstring | to_wstring_from_utf8 (char const *s, size_t len) |
| std::wstring | to_wstring_from_utf8 (fz::buffer const &in) |
| std::string | to_string (std::wstring_view const &in) |
| Converts from std::wstring into std::string in system encoding. | |
| template<typename T> | |
| auto | to_string (T &&in) -> decltype(std::string(std::forward< T >(in))) |
| Returns identity, that way to_wstring can be called with native_string. | |
| template<typename Arg> | |
| std::enable_if< std::is_arithmetic_v< std::decay_t< Arg > >, std::string >::type | to_string (Arg &&arg) |
| Converts from arithmetic type to std::string. | |
| template<typename Char> | |
| size_t | strlen (Char const *str) |
| Returns length of 0-terminated character sequence. Works with both narrow and wide-characters. | |
| std::string | to_utf8 (std::string_view const &in) |
| Converts from std::string in native encoding into std::string in UTF-8. | |
| std::string | to_utf8 (std::wstring_view const &in) |
| Converts from std::wstring in native encoding into std::string in UTF-8. | |
| template<typename String, typename Arg> | |
| auto | toString (Arg &&arg) -> typename std::enable_if< std::is_same_v< String, std::string >, decltype(to_string(std::forward< Arg >(arg)))>::type |
| Calls either fz::to_string or fz::to_wstring depending on the passed template argument. | |
| template<typename Char> | |
| constexpr Char const * | choose_string (char const *c, wchar_t const *w) |
| Returns the function argument of the type matching the template argument. | |
| template<> | |
| constexpr char const * | choose_string (char const *c, wchar_t const *) |
| template<> | |
| constexpr wchar_t const * | choose_string (char const *, wchar_t const *w) |
| std::string | replaced_substrings (std::string_view const &in, std::string_view const &find, std::string_view const &replacement) |
Returns in with all occurrences of find in the input string replaced with replacement. | |
| std::wstring | replaced_substrings (std::wstring_view const &in, std::wstring_view const &find, std::wstring_view const &replacement) |
| std::string | replaced_substrings (std::string_view const &in, char find, char replacement) |
Returns in with all occurrences of find in the input string replaced with replacement. | |
| std::wstring | replaced_substrings (std::wstring_view const &in, wchar_t find, wchar_t replacement) |
| bool | replace_substrings (std::string &in, std::string_view const &find, std::string_view const &replacement) |
Modifies in, replacing all occurrences of find with replacement. | |
| bool | replace_substrings (std::wstring &in, std::wstring_view const &find, std::wstring_view const &replacement) |
| bool | replace_substrings (std::string &in, char find, char replacement) |
Modifies in, replacing all occurrences of find with replacement. | |
| bool | replace_substrings (std::wstring &in, wchar_t find, wchar_t replacement) |
| template<typename String, typename Delims> | |
| strtokenizer (String &&string, Delims &&delims, bool ignore_empty) -> strtokenizer< String, Delims > | |
| strtokenizer class construction-guide. | |
| std::vector< std::string > | strtok (std::string_view const &tokens, std::string_view const &delims, bool const ignore_empty=true) |
| Tokenizes string. | |
| std::vector< std::wstring > | strtok (std::wstring_view const &tokens, std::wstring_view const &delims, bool const ignore_empty=true) |
| auto | strtok (std::string_view const &tokens, char const delim, bool const ignore_empty=true) |
| auto | strtok (std::wstring_view const &tokens, wchar_t const delim, bool const ignore_empty=true) |
| std::vector< std::string_view > | strtok_view (std::string_view const &tokens, std::string_view const &delims, bool const ignore_empty=true) |
| Tokenizes string. | |
| std::vector< std::wstring_view > | strtok_view (std::wstring_view const &tokens, std::wstring_view const &delims, bool const ignore_empty=true) |
| auto | strtok_view (std::string_view const &tokens, char const delim, bool const ignore_empty=true) |
| auto | strtok_view (std::wstring_view const &tokens, wchar_t const delim, bool const ignore_empty=true) |
| template<typename T> | |
| T | to_integral (std::string_view const &s, T const errorval=T()) |
| Converts string to integral type T. If string is not convertible, errorval is returned. | |
| template<typename T> | |
| T | to_integral (std::wstring_view const &s, T const errorval=T()) |
| template<typename T, typename StringType> | |
| T | to_integral (std::basic_string_view< StringType > const &s, T const errorval=T()) |
| template<typename T> | |
| std::optional< T > | to_integral_o (std::string_view const &s) |
| Converts string to integral type T. If string is not convertible, nullopt. | |
| template<typename T> | |
| std::optional< T > | to_integral_o (std::wstring_view const &s) |
| template<typename T, typename StringType> | |
| std::optional< T > | to_integral_o (std::basic_string_view< StringType > const &s) |
| template<typename String> | |
| bool | str_is_ascii (String const &s) |
| Returns true iff the string only has characters in the 7-bit ASCII range. | |
| std::string | trimmed (std::string_view s, std::string_view const &chars=" \r\n\t", bool fromLeft=true, bool fromRight=true) |
| Return passed string with all leading and trailing whitespace removed. | |
| std::wstring | trimmed (std::wstring_view s, std::wstring_view const &chars=L" \r\n\t", bool fromLeft=true, bool fromRight=true) |
| std::string | ltrimmed (std::string_view s, std::string_view const &chars=" \r\n\t") |
| std::wstring | ltrimmed (std::wstring_view s, std::wstring_view const &chars=L" \r\n\t") |
| std::string | rtrimmed (std::string_view s, std::string_view const &chars=" \r\n\t") |
| std::wstring | rtrimmed (std::wstring_view s, std::wstring_view const &chars=L" \r\n\t") |
| template<typename String, typename std::enable_if_t< std::is_same_v< typename String::value_type, char >, int > = 0> | |
| void | trim (String &s, std::string_view const &chars=" \r\n\t", bool fromLeft=true, bool fromRight=true) |
| Remove all leading and trailing whitespace from string. | |
| template<typename String, typename std::enable_if_t< std::is_same_v< typename String::value_type, wchar_t >, int > = 0> | |
| void | trim (String &s, std::wstring_view const &chars=L" \r\n\t", bool fromLeft=true, bool fromRight=true) |
| template<typename String, typename std::enable_if_t< std::is_same_v< typename String::value_type, char >, int > = 0> | |
| void | ltrim (String &s, std::string_view const &chars=" \r\n\t") |
| template<typename String, typename std::enable_if_t< std::is_same_v< typename String::value_type, wchar_t >, int > = 0> | |
| void | ltrim (String &s, std::wstring_view const &chars=L" \r\n\t") |
| template<typename String, typename std::enable_if_t< std::is_same_v< typename String::value_type, char >, int > = 0> | |
| void | rtrim (String &s, std::string_view const &chars=" \r\n\t") |
| template<typename String, typename std::enable_if_t< std::is_same_v< typename String::value_type, wchar_t >, int > = 0> | |
| void | rtrim (String &s, std::wstring_view const &chars=L" \r\n\t") |
| template<bool insensitive_ascii = false, typename String, typename Beginning> | |
| std::enable_if_t< std::is_same_v< string_value_type_t< String >, string_value_type_t< Beginning > >, bool > | starts_with (String const &s, Beginning const &beginning) |
| Tests whether the first string starts with the second string. | |
| template<bool insensitive_ascii = false, typename String, typename Ending> | |
| std::enable_if_t< std::is_same_v< string_value_type_t< String >, string_value_type_t< Ending > >, bool > | ends_with (String const &s, Ending const &ending) |
| Tests whether the first string ends with the second string. | |
| std::string | normalize_hyphens (std::string_view const &in) |
| std::wstring | normalize_hyphens (std::wstring_view const &in) |
| bool | is_valid_utf8 (std::string_view s) |
| Verifies that the input data is valid UTF-8. | |
| bool | is_valid_utf8 (std::string_view s, size_t &state) |
| Verifies that the input data is valid UTF-8. | |
| void | unicode_codepoint_to_utf8_append (std::string &result, uint32_t codepoint) |
| Encodes a valid Unicode codepoint as UTF-8 and appends it to the passed string. | |
| bool | utf16be_to_utf8_append (std::string &result, std::string_view data, uint32_t &state) |
| Converts from UTF-16-BE and appends it to the passed string. | |
| bool | utf16le_to_utf8_append (std::string &result, std::string_view data, uint32_t &state) |
| Just as utf16be_to_utf8_append but for little-endian UTF-16. | |
| native_string | to_native_from_utf8 (std::string_view s) |
| void | wipe_conversion_cache () |
String types and assorted functions.
Defines the native_string type and offers various functions to convert between different string types.
| #define fzS | ( | Char, | |
| s ) |
Macro to get const pointer to a string of the corresponding type.
Useful when using string literals in templates where the type of string is a template argument:
| #define fzT | ( | x | ) |
Macro for a string literal in system-native character type.
Note: Macro definition changes depending on platform!
Example: fzT("this string is wide on Windows and narrow elsewhere")