userver: userver/utils/text.hpp File Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
text.hpp File Reference

Text utilities. More...

#include <locale>
#include <string>
#include <string_view>
#include <vector>
#include <boost/multiprecision/cpp_dec_float.hpp>
+ Include dependency graph for text.hpp:

Go to the source code of this file.

Namespaces

namespace  utils
 Utilities.
 
namespace  utils::text
 Text utilities.
 
namespace  utils::text::utf8
 UTF8 text utilities.
 

Functions

std::string utils::text::Trim (const std::string &str)
 Return trimmed copy of string.
 
std::string utils::text::Trim (std::string &&str)
 Trim string in-place.
 
std::vector< std::string > utils::text::Split (std::string_view str, std::string_view separators)
 
std::vector< std::string_view > utils::text::SplitIntoStringViewVector (std::string_view str, std::string_view separators)
 
std::string utils::text::Join (const std::vector< std::string > &strs, std::string_view sep)
 Join string.
 
std::string utils::text::Format (double value, const std::string &locale, int ndigits=0, bool is_fixed=true)
 Return number formatted with specified locale.
 
std::string utils::text::Format (double value, int ndigits)
 Return number formatted.
 
std::string utils::text::Format (boost::multiprecision::cpp_dec_float_50 value, int ndigits)
 Return cpp_dec_float_50 formatted.
 
bool utils::text::StartsWith (std::string_view hay, std::string_view needle) noexcept
 Return true if hay starts with needle, false otherwise.
 
bool utils::text::EndsWith (std::string_view hay, std::string_view needle) noexcept
 Return true if hay ends with needle, false otherwise.
 
std::string utils::text::ToLower (std::string_view str, const std::string &locale=kEnLocale)
 Transform letters to lower case.
 
std::string utils::text::Capitalize (std::string_view str, const std::string &locale)
 Capitalizes the first letter of the str.
 
std::string utils::text::RemoveQuotes (std::string_view str)
 
bool utils::text::IsAscii (char ch) noexcept
 Checks whether the character is an ASCII character.
 
bool utils::text::IsAsciiSpace (char ch) noexcept
 Checks whether the character is a whitespace character in C locale.
 
bool utils::text::IsAscii (std::string_view text) noexcept
 Checks if text contains only ASCII characters.
 
const std::locale & utils::text::GetLocale (const std::string &name)
 Returns a locale with the specified name.
 
unsigned utils::text::utf8::CodePointLengthByFirstByte (unsigned char c) noexcept
 Returns the length in bytes of the UTF-8 code point by the first byte.
 
bool utils::text::utf8::IsWellFormedCodePoint (const unsigned char *bytes, std::size_t length) noexcept
 bytes must not be a nullptr, length must not be 0.
 
bool utils::text::utf8::IsValid (const unsigned char *bytes, std::size_t length) noexcept
 bytes must not be a nullptr, length must not be 0.
 
std::size_t utils::text::utf8::GetCodePointsCount (std::string_view text)
 
void utils::text::utf8::TrimTruncatedEnding (std::string &str)
 
void utils::text::utf8::TrimViewTruncatedEnding (std::string_view &view)
 
std::size_t utils::text::utf8::GetTextPosByCodePointPos (std::string_view text, std::size_t pos) noexcept
 
void utils::text::utf8::RemovePrefix (std::string &text, std::size_t count) noexcept
 
void utils::text::utf8::RemoveViewPrefix (std::string_view &text, std::size_t count) noexcept
 
void utils::text::utf8::TakePrefix (std::string &text, std::size_t count) noexcept
 
void utils::text::utf8::TakeViewPrefix (std::string_view &text, std::size_t count) noexcept
 
bool utils::text::IsUtf8 (std::string_view text) noexcept
 Checks if text is in utf-8 encoding.
 
bool utils::text::IsPrintable (std::string_view text, bool ascii_only=true) noexcept
 
bool utils::text::IsCString (std::string_view text) noexcept
 Checks if there are no embedded null ('\0') characters in text.
 
std::string utils::text::CamelCaseToSnake (std::string_view camel)
 convert CamelCase to snake_case(underscore)
 

Variables

const std::string utils::text::kEnLocale {"en_US.UTF-8"}
 

Detailed Description

Text utilities.

Definition in file text.hpp.