Tkrzw
Classes | Namespaces | Functions
tkrzw_str_util.h File Reference

String utilities. More...

#include <map>
#include <string>
#include <vector>
#include <cinttypes>
#include "tkrzw_lib_common.h"

Classes

class  tkrzw::ScopedStringView
 Wrapper of string_view of allocated memory. More...
 

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...
 
double tkrzw::StrToDouble (std::string_view str, double defval=0.0)
 Converts a decimal string to a real number. More...
 
uint64_t tkrzw::StrToIntBigEndian (std::string_view str)
 Converts a big-endian binary string to an integer. More...
 
long double tkrzw::StrToFloatBigEndian (std::string_view str)
 Converts a big-endian binary string to a real number. More...
 
uint64_t tkrzw::StrToIntDelta (std::string_view str, bool zigzag)
 Converts a byte-delta-encoded string into an integer. More...
 
bool tkrzw::StrToBool (std::string_view str, bool defval=false)
 Converts a boolean string to a boolean value. More...
 
int64_t tkrzw::StrToIntOrBool (std::string_view str, int64_t defval=0)
 Converts a decimal or boolean string to an integer or boolean value. 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...
 
std::string tkrzw::FloatToStrBigEndian (long double data, size_t size=sizeof(double))
 Converts a floating-point number into a big-endian binary string. More...
 
std::string tkrzw::IntToStrDelta (uint64_t data, bool zigzag)
 Converts an integer into a string in byte delta encoding. More...
 
template<typename T >
std::string tkrzw::StrJoin (const T &elems, 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...
 
void tkrzw::StrUpperCase (std::string *str)
 Converts letters of a string into upper case in-place. More...
 
std::string tkrzw::StrLowerCase (std::string_view str)
 Converts letters of a string into lower case. More...
 
void tkrzw::StrLowerCase (std::string *str)
 Converts letters of a string into lower case in-place. 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...
 
void tkrzw::StrReplaceCharacters (std::string *str, std::string_view before, std::string_view after)
 Modifies a string by replacing characters to diffent characters in-place. More...
 
bool tkrzw::StrContains (std::string_view text, std::string_view pattern)
 Checks whether a text contains a pattern. More...
 
bool tkrzw::StrCaseContains (std::string_view text, std::string_view pattern)
 Checks whether a text contains a pattern in a case-insensitive manner. More...
 
bool tkrzw::StrWordContains (std::string_view text, std::string_view pattern)
 Checks whether a text contains a word surrounded by non-alphanumeric word boundaries. More...
 
bool tkrzw::StrCaseWordContains (std::string_view text, std::string_view pattern)
 Checks whether a text contains a word in a case-sensitive manner. More...
 
bool tkrzw::StrContainsBatch (std::string_view text, const std::vector< std::string > &patterns)
 Checks a text contains at least one of patterns. More...
 
bool tkrzw::StrCaseContainsBatch (std::string_view text, const std::vector< std::string > &patterns)
 Checks a text contains at least one of patterns in a case-sensitive manner. More...
 
bool tkrzw::StrWordContainsBatch (std::string_view text, const std::vector< std::string > &patterns)
 Checks a text contains at least one of words surrounded by non-alphanumeric word boundaries. More...
 
bool tkrzw::StrCaseWordContainsBatch (std::string_view text, const std::vector< std::string > &patterns)
 Checks a text contains at least one of words in a case-sensitive manner. More...
 
bool tkrzw::StrCaseWordContainsBatchLower (std::string_view text, const std::vector< std::string > &patterns)
 Checks a text contains at least one of lowercase words in a case-sensitive manner. 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...
 
int32_t tkrzw::StrCaseSearch (std::string_view text, std::string_view pattern)
 Searches a text for a pattern in a case-insensitive manner. More...
 
int32_t tkrzw::StrWordSearch (std::string_view text, std::string_view pattern)
 Searches a text for a word surrounded by non-alphanumeric word boundaries. More...
 
int32_t tkrzw::StrCaseWordSearch (std::string_view text, std::string_view pattern)
 Searches a text for a word surrounded in a case-insensitive manner. 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...
 
void tkrzw::StrStripLine (std::string *str)
 Remove linefeed characters from the end of a string in-place. 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...
 
int32_t tkrzw::StrSearchRegex (std::string_view text, std::string_view pattern)
 Searches a string for a pattern matching a regular expression. More...
 
std::string tkrzw::StrReplaceRegex (std::string_view text, std::string_view pattern, std::string_view replace)
 Replaces substrings matching a pattern of regular expression. 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::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::vector< std::string > tkrzw::MakeStrVectorFromViews (const std::vector< std::string_view > &views)
 Makes a string vector from a string view vector. More...
 
std::vector< std::string_view > tkrzw::MakeStrViewVectorFromValues (const std::vector< std::string > &values)
 Makes a string view vector from 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...
 
std::map< std::string, std::string > tkrzw::MakeStrMapFromViews (const std::map< std::string_view, std::string_view > &views)
 Makes a string map from a string view map. More...
 
std::map< std::string_view, std::string_view > tkrzw::MakeStrViewMapFromRecords (const std::map< std::string, std::string > &records)
 Makes a string view map from a string map. More...
 
template<typename T >
std::string tkrzw::SerializeBasicValue (T value)
 Serializes a value of a basic type into a string. More...
 
template<typename T >
tkrzw::DeserializeBasicValue (std::string_view serialized)
 Deserializes a string into a value of a basic type. More...
 
template<typename T >
std::string tkrzw::SerializeBasicVector (const std::vector< T > &values)
 Serializes a vector of a basic type into a string. More...
 
template<typename T >
std::vector< T > tkrzw::DeserializeBasicVector (std::string_view serialized)
 Deserializes a string into a vector of a basic type. More...
 
template<typename T >
std::string tkrzw::SerializeIntVectorDelta (const std::vector< T > &values, bool zigzag)
 Serializes a vector of an integer type into a string in byte delta encoding. More...
 
template<typename T >
std::vector< T > tkrzw::DeserializeIntVectorDelta (std::string_view serialized, bool zigzag)
 Deserializes a byte-delta-encoded string into a vector of an integer type. More...
 

Detailed Description

String utilities.