Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
granada::util::string Namespace Reference

Functions

static void ltrim (std::string &s)
 
static void rtrim (std::string &s)
 
static void trim (std::string &s)
 
static void split (const std::string &s, char delim, std::vector< std::string > &elems)
 
static void replace (std::string &content, const std::deque< std::pair< std::string, std::string >> &values, const std::string &open, const std::string &close)
 
static void replace (std::string &content, const std::unordered_map< std::string, std::string > &values, const std::string &open, const std::string &close)
 
static void replace (std::string &content, const std::deque< std::pair< std::string, std::string >> &values)
 
static void replace (std::string &content, const std::unordered_map< std::string, std::string > &values)
 
static web::json::value to_json (const std::string &str)
 
static std::string stringified_json (const std::string &str)
 
static void to_upper (std::string &str)
 
static void to_lower (std::string &str)
 

Detailed Description

Utils for string manipulation.

Function Documentation

static void granada::util::string::ltrim ( std::string &  s)
inlinestatic

Trim from start

Parameters
sString to ltrim.
static void granada::util::string::replace ( std::string &  content,
const std::deque< std::pair< std::string, std::string >> &  values,
const std::string &  open,
const std::string &  close 
)
static

Replace a map of key tags in a string by a value. Example: content: hello {{username}} !!! {{date}} Replace map: username => "John Doe" date => "Tuesday, May 17, 2016" Open: {{ , Close: }} Result: hello John Doe !!! Tuesday, May 17, 2016

Parameters
contentContent containing the tags to replace.
valuesDeque with the key-values pairs containing the values to replace in the file.
openBefore tag mark.
closeAfter tag mark.
static void granada::util::string::replace ( std::string &  content,
const std::unordered_map< std::string, std::string > &  values,
const std::string &  open,
const std::string &  close 
)
static

Replace a map of key tags in a string by a value. Example: content: hello {{username}} !!! {{date}} Replace map: username => "John Doe" date => "Tuesday, May 17, 2016" Open: {{ , Close: }} Result: hello John Doe !!! Tuesday, May 17, 2016

Parameters
contentContent containing the tags to replace.
valuesMap with the key-values pairs containing the values to replace in the file.
openBefore tag mark.
closeAfter tag mark.
static void granada::util::string::replace ( std::string &  content,
const std::deque< std::pair< std::string, std::string >> &  values 
)
inlinestatic

Replace a deque of key tags in a string by a value using before and after tag marks: open "{{" and default close "}}"

Parameters
contentontent containing the tags to replace.
valuesDeque with the key-values pairs containing the values to replace in the file.
static void granada::util::string::replace ( std::string &  content,
const std::unordered_map< std::string, std::string > &  values 
)
inlinestatic

Replace a map of key tags in a string by a value using before and after tag marks: open "{{" and default close "}}"

Parameters
contentontent containing the tags to replace.
valuesMap with the key-values pairs containing the values to replace in the file.
static void granada::util::string::rtrim ( std::string &  s)
inlinestatic

Trim from end

Parameters
sString to rtrim.
static void granada::util::string::split ( const std::string &  s,
char  delim,
std::vector< std::string > &  elems 
)
static

Split a string into a vector with a given delimiter.

Parameters
sString to split.
delimDelimiter.
elemsVector containing the splitted string.
Returns
Vector containing the splitted string.
static std::string granada::util::string::stringified_json ( const std::string &  str)
inlinestatic

Checks if a given string can be parsed to a json, if so it returns the same- string, if not it returns a strigified empty json object "{}".

Parameters
strString to check.
Returns
Given string or strigified empty json object "{}".
static web::json::value granada::util::string::to_json ( const std::string &  str)
static

Parses a string to a JSON and returns it, if conversion fails, convert it to an empty JSON object.

Parameters
strString to parse.
Returns
Parsed JSON.
static void granada::util::string::to_lower ( std::string &  str)
inlinestatic

Convert a string to lowercase.

Parameters
strString to lowercase.
static void granada::util::string::to_upper ( std::string &  str)
inlinestatic

Convert a string to UPPERCASE.

Parameters
strString to uppercase.
static void granada::util::string::trim ( std::string &  s)
inlinestatic

Trim from both ends

Parameters
sString to trim.