Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
io_stringutil Namespace Reference

Functions

bool startswith (const std::string &a, const std::string &b)
 Check if string starts with given text. More...
 
std::string trim (const std::string &s)
 Remove leading and trailing white spaces. More...
 

Function Documentation

bool io_stringutil::startswith ( const std::string &  a,
const std::string &  b 
)
inline

Check if string starts with given text.

Parameters
ainput string
btext
Returns
true if string start with text; else false

Definition at line 67 of file io_ascii.hh.

68 {
69  if ( a.find( b ) == 0 ) return true;
70  return false;
71 }
fi JEventTimesliceWriter a
std::string io_stringutil::trim ( const std::string &  s)
inline

Remove leading and trailing white spaces.

Parameters
sinput string
Returns
trimmed string

Definition at line 79 of file io_ascii.hh.

80 {
81  using namespace std;
82 
83  if ( s == "" ) return s;
84 
85  string::size_type i1;
86  string::size_type i2;
87 
88  for (i1 = 0; i1 < s.length(); i1++)
89  {
90  if ( !isspace (s[i1]) ) break;
91  }
92  for (i2 = s.length() - 1 ; i2 > i1 ; i2--)
93  {
94  if ( !isspace (s[i2]) ) break;
95  }
96  return s.substr( i1, i2 - i1 + 1 );
97 }