inicpp
C++ parser of INI files with schema validation.
inicpp::string_utils Namespace Reference

Functions

std::string left_trim (const std::string &str)
 
std::string right_trim (const std::string &str)
 
std::string trim (const std::string &str)
 
bool find_needle (const std::string &haystack, const std::string &needle)
 
bool starts_with (const std::string &str, const std::string &search_str)
 
bool ends_with (const std::string &str, const std::string &search_str)
 
std::vector< std::string > split (const std::string &str, char delim)
 
template<typename ReturnType >
ReturnType parse_string (const std::string &value, const std::string &option_name)
 
template<>
string_ini_t parse_string< string_ini_t > (const std::string &value, const std::string &)
 
template<>
boolean_ini_t parse_string< boolean_ini_t > (const std::string &value, const std::string &option_name)
 
template<>
enum_ini_t parse_string< enum_ini_t > (const std::string &value, const std::string &option_name)
 
template<>
float_ini_t parse_string< float_ini_t > (const std::string &value, const std::string &option_name)
 
template<>
signed_ini_t parse_string< signed_ini_t > (const std::string &value, const std::string &option_name)
 
template<>
unsigned_ini_t parse_string< unsigned_ini_t > (const std::string &value, const std::string &option_name)
 

Detailed Description

Namespace which contains methods for working with strings, including basic string operations and inicpp specific parsing.

Function Documentation

bool inicpp::string_utils::ends_with ( const std::string &  str,
const std::string &  search_str 
)

Tries to find out if given str ends with search_str.

Parameters
strsearched string
search_strstring which is searched for
Returns
true if given string starts with search_str

Definition at line 55 of file string_utils.cpp.

bool inicpp::string_utils::find_needle ( const std::string &  haystack,
const std::string &  needle 
)

In haystack find any occurence of needle.

Parameters
haystackstring in which search is executed
needlestring which is searched for
Returns
true if at least one needle was found, false otherwise

Definition at line 33 of file string_utils.cpp.

std::string inicpp::string_utils::left_trim ( const std::string &  str)

Trim whitespaces from start of given string.

Parameters
strprocessed string
Returns
newly created instance of string

Definition at line 10 of file string_utils.cpp.

template<typename ReturnType >
ReturnType inicpp::string_utils::parse_string ( const std::string &  value,
const std::string &  option_name 
)

Function for parsing string input value to strongly typed one

Parameters
valueValue to be parsed
option_nameOption name from this value - will be in exception text if thrown
Returns
Value parsed to proper (ReturnType) type
Exceptions
invalid_type_exceptionif such cast cannot be made

Definition at line 75 of file string_utils.h.

template<>
boolean_ini_t inicpp::string_utils::parse_string< boolean_ini_t > ( const std::string &  value,
const std::string &  option_name 
)

Parse string to boolean value.

Parameters
valueValue to be parsed
option_nameOption name from this value - will be in exception text if thrown
Returns
parsed value with correct type
Exceptions
invalid_type_exceptionif string cannot be parsed

Definition at line 90 of file string_utils.cpp.

template<>
enum_ini_t inicpp::string_utils::parse_string< enum_ini_t > ( const std::string &  value,
const std::string &  option_name 
)

Parse string to enum value.

Parameters
valueValue to be parsed
option_nameOption name from this value - will be in exception text if thrown
Returns
parsed value with correct type
Exceptions
invalid_type_exceptionif string cannot be parsed

Definition at line 104 of file string_utils.cpp.

template<>
float_ini_t inicpp::string_utils::parse_string< float_ini_t > ( const std::string &  value,
const std::string &  option_name 
)

Parse string to float value.

Parameters
valueValue to be parsed
option_nameOption name from this value - will be in exception text if thrown
Returns
parsed value with correct type
Exceptions
invalid_type_exceptionif string cannot be parsed

Definition at line 109 of file string_utils.cpp.

template<>
signed_ini_t inicpp::string_utils::parse_string< signed_ini_t > ( const std::string &  value,
const std::string &  option_name 
)

Parse string to signed value.

Parameters
valueValue to be parsed
option_nameOption name from this value - will be in exception text if thrown
Returns
parsed value with correct type
Exceptions
invalid_type_exceptionif string cannot be parsed

Definition at line 118 of file string_utils.cpp.

template<>
string_ini_t inicpp::string_utils::parse_string< string_ini_t > ( const std::string &  value,
const std::string &   
)

Specialization for string type, which doesn't need to be explicitely parsed.

Definition at line 86 of file string_utils.cpp.

template<>
unsigned_ini_t inicpp::string_utils::parse_string< unsigned_ini_t > ( const std::string &  value,
const std::string &  option_name 
)

Parse string to unsigned value.

Parameters
valueValue to be parsed
option_nameOption name from this value - will be in exception text if thrown
Returns
parsed value with correct type
Exceptions
invalid_type_exceptionif string cannot be parsed

Definition at line 135 of file string_utils.cpp.

std::string inicpp::string_utils::right_trim ( const std::string &  str)

Trim whitespaces from end of given string.

Parameters
strprocessed string
Returns
newly created instance of string

Definition at line 16 of file string_utils.cpp.

std::vector< std::string > inicpp::string_utils::split ( const std::string &  str,
char  delim 
)

Split given string with given delimiter.

Parameters
strtext which will be splitted
delimdelimiter
Returns
array of newly created substrings

Definition at line 73 of file string_utils.cpp.

bool inicpp::string_utils::starts_with ( const std::string &  str,
const std::string &  search_str 
)

Tries to find out if given str starts with search_str.

Parameters
strsearched string
search_strstring which is searched for
Returns
true if given string starts with search_str

Definition at line 38 of file string_utils.cpp.

std::string inicpp::string_utils::trim ( const std::string &  str)

Trim whitespaces from start and end of given string.

Parameters
strprocessed string
Returns
newly created instance of string

Definition at line 22 of file string_utils.cpp.