ATLAS Offline Software
Loading...
Searching...
No Matches
GRLStrUtil Namespace Reference

Functions

void trim (std::string &input)
void split (const std::string &input, std::string &first, std::string &second)
std::vector< std::string > split (std::string input)

Function Documentation

◆ split() [1/2]

void GRLStrUtil::split ( const std::string & input,
std::string & first,
std::string & second )

Definition at line 23 of file StrUtil.cxx.

23 {
24 // split input in two
25 string::size_type position = input.find_first_of(" \t\n");
26 if ( position==std::string::npos ) {
27 first = input;
28 second = "";
29 } else {
30 first = input.substr( 0, position );
31 second = input.substr( position+1, input.size()-position );
32 // trim leading whitespace of second
33 position= second.find_first_not_of(" \t\n");
34 second.erase(0, position);
35 }
36 }

◆ split() [2/2]

vector< string > GRLStrUtil::split ( std::string input)

Definition at line 39 of file StrUtil.cxx.

39 {
40 trim(input);
41 vector<string> splitVec;
42 string first, second;
43 do {
44 split(input,first,second);
45 if (!first.empty()) splitVec.push_back(first);
46 input = second;
47 } while(!input.empty());
48 return splitVec;
49 }
void split(const std::string &input, std::string &first, std::string &second)
Definition StrUtil.cxx:23
void trim(std::string &input)
Definition StrUtil.cxx:12

◆ trim()

void GRLStrUtil::trim ( std::string & input)

Definition at line 12 of file StrUtil.cxx.

12 {
13 // trim leading and trailing whitespace
14 string::size_type position = input.find_first_not_of(" \t\n");
15 if ( position == std::string::npos ) return; // skip, it's all whitespace
16 input.erase(0, position);
17 position= input.find_last_not_of(" \t\n");
18 if ( position != std::string::npos)
19 input.erase( position+1 );
20 }