Jpp
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

◆ startswith()

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 69 of file io_ascii.hh.

70  {
71  if ( a.find( b ) == 0 ) return true;
72  return false;
73  }

◆ trim()

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 81 of file io_ascii.hh.

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