PF_API 0.52

Code/Libs/Utils_LIB/UStringUtils.h

Go to the documentation of this file.
00001 
00002 //    Copyright (C) 2004-2006 Dylan Blair
00003 //
00004 //    email: dblair@alumni.cs.utexas.edu
00005 //
00006 //    This library is free software; you can redistribute it and/or
00007 //    modify it under the terms of the GNU Lesser General Public
00008 //    License as published by the Free Software Foundation; either
00009 //    version 2.1 of the License, or (at your option) any later version.
00010 //
00011 //    This library is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 //    Lesser General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU Lesser General Public
00017 //    License along with this library; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef USTRING_UTILS_H
00022 #define USTRING_UTILS_H
00023 
00024 #include <string>
00025 
00026 namespace OpenSkyNet {
00027     namespace Utils {
00029         inline void Tokenize(const std::string& s_, std::vector<std::string>& tokens_, const std::string& delimiters_=" ") {
00030             // Skip delimiters at beginning.
00031             std::string::size_type lastPos = s_.find_first_not_of(delimiters_, 0);
00032             // Find first "non-delimiter".
00033             std::string::size_type pos = s_.find_first_of(delimiters_, lastPos);
00034 
00035             while (std::string::npos != pos || std::string::npos != lastPos) {
00036                 // Found a token, add it to the vector.
00037                 tokens_.push_back(s_.substr(lastPos, pos - lastPos));
00038                 // Skip delimiters.  Note the "not_of"
00039                 lastPos = s_.find_first_not_of(delimiters_, pos);
00040                 // Find next "non-delimiter"
00041                 pos = s_.find_first_of(delimiters_, lastPos);
00042             }
00043         }
00044 
00045         inline void EraseAll(std::string& s_, const std::string& charsToErase_=" ") {
00046             std::string::size_type lastErasePos = s_.find_first_of(charsToErase_, 0);
00047             while (std::string::npos != lastErasePos) {
00048                 s_.erase(s_.begin() + lastErasePos);
00049                 lastErasePos = s_.find_first_of(charsToErase_, lastErasePos);
00050             }
00051         }
00052     }
00053 }
00054 
00055 #endif //USTRING_UTILS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines