Macros | Functions
vul_string.cxx File Reference
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <sstream>
#include <cmath>
#include "vul_string.h"
#include <cassert>
#include <vul/vul_reg_exp.h>
#include <vul/vul_sprintf.h>

Go to the source code of this file.

Macros

#define END_OF_STRING   (0)
 
#define REGEXP_INTEGER   "\\-?[0123456789]+"
 

Functions

char * vul_string_c_upcase (char *s)
 Converts all alphabetical characters to uppercase. More...
 
char * vul_string_c_downcase (char *s)
 Converts all alphabetical characters to lowercase. More...
 
char * vul_string_c_capitalize (char *s)
 Capitalizes all words in a string. More...
 
char * vul_string_c_trim (char *str, const char *rem)
 Removes any occurrences of rem from str, and returns the modified string. More...
 
char * vul_string_c_left_trim (char *str, const char *rem)
 Removes any prefix occurrence of rem from str and returns modified string. More...
 
char * vul_string_c_right_trim (char *str, const char *rem)
 Removes any suffix occurrence of rem from str and returns modified string. More...
 
char * vul_string_c_reverse (char *c)
 Reverses the order of the characters in string. More...
 
std::string & vul_string_reverse (std::string &s)
 Reverses the order of the characters in string. More...
 
std::string & vul_string_upcase (std::string &s)
 Converts all alphabetical characters to uppercase. More...
 
std::string & vul_string_downcase (std::string &s)
 Converts all alphabetical characters to lowercase. More...
 
std::string & vul_string_capitalize (std::string &s)
 Capitalizes all words in string. More...
 
std::string & vul_string_trim (std::string &sr, const char *rem)
 Removes any occurrences of rem from str and returns modified string. More...
 
std::string & vul_string_left_trim (std::string &sr, const char *rem)
 Removes any prefix occurrence of rem from str and returns modified string. More...
 
std::string & vul_string_right_trim (std::string &sr, const char *rem)
 Removes any suffix occurrence of rem from str and returns modified string. More...
 
int vul_string_atoi (std::string const &s)
 Reads an integer from a string. More...
 
double vul_string_atof (std::string const &s)
 Reads a double from a string. More...
 
double vul_string_atof_withsuffix (std::string const &s)
 Reads a double from a string, with k, kb, M, etc suffix. More...
 
bool vul_string_to_bool (const std::string &str)
 Convert a string to a boolean. More...
 
std::vector< int > vul_string_to_int_list (std::string str)
 Convert a string to a list of ints, using the matlab index format. More...
 
bool vul_string_expand_var (std::string &str)
 Expand any environment variables in the string. More...
 
bool vul_string_replace (std::string &full_str, const std::string &find_str, const std::string &replace_str, int num_times)
 replaces instances "find_str" in "full_str" with "replace_str" a given "num_times". More...
 
std::string vul_string_escape_ctrl_chars (const std::string &in)
 Replace control chars with escaped representations. More...
 

Macro Definition Documentation

◆ END_OF_STRING

#define END_OF_STRING   (0)

Definition at line 20 of file vul_string.cxx.

◆ REGEXP_INTEGER

#define REGEXP_INTEGER   "\\-?[0123456789]+"

Function Documentation

◆ vul_string_atof()

double vul_string_atof ( std::string const &  s)

Reads a double from a string.

Definition at line 222 of file vul_string.cxx.

◆ vul_string_atof_withsuffix()

double vul_string_atof_withsuffix ( std::string const &  s)

Reads a double from a string, with k, kb, M, etc suffix.

No space is allowed between the number and the suffix. k=10^3, kb=2^10, M=10^6, Mb=2^20, G=10^9, Gb=2^30, T=10^12, Tb=2^40 If parse fails, return 0.0;

Definition at line 232 of file vul_string.cxx.

◆ vul_string_atoi()

int vul_string_atoi ( std::string const &  s)

Reads an integer from a string.

Definition at line 217 of file vul_string.cxx.

◆ vul_string_c_capitalize()

char* vul_string_c_capitalize ( char *  )

Capitalizes all words in a string.

A word is defined as a sequence of characters separated by non-alphanumerics.

Definition at line 49 of file vul_string.cxx.

◆ vul_string_c_downcase()

char* vul_string_c_downcase ( char *  s)

Converts all alphabetical characters to lowercase.

Definition at line 36 of file vul_string.cxx.

◆ vul_string_c_left_trim()

char* vul_string_c_left_trim ( char *  str,
const char *  rem 
)

Removes any prefix occurrence of rem from str and returns modified string.

Definition at line 81 of file vul_string.cxx.

◆ vul_string_c_reverse()

char* vul_string_c_reverse ( char *  c)

Reverses the order of the characters in string.

Definition at line 116 of file vul_string.cxx.

◆ vul_string_c_right_trim()

char* vul_string_c_right_trim ( char *  str,
const char *  rem 
)

Removes any suffix occurrence of rem from str and returns modified string.

Definition at line 100 of file vul_string.cxx.

◆ vul_string_c_trim()

char* vul_string_c_trim ( char *  str,
const char *  rem 
)

Removes any occurrences of rem from str, and returns the modified string.

Definition at line 63 of file vul_string.cxx.

◆ vul_string_c_upcase()

char* vul_string_c_upcase ( char *  s)

Converts all alphabetical characters to uppercase.

Definition at line 24 of file vul_string.cxx.

◆ vul_string_capitalize()

std::string& vul_string_capitalize ( std::string &  s)

Capitalizes all words in string.

Definition at line 163 of file vul_string.cxx.

◆ vul_string_downcase()

std::string& vul_string_downcase ( std::string &  s)

Converts all alphabetical characters to lowercase.

Definition at line 155 of file vul_string.cxx.

◆ vul_string_escape_ctrl_chars()

std::string vul_string_escape_ctrl_chars ( const std::string &  in)

Replace control chars with escaped representations.

Space and "\n" are preserved, but tabs, CR, etc are escaped. This is not aimed and is not suitable for any particular input-validation security problem, such as sql-injection.

Definition at line 511 of file vul_string.cxx.

◆ vul_string_expand_var()

bool vul_string_expand_var ( std::string &  str)

Expand any environment variables in the string.

Expands "foo\f$VARfoo" to "foobarfoo" when $VAR=bar. If both $VAR and $VARfoo exist, an arbitrary choice will be made of which variable to use. This problem can be avoided by using the syntax "foo${VAR}foo." " $(VAR)" and "$[VAR]" can also be used. There are no inbuilt variables like in shell scripting, and variable names cannot contain whitespace or "$"s. "$$" can be used to insert a literal "

Definition at line 387 of file vul_string.cxx.

◆ vul_string_left_trim()

std::string& vul_string_left_trim ( std::string &  sr,
const char *  rem 
)

Removes any prefix occurrence of rem from str and returns modified string.

Definition at line 198 of file vul_string.cxx.

◆ vul_string_replace()

bool vul_string_replace ( std::string &  full_str,
const std::string &  find_str,
const std::string &  replace_str,
int  num_times 
)

replaces instances "find_str" in "full_str" with "replace_str" a given "num_times".

Returns
true iff at least one replacement took place.

Definition at line 484 of file vul_string.cxx.

◆ vul_string_reverse()

std::string& vul_string_reverse ( std::string &  s)

Reverses the order of the characters in string.

Definition at line 132 of file vul_string.cxx.

◆ vul_string_right_trim()

std::string& vul_string_right_trim ( std::string &  sr,
const char *  rem 
)

Removes any suffix occurrence of rem from str and returns modified string.

Definition at line 208 of file vul_string.cxx.

◆ vul_string_to_bool()

bool vul_string_to_bool ( const std::string &  str)

Convert a string to a boolean.

Looks for On, true, yes, 1 to mean true. everything else is false. It ignores leading and trailing whitespace and capitalisation.

Definition at line 281 of file vul_string.cxx.

◆ vul_string_to_int_list()

std::vector<int> vul_string_to_int_list ( std::string  str)

Convert a string to a list of ints, using the matlab index format.

Convert a string to a list of ints.

e.g. "0,1,10:14,20:-2:10" results in 0,1,10,11,12,13,14,20,18,16,14,12,10 No spaces are allowed.

Returns
empty on error.

Definition at line 301 of file vul_string.cxx.

◆ vul_string_trim()

std::string& vul_string_trim ( std::string &  sr,
const char *  rem 
)

Removes any occurrences of rem from str and returns modified string.

Definition at line 184 of file vul_string.cxx.

◆ vul_string_upcase()

std::string& vul_string_upcase ( std::string &  s)

Converts all alphabetical characters to uppercase.

Definition at line 147 of file vul_string.cxx.