libxcks  0.1.0.1
strutil.hpp File Reference

String utilities. More...

#include <string>
#include <ctime>
Include dependency graph for strutil.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void libxcks::ltrim (std::string &s)
 Trim from start (in place). More...
 
void libxcks::rtrim (std::string &s)
 Trim from end (in place). More...
 
void libxcks::trim (std::string &s)
 Trim from both ends (in place). More...
 
std::string libxcks::ltrim_copy (std::string s)
 Trim from start (copying). More...
 
std::string libxcks::rtrim_copy (std::string s)
 Trim from end (copying). More...
 
std::string libxcks::trim_copy (std::string s)
 Trim from both ends (copying). More...
 
std::string libxcks::replaceAllCopy (std::string str, const std::string &from, const std::string &to)
 Replace all occurrences of a substring by another in a string. More...
 
void libxcks::replaceAll (std::string &str, const std::string &from, const std::string &to)
 Replace in-place all occurrences of a substring by another in a string. More...
 
bool libxcks::stringICompare (const std::string &str1, const std::string &str2)
 Case-insensitive comparison of two strings. More...
 
std::string libxcks::from_u8string (const std::string &s)
 Returns an UTF-8 encoded string in an object of type std::string (C++17). More...
 
std::string libxcks::from_u8string (std::string &&s)
 Returns an UTF-8 encoded string in an object of type std::string (C++17). More...
 
time_t libxcks::parseISO8601 (const std::string &iso8601)
 Parse ISO 8601 date/time. More...
 
std::string libxcks::escapeForXML (const std::string &str)
 Escapes a string for writing it in a XML stream. More...
 

Detailed Description

String utilities.

Definition in file strutil.hpp.

Function Documentation

◆ escapeForXML()

std::string libxcks::escapeForXML ( const std::string &  str)

Escapes a string for writing it in a XML stream.

Note
This function doesn't recognize XML tags, so use it only on plain text.
The input string mustn't contain any XML escaped character.
Parameters
strThe string to escape.
Returns
An escaped string for writing in a XML string.

Definition at line 318 of file strutil.cpp.

◆ from_u8string() [1/2]

std::string libxcks::from_u8string ( const std::string &  s)

Returns an UTF-8 encoded string in an object of type std::string (C++17).

This function just returns the string.

Parameters
[in]sThe UTF-8 encoded string.
Returns
The UTF-8 encoded string.

Definition at line 217 of file strutil.cpp.

◆ from_u8string() [2/2]

std::string libxcks::from_u8string ( std::string &&  s)

Returns an UTF-8 encoded string in an object of type std::string (C++17).

This function just moves the string.

Parameters
[in]sThe UTF-8 encoded string.
Returns
The UTF-8 encoded string.

Definition at line 232 of file strutil.cpp.

◆ ltrim()

void libxcks::ltrim ( std::string &  s)

Trim from start (in place).

Parameters
[in,out]sThe string to trim from start.

Definition at line 53 of file strutil.cpp.

◆ ltrim_copy()

std::string libxcks::ltrim_copy ( std::string  s)

Trim from start (copying).

Parameters
[in]sThe string to trim from start.
Returns
The trimmed string from start.

Definition at line 95 of file strutil.cpp.

◆ parseISO8601()

std::time_t libxcks::parseISO8601 ( const std::string &  iso8601)

Parse ISO 8601 date/time.

Parameters
[in]iso8601The string containing the ISO 8601 date/time.
Returns
The read date/time or Invalid_DateTime on unsuccessfully parse.

Definition at line 265 of file strutil.cpp.

◆ replaceAll()

void libxcks::replaceAll ( std::string &  str,
const std::string &  from,
const std::string &  to 
)

Replace in-place all occurrences of a substring by another in a string.

Parameters
[in]strThe string to search in.
[in]fromThe substring to replace in str.
[in]toThe substitution substring.
Returns
The string with all occurrences of a from replaced by to.

Definition at line 166 of file strutil.cpp.

◆ replaceAllCopy()

std::string libxcks::replaceAllCopy ( std::string  str,
const std::string &  from,
const std::string &  to 
)

Replace all occurrences of a substring by another in a string.

Parameters
[in]strThe string to search in.
[in]fromThe substring to replace in str.
[in]toThe substitution substring.
Returns
The string with all occurrences of a from replaced by to.

Definition at line 145 of file strutil.cpp.

◆ rtrim()

void libxcks::rtrim ( std::string &  s)

Trim from end (in place).

Parameters
[in,out]sThe string to trim from end.

Definition at line 67 of file strutil.cpp.

◆ rtrim_copy()

std::string libxcks::rtrim_copy ( std::string  s)

Trim from end (copying).

Parameters
[in]sThe string to trim from end.
Returns
The trimmed string from end.

Definition at line 109 of file strutil.cpp.

◆ stringICompare()

bool libxcks::stringICompare ( const std::string &  str1,
const std::string &  str2 
)

Case-insensitive comparison of two strings.

Parameters
[in]str1First string to compare.
[in]str2Second string to compare.
Returns
true if the two string are case-insensitive equals or false otherwise.

Definition at line 191 of file strutil.cpp.

◆ trim()

void libxcks::trim ( std::string &  s)

Trim from both ends (in place).

Parameters
[in,out]sThe string to trim from both ends.

Definition at line 81 of file strutil.cpp.

◆ trim_copy()

std::string libxcks::trim_copy ( std::string  s)

Trim from both ends (copying).

Parameters
[in]sThe string to trim from both ends.
Returns
The trimmed string from both ends.

Definition at line 123 of file strutil.cpp.