OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
StringUtils.h
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#* Please direct any questions or comments to the OpenIG Forums
29 //#* Email address: openig@compro.net
30 //#*
31 //#*
32 //#*****************************************************************************
33 
34 #ifndef STRINGUTILS_H
35 #define STRINGUTILS_H
36 
37 #if defined(OPENIG_SDK)
38  #include <OpenIG-Base/Export.h>
39 #else
40  #include <Core-Base/Export.h>
41 #endif
42 
43 #include <string>
44 #include <vector>
45 #include <algorithm>
46 #include <cctype>
47 #include <functional>
48 
49 namespace OpenIG {
50  namespace Base {
51 
58  class IGCORE_EXPORT StringUtils
59  {
60  protected:
61  StringUtils();
62  ~StringUtils();
63 
64  public:
72  static StringUtils* instance();
73 
74  typedef std::vector<std::string> Tokens;
75  typedef std::vector<std::string>::iterator TokensIterator;
76  typedef std::vector<std::string>::const_iterator TokensConstIterator;
77 
78  typedef std::vector< std::string > StringList;
79  typedef std::vector< std::string >::iterator StringListIterator;
80  typedef std::vector< std::string >::const_iterator StringListConstIterator;
81 
91  Tokens tokenize(const std::string& str, const std::string& delimiters = " ");
92 
102  Tokens tokenizeExtended(const std::string& str);
103 
112  template<typename T>
113  inline std::string &ltrim(std::string &s, T istestchar = std::isspace)
114  {
115  s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(istestchar)));
116  return s;
117  }
118 
127  template<typename T>
128  inline std::string &rtrim(std::string &s, T istestchar = std::isspace)
129  {
130  s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(istestchar)).base(), s.end());
131  return s;
132  }
133 
142  template<typename T>
143  inline std::string &trim(std::string &s, T istestchar = std::isspace)
144  {
145  return ltrim(rtrim(s, istestchar), istestchar);
146  }
147 
156  unsigned int numberOfLines(const std::string& text);
157 
166  std::string env(const std::string& var);
167  };
168  } // namespace
169 } // namespace
170 
171 #endif // STRINGUTILS_H
Definition: ImageGenerator.h:62
std::string & trim(std::string &s, T istestchar=std::isspace)
trim a string from left and right
Definition: StringUtils.h:143
std::string & rtrim(std::string &s, T istestchar=std::isspace)
trim a string from right
Definition: StringUtils.h:128
The singleton StringUtils class.
Definition: StringUtils.h:58
std::string & ltrim(std::string &s, T istestchar=std::isspace)
trim a string from left
Definition: StringUtils.h:113