String operations
Library in C++ that implements operations over the STL string.
Functions and files
The main file that contains all functions.
File that contains the test functions to check if everything is working.
Table of content
- split
- str_to_float
- float_to_str
- isInt
- isFloat
- capitalize
- check_regex_exp
- trim
- split
- find_full_words
- find_replace_first
- find_replace_all
- find_term
- reduce
- mismatch_string
- vec_float_to_str
- vec_str_to_float
- indexOf
- contains
split
Aux function for split
Templates:
- Out, typename
Return type
: void
Access
: private
Arguments:
Type
: std::string,Name
: sType
: char,Name
: delimType
: Out,Name
: result
str_to_float
Cast std::string val
to float
Templates:
- f, typename
Return type
: f
Access
: private
Arguments:
Type
: std::string,Name
: val
float_to_str
Cast float val
to std::string.
Templates:
- f, typename
Return type
: std::string
Access
: private
Arguments:
Type
: f,Name
: val
isInt
Checks if val
is a integer.
Return type
: bool
Access
: public
Arguments:
Type
: std::string,Name
: val
isFloat
Checks if val
is any kind of float.
Return type
: bool
Access
: public
Arguments:
Type
: std::string,Name
: val
capitalize
Capitalize the first char of str
.
Return type
: std::string
Access
: public
Arguments:
Type
: std::string,Name
: str
check_regex_exp
Creates a regex expression using the string exp
and checks if there is a match in str
. If it throws an exception (problably because your exp
was wrong), put the function call in a try/catch and do something like: catch (std::exception &e) {print(e.what())}
Return type
: bool
Access
: public
Arguments:
Type
: std::string,Name
: strType
: std::string,Name
: exp
trim
Returns the "trimmed" str
(can be another char besides whitespace
). E.g.: " trim me " -> "trim me".
Return type
: std::string
Access
: public
Arguments:
Type
: std::string,Name
: strType
: std::string,Name
: whitespaceDefault value
: " "
split
Returns a vector with the split string s
spliting at delim
char.
Return type
: std::vectorstd::string
Access
: public
Arguments:
Type
: std::string,Name
: sType
: char,Name
: delimDefault value
: ' '
find_full_words
Checks if there is a full word
in s
.
Return type
: bool
Access
: public
Arguments:
Type
: std::string,Name
: sType
: std::string,Name
: word
find_replace_first
Replace the first
occurrence of string toReplace
with replaceWith
in a copy of s
. Returns the replaced string, if not replaced it'll return the copy of s
.
Return type
: std::string
Access
: public
Arguments:
Type
: std::string,Name
: sType
: std::string,Name
: toReplaceType
: std::string,Name
: replaceWith
find_replace_all
Replace all
occurrence of string toReplace
with replaceWith
in a copy of s
. Returns the replaced string, if not replaced it'll return the copy of s
.
Return type
: std::string
Access
: public
Arguments:
Type
: std::string,Name
: sType
: std::string,Name
: toReplaceType
: std::string,Name
: replaceWith
find_term
Checks if the term
is in s
.
Return type
: bool
Access
: public
Arguments:
Type
: std::string,Name
: sType
: std::string,Name
: term
reduce
Removes the whitespace
(or another char) from str
and fill the gap with fill
. E.g.: " there is too much empty space" -> "there-is-too-much-empty-space" or "there is too much empty space"
.
Return type
: std::string
Access
: public
Arguments:
Type
: std::string,Name
: strType
: std::string,Name
: fillDefault value
: " "Type
: std::string,Name
: whitespaceDefault value
: " "
mismatch_string
Removes the begin of a
that matches b
. Useful for handling paths. E.g.: "/this/is/a/path/to/something.txt" - "/this/is/a/path/" = "to/something.txt"
Return type
: std::string
Access
: public
Arguments:
Type
: std::string,Name
: aType
: std::string,Name
: b
vec_float_to_str
Transforms a float (or double, or whatever float it is) vector float_v
to a std::string vector.
Templates:
- f, typename
Return type
: std::vectorstd::string
Access
: public
Arguments:
Type
: std::vector,Name
: float_v
vec_str_to_float
Transforms a std::string vector str_v
to a float (or double, or whatever float it is). You need to specify the return type, e.g.: vec_str_to_float<double>(string_vector)
Templates:
- f, typename
Return type
: std::vector
Access
: public
Arguments:
Type
: std::vectorstd::string,Name
: str_v
indexOf
Returns the index of first occurence of val
inside of vec
. If not found, returns -1.
Templates:
- T, typename
Return type
: int
Access
: public
Arguments:
Type
: std::vector,Name
: vecType
: T,Name
: val
contains
Uses indexOf
to check if val
is in vec
.
Templates:
- T, typename
Return type
: bool
Access
: public
Arguments:
Type
: std::vector,Name
: vecType
: T,Name
: val
Python-like print.
Templates:
- T, typename
- TAIL, typename
Return type
: void
Access
: public
Arguments:
Type
: T,Name
: tType
: TAIL...,Name
: tail