Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UStringUtils.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2006 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef USTRING_UTILS_H
22 #define USTRING_UTILS_H
23 
24 #include <string>
25 
26 namespace OpenSkyNet {
27  namespace Utils {
29  inline void Tokenize(const std::string& s_, std::vector<std::string>& tokens_, const std::string& delimiters_=" ") {
30  // Skip delimiters at beginning.
31  std::string::size_type lastPos = s_.find_first_not_of(delimiters_, 0);
32  // Find first "non-delimiter".
33  std::string::size_type pos = s_.find_first_of(delimiters_, lastPos);
34 
35  while (std::string::npos != pos || std::string::npos != lastPos) {
36  // Found a token, add it to the vector.
37  tokens_.push_back(s_.substr(lastPos, pos - lastPos));
38  // Skip delimiters. Note the "not_of"
39  lastPos = s_.find_first_not_of(delimiters_, pos);
40  // Find next "non-delimiter"
41  pos = s_.find_first_of(delimiters_, lastPos);
42  }
43  }
44 
45  inline void EraseAll(std::string& s_, const std::string& charsToErase_=" ") {
46  std::string::size_type lastErasePos = s_.find_first_of(charsToErase_, 0);
47  while (std::string::npos != lastErasePos) {
48  s_.erase(s_.begin() + lastErasePos);
49  lastErasePos = s_.find_first_of(charsToErase_, lastErasePos);
50  }
51  }
52  }
53 }
54 
55 #endif //USTRING_UTILS_H
void Tokenize(const std::string &s_, std::vector< std::string > &tokens_, const std::string &delimiters_=" ")
Definition: UStringUtils.h:29
void EraseAll(std::string &s_, const std::string &charsToErase_=" ")
Definition: UStringUtils.h:45