Wtx ~ Wt Extension Library
WtxLib
Core.cpp
1 
2 #include <sstream>
3 #include <algorithm>
4 
5 #include "Core.h"
6 
7 static std::vector<std::string> & split( const std::string & s, char delim, std::vector<std::string> & elems )
8 {
9  std::stringstream ss( s );
10  std::string item;
11  while( std::getline( ss, item, delim ) )
12  {
13  elems.push_back( item );
14  }
15  return elems;
16 }
17 
18 
19 std::vector<std::string> Wtx::Core::split( const std::string & s, char delim )
20 {
21  std::vector<std::string> elems;
22  ::split( s, delim, elems );
23  return elems;
24 }
25 
26 const char* Wtx::Core::trim_ws = " \t\n\r\f\v";
27 
28 // trim from end of string (right)
29 std::string & Wtx::Core::rtrim( std::string & s, const char* t )
30 {
31  s.erase( s.find_last_not_of(t) + 1 );
32  return s;
33 }
34 
35 // trim from beginning of string (left)
36 std::string & Wtx::Core::ltrim( std::string & s, const char* t )
37 {
38  s.erase( 0, s.find_first_not_of(t) );
39  return s;
40 }
41 
42 // trim from both ends of string (left & right)
43 std::string & Wtx::Core::trim( std::string & s, const char* t )
44 {
45  return ltrim( rtrim(s, t), t );
46 }
47 
48 std::string Wtx::Core::toupper( const std::string & s )
49 {
50  std::string retVal = s;
51 
52  std::transform( retVal.begin(), retVal.end(), retVal.begin(), ::toupper );
53 
54  return retVal;
55 }
56 
57 std::string Wtx::Core::tolower( const std::string & s )
58 {
59  std::string retVal = s;
60 
61  std::transform( retVal.begin(), retVal.end(), retVal.begin(), ::tolower );
62 
63  return retVal;
64 }
65 
66