string_manip.h File Reference

std::string helpers More...

#include <string>
#include <vector>
#include <sstream>
#include <stdexcept>
Include dependency graph for string_manip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string erase_to_last_of (std::string const &str, char ch)
std::string split (std::string &s, char c)
 split string s by first occurence of char c, returning the second part.
bool is_prefix (std::string const &s, std::string const &prefix)
 return true if "prefix" is a prefix of "s", behavior is undefined if prefix is an empty string
std::vector< std::string > separate_token (std::string const &str, char sep)
std::string ltrim (std::string const &str, std::string const &totrim="\t ")
 remove trim chars from start of input string return the new string
std::string rtrim (std::string const &str, std::string const &totrim="\t ")
 remove trim chars from end of input string return the new string
std::string trim (std::string const &str, std::string const &totrim="\t ")
 ltrim(rtrim(str))
std::string const format_percent (double value, size_t int_width, size_t frac_width, bool showpos=false)
 format_percent - smart format of double percentage value
template<typename To , typename From >
To op_lexical_cast (From const &src)
template<>
unsigned int op_lexical_cast< unsigned int > (std::string const &str)

Detailed Description

std::string helpers

Remarks:
Copyright 2002 OProfile authors
Read the file COPYING
Author:
Philippe Elie
John Levon

Function Documentation

std::string erase_to_last_of ( std::string const &  str,
char  ch 
)
Parameters:
str string
ch the characterto search

erase char from the begin of str to the last occurence of ch from and return the string

std::string const format_percent ( double  value,
size_t  int_width,
size_t  frac_width,
bool  showpos = false 
)

format_percent - smart format of double percentage value

Parameters:
value - the value
int_width - the maximum integer integer width default to 2
frac_width - the fractionnary width default to 4
showpos - show + sign for positive values

This formats a percentage into exactly the given width and returns it. If the integer part is larger than the given int_width, the returned string will be wider. The returned string is never shorter than (fract_with + int_width + 1)

References is_prefix().

bool is_prefix ( std::string const &  s,
std::string const &  prefix 
)

return true if "prefix" is a prefix of "s", behavior is undefined if prefix is an empty string

std::string ltrim ( std::string const &  str,
std::string const &  totrim = "\t " 
)

remove trim chars from start of input string return the new string

template<typename To , typename From >
To op_lexical_cast ( From const &  src  )  [inline]
Parameters:
src input parameter convert From src to a T through an istringstream.

Throws invalid_argument if conversion fail.

Note that this is not as foolproof as boost's lexical_cast

Referenced by generic_spec< T >::set().

template<>
unsigned int op_lexical_cast< unsigned int > ( std::string const &  str  )  [inline]
std::string rtrim ( std::string const &  str,
std::string const &  totrim = "\t " 
)

remove trim chars from end of input string return the new string

std::vector<std::string> separate_token ( std::string const &  str,
char  sep 
)
Parameters:
str the string to tokenize
sep the separator_char

separate fields in a string in a list of token; field are separated by the sep character, sep char can be escaped by '\' to specify a sep char in a token, '\' not followed by a sep is taken as it e.g. "\,\a" --> ",\a"

std::string split ( std::string &  s,
char  c 
)

split string s by first occurence of char c, returning the second part.

s is set to the first part. Neither include the split character

std::string trim ( std::string const &  str,
std::string const &  totrim = "\t " 
)

ltrim(rtrim(str))


Generated on 29 Jul 2013 for oprofile by  doxygen 1.6.1