Tkrzw
|
String utilities. More...
#include <map>
#include <string>
#include <vector>
#include <cinttypes>
#include "tkrzw_lib_common.h"
Namespaces | |
tkrzw | |
Common namespace of Tkrzw. | |
Functions | |
int64_t | tkrzw::StrToInt (std::string_view str, int64_t defval=0) |
Converts a decimal string to an integer. More... | |
int64_t | tkrzw::StrToIntMetric (std::string_view str, int64_t defval=0) |
Converts a decimal string with a metric prefix to an integer. More... | |
uint64_t | tkrzw::StrToIntOct (std::string_view str, uint64_t defval=0) |
Converts a octal string to an integer. More... | |
uint64_t | tkrzw::StrToIntHex (std::string_view str, uint64_t defval=0) |
Converts a hexadecimal string to an integer. More... | |
uint64_t | tkrzw::StrToIntBigEndian (std::string_view str) |
Converts a big-endian binary string to an integer. More... | |
double | tkrzw::StrToDouble (std::string_view str, double defval=0.0) |
Converts a decimal string to a real number. More... | |
bool | tkrzw::StrToBool (std::string_view str, bool defval=false) |
Converts a boolean string to a real number. More... | |
void | tkrzw::VSPrintF (std::string *dest, const char *format, va_list ap) |
Appends a formatted string at the end of a string. More... | |
void | tkrzw::SPrintF (std::string *dest, const char *format,...) |
Appends a formatted string at the end of a string. More... | |
std::string | tkrzw::SPrintF (const char *format,...) |
Generates a formatted string. More... | |
template<typename T > | |
std::string | tkrzw::ToString (T data) |
Converts an integer to a decimal string. More... | |
std::string | tkrzw::ToString (double data) |
Converts a real number to a decimal string. More... | |
std::string | tkrzw::ToString (float data) |
Converts a real number to a decimal string. More... | |
std::string | tkrzw::ToString (long double data) |
Converts a real number to a decimal string. More... | |
std::string | tkrzw::ToString (bool data) |
Converts a boolean value to a decimal string. More... | |
std::string | tkrzw::ToString (char data) |
Converts a character into a string. More... | |
std::string | tkrzw::ToString (const char *data) |
Converts a C-style string into a string. More... | |
std::string | tkrzw::ToString (std::string_view data) |
Converts a string view into a string. More... | |
std::string | tkrzw::ToString (const std::string &data) |
Copies a string. More... | |
std::string | tkrzw::IntToStrBigEndian (uint64_t data, size_t size=sizeof(uint64_t)) |
Converts an integer into a big-endian binary string. More... | |
template<typename T > | |
std::string | tkrzw::StrJoin (const T &elems, const std::string_view &delim) |
Converts each record of a container into strings and join them. More... | |
std::string | tkrzw::StrCat () |
Returns an empty string. More... | |
template<typename FIRST , typename... REST> | |
std::string | tkrzw::StrCat (const FIRST &first, const REST &... rest) |
Concatenates data of arbitrary parameters into a string. More... | |
std::vector< std::string > | tkrzw::StrSplit (std::string_view str, char delim, bool skip_empty=false) |
Splits a string with a delimiter character. More... | |
std::vector< std::string > | tkrzw::StrSplit (std::string_view str, std::string_view delim, bool skip_empty=false) |
Splits a string with a delimiter string. More... | |
std::vector< std::string > | tkrzw::StrSplitAny (std::string_view str, std::string_view delims, bool skip_empty=false) |
Splits a string with delimiter characters. More... | |
std::map< std::string, std::string > | tkrzw::StrSplitIntoMap (std::string_view str, std::string_view delim_records, std::string_view delim_kv) |
Splits a string into a key-value map. More... | |
std::string | tkrzw::StrUpperCase (std::string_view str) |
Converts letters of a string into upper case. More... | |
std::string | tkrzw::StrLowerCase (std::string_view str) |
Converts letters of a string into lower case. More... | |
std::string | tkrzw::StrReplace (std::string_view str, std::string_view before, std::string_view after) |
Converts a string by replacing substrings to diffent substrings. More... | |
bool | tkrzw::StrContains (std::string_view text, std::string_view pattern) |
Checks whether a text contains a pattern. More... | |
bool | tkrzw::StrBeginsWith (std::string_view text, std::string_view pattern) |
Checks whether a text begins with a pattern. More... | |
bool | tkrzw::StrEndsWith (std::string_view text, std::string_view pattern) |
Checks whether a text ends with a pattern. More... | |
int32_t | tkrzw::StrCaseCompare (std::string_view a, std::string_view b) |
Compares two strings ignoring case. More... | |
int32_t | tkrzw::StrSearch (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, with string::find. More... | |
int32_t | tkrzw::StrSearchDoubleLoop (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, by naive double loop. More... | |
int32_t | tkrzw::StrSearchMemchr (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, with memchr. More... | |
int32_t | tkrzw::StrSearchMemmem (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, with memmem. More... | |
int32_t | tkrzw::StrSearchKMP (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, by Knuth–Morris–Pratt algorithm. More... | |
int32_t | tkrzw::StrSearchBM (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, by Boyer-Moore algorithm. More... | |
int32_t | tkrzw::StrSearchRK (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, by Rabin-Karp algorithm. More... | |
int32_t | tkrzw::StrSearchZ (std::string_view text, std::string_view pattern) |
Searches a text for a pattern, by Z algorithm. More... | |
std::vector< int32_t > | tkrzw::StrSearchWhole (std::string_view text, std::string_view pattern, size_t max_results=0) |
Searches a text for a pattern and get indices of all occurrences, with string::find. More... | |
std::vector< int32_t > | tkrzw::StrSearchWholeKMP (std::string_view text, std::string_view pattern, size_t max_results=0) |
Searches a text for a pattern and get indices of all occurrences, by KMP algorithm. More... | |
std::vector< int32_t > | tkrzw::StrSearchWholeBM (std::string_view text, std::string_view pattern, size_t max_results=0) |
Searches a text for a pattern and get indices of all occurrences, by BM algorithm. More... | |
std::vector< int32_t > | tkrzw::StrSearchWholeRK (std::string_view text, std::string_view pattern, size_t max_results=0) |
Searches a text for a pattern and get indices of all occurrences, by RK algorithm. More... | |
std::vector< std::vector< int32_t > > | tkrzw::StrSearchBatch (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0) |
Searches a text for patterns and get indices of all occurrences, by string::find. More... | |
std::vector< std::vector< int32_t > > | tkrzw::StrSearchBatchKMP (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0) |
Searches a text for patterns and get indices of all occurrences, by KMP algorithm. More... | |
std::vector< std::vector< int32_t > > | tkrzw::StrSearchBatchBM (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0) |
Searches a text for patterns and get indices of all occurrences, by BM algorithm. More... | |
std::vector< std::vector< int32_t > > | tkrzw::StrSearchBatchRK (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0) |
Searches a text for patterns and get indices of all occurrences, by RK algorithm. More... | |
std::string | tkrzw::StrStripSpace (std::string_view str) |
Removes space characters at the head or the tail of a string. More... | |
std::string | tkrzw::StrStripLine (std::string_view str) |
Removes linefeed characters from the end of a string. More... | |
std::string | tkrzw::StrSqueezeAndStripSpace (std::string_view str) |
Squeezes space characters in a string and removes spaces at both ends. More... | |
std::string | tkrzw::StrTrimForTSV (std::string_view str, bool keep_tab=false) |
Trims a string for TSV by normalizing space and control characters. More... | |
std::string | tkrzw::StrEscapeC (std::string_view str, bool esc_nonasc=false) |
Escapes C-style meta characters in a string. More... | |
std::string | tkrzw::StrUnescapeC (std::string_view str) |
Unescapes C-style escape sequences in a string. More... | |
std::string | tkrzw::StrEncodeBase64 (std::string_view str) |
Encodes a string into a Base64 string. More... | |
std::string | tkrzw::StrDecodeBase64 (std::string_view str) |
Decodes a Base64 string into a string. More... | |
std::string | tkrzw::StrEncodeURL (std::string_view str) |
Encodes a string into a URL part string. More... | |
std::string | tkrzw::StrDecodeURL (std::string_view str) |
Decodes a URL part string into a string. More... | |
std::vector< uint32_t > | tkrzw::ConvertUTF8ToUCS4 (std::string_view utf) |
Converts a UTF-8 string into a UCS-4 vector. More... | |
std::string | tkrzw::ConvertUCS4ToUTF8 (const std::vector< uint32_t > &ucs) |
Converts a UCS-4 vector into a UTF-8 string. More... | |
std::wstring | tkrzw::ConvertUTF8ToWide (std::string_view utf) |
Converts a UTF-8 string into a wide string. More... | |
std::string | tkrzw::ConvertWideToUTF8 (const std::wstring &wstr) |
Converts a wide string into a UTF-8 string. More... | |
std::string | tkrzw::MakeRandomCharacterText (int32_t length, uint8_t first_char, uint8_t last_char) |
Makes a text composed of characters selected at random. More... | |
std::string | tkrzw::SerializeStrPair (std::string_view first, std::string_view second) |
Serializes a pair of strings into a string. More... | |
void | tkrzw::DeserializeStrPair (std::string_view serialized, std::string_view *first, std::string_view *second) |
Deserializes a serialized string into a pair of strings. More... | |
std::string_view | tkrzw::GetFirstFromSerializedStrPair (std::string_view serialized) |
Get the first part from a serialized string pair. More... | |
std::string | tkrzw::SerializeStrVector (const std::vector< std::string > &values) |
Serializes a vector of strings into a string. More... | |
std::vector< std::string > | tkrzw::DeserializeStrVector (std::string_view serialized) |
Deserializes a serialized string into a string vector. More... | |
std::string | tkrzw::SerializeStrMap (const std::map< std::string, std::string > &records) |
Serializes a map of strings into a string. More... | |
std::map< std::string, std::string > | tkrzw::DeserializeStrMap (std::string_view serialized) |
Deserializes a serialized string into a string map. More... | |
String utilities.