Easy3D 2.5.3
easy3d::string Namespace Reference

String manipulation utilities. More...

Functions

void split (const std::string &in, char separator, std::vector< std::string > &out, bool skip_empty_fields=true)
 Splits a string into parts. More...
 
bool split (const std::string &in, char separator, std::string &left, std::string &right)
 Splits a string into two parts. More...
 
std::string join (const std::vector< std::string > &in, char separator)
 Join multiple strings. More...
 
std::string join (const std::vector< std::string > &in, const std::string &separator)
 Join multiple strings. More...
 
void replace (std::string &in, const std::string &old_substr, const std::string &new_substr)
 Replaces the old sub-string by a new sub-string.
 
std::string to_lowercase (const std::string &s)
 Converts a string to lowercase. More...
 
std::string to_uppercase (const std::string &s)
 Converts a string to uppercase. More...
 
std::string quote (const std::string &s, char quotes='\"')
 Adds quotes to a string. More...
 
bool starts_with (const std::string &haystack, const std::string &needle)
 Checks if a string starts with a substring. More...
 
bool ends_with (const std::string &haystack, const std::string &needle)
 Checks if a string ends with a substring. More...
 
std::string to_string (int value, int width, char fill='0')
 Converts an integer value to a string of a desired length. More...
 
void append_v (std::string &dst, const char *format, va_list ap)
 
std::string printf (const char *format,...)
 
void appendf (std::string &dst, const char *format,...)
 Appends the resulting string to a supplied string.
 
std::string date_time ()
 Gets the time string, e.g., "Fri Jan 09 11:39:32 2015".
 
std::string time (double time, int num_digits=1)
 Converts time (in millisecond) into a string with the most suitable/readable unit. The result will look like e.g., 88ms, 2.3s, 1.7m, 0.1h.
 
std::wstring to_wstring (const std::string &str)
 Converts from std::string to std::wstring.
 
std::string from_wstring (const std::wstring &wstr)
 Converts from std::wstring to std::string.
 
std::string to_string (char c)
 Creates a one char string. More...
 

Detailed Description

String manipulation utilities.

Function Documentation

◆ ends_with()

bool ends_with ( const std::string &  haystack,
const std::string &  needle 
)

Checks if a string ends with a substring.

Parameters
[in]haystackthe input string
[in]needlethe substring to check
Returns
true if haystack ends with needle, false otherwise.

◆ join() [1/2]

std::string join ( const std::vector< std::string > &  in,
char  separator 
)

Join multiple strings.

Joins all the strings in list in into a single string with each element separated by the given separator character.

Parameters
[in]inthe list of strings to join
[in]separatorthe separator character
Returns
the joined string
See also
split_string()

◆ join() [2/2]

std::string join ( const std::vector< std::string > &  in,
const std::string &  separator 
)

Join multiple strings.

Joins all the strings in list in into a single string with each element separated by the given separator string.

Parameters
[in]inthe list of strings to join
[in]separatorthe separator string (can be an empty string)
Returns
the joined string
See also
split_string()

◆ printf()

std::string printf ( const char *  format,
  ... 
)

Return a C++ string and work like printf.

◆ quote()

std::string quote ( const std::string &  s,
char  quotes = '\"' 
)

Adds quotes to a string.

Adds character quote at the beginning and the end of string s and returns the resulting string.

Parameters
[in]sthe string to quote
[in]quotesthe quoting char (default is '"')
Returns
the quoted string

◆ split() [1/2]

bool split ( const std::string &  in,
char  separator,
std::string &  left,
std::string &  right 
)

Splits a string into two parts.

Parameters
[in]inthe input string to split
[in]separatorthe separator character
[in]leftthe part of the input string on the left of the separator or the empty string if the separator did not appear in the input string
[in]rightthe right of the input string on the left of the separator or the empty string if the separator did not appear in the input string
Return values
trueif the separator was found in the input string
falseotherwise

◆ split() [2/2]

void split ( const std::string &  in,
char  separator,
std::vector< std::string > &  out,
bool  skip_empty_fields = true 
)

Splits a string into parts.

Splits the string in into a list of substrings out wherever separator occurs.

Parameters
[in]inthe input string to split
[in]separatorthe separator character
[in]outthe resulting list of substrings
[in]skip_empty_fieldsspecifies whether empty parts should be ignored and not stored in list out (this is true by default).
See also
join_strings()

◆ starts_with()

bool starts_with ( const std::string &  haystack,
const std::string &  needle 
)

Checks if a string starts with a substring.

Parameters
[in]haystackthe input string
[in]needlethe substring to check
Returns
true if haystack starts with needle, false otherwise.

◆ to_lowercase()

std::string to_lowercase ( const std::string &  s)

Converts a string to lowercase.

The conversion is done in place in the string s.

Parameters
[in,out]sThe string to convert
See also
to_uppercase()

◆ to_string() [1/2]

std::string easy3d::string::to_string ( char  c)
inline

Creates a one char string.

Parameters
[in]cthe character to convert to a string
Returns
a string that contains character c

◆ to_string() [2/2]

std::string to_string ( int  value,
int  width,
char  fill = '0' 
)

Converts an integer value to a string of a desired length.

Different from the std::to_string(), this method results in a fixed-width string by filling the missing parts with character fill.

◆ to_uppercase()

std::string to_uppercase ( const std::string &  s)

Converts a string to uppercase.

The conversion is done in place in the string s.

Parameters
[in,out]sThe string to convert
See also
to_lowercase()