From: <sv...@ww...> - 2004-09-26 06:07:07
|
Author: mkrose Date: 2004-09-25 23:06:59 -0700 (Sat, 25 Sep 2004) New Revision: 1252 Modified: trunk/CSP/SimCore/Util/SConscript trunk/CSP/SimCore/Util/StringTools.cpp trunk/CSP/SimCore/Util/StringTools.h Log: Clean up string tools, add to build. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1252 Modified: trunk/CSP/SimCore/Util/SConscript =================================================================== --- trunk/CSP/SimCore/Util/SConscript 2004-09-26 06:00:09 UTC (rev 1251) +++ trunk/CSP/SimCore/Util/SConscript 2004-09-26 06:06:59 UTC (rev 1252) @@ -19,6 +19,7 @@ Import('env build') SOURCES = [ + 'StringTools.cpp', 'SynchronousUpdate.cpp' ] Modified: trunk/CSP/SimCore/Util/StringTools.cpp =================================================================== --- trunk/CSP/SimCore/Util/StringTools.cpp 2004-09-26 06:00:09 UTC (rev 1251) +++ trunk/CSP/SimCore/Util/StringTools.cpp 2004-09-26 06:06:59 UTC (rev 1252) @@ -1,63 +1,48 @@ -// Combat Simulator Project - FlightSim Demo -// Copyright (C) 2002 The Combat Simulator Project +// Combat Simulator Project +// Copyright (C) 2002, 2004 The Combat Simulator Project // http://csp.sourceforge.net -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** - * @file Tools.cpp + * @file StringTools.cpp * **/ -#include "Tools.h" +#include <SimCore/Util/StringTools.h> #include <ctype.h> #include <algorithm> -// catches non-existent files to open, displays an error and exits the program -FILE* fileopen(const char *cFilename, const char *cMode) -{ - FILE *f = fopen(cFilename, cMode); - - if (f==0) - { - printf("\n\n\nerror while opening file '%s'! Exiting program ....\n\n", cFilename); - exit(-1); - } - - return f; +void ConvertStringToUpper(std::string &str) { + std::transform(str.begin(), str.end(), str.begin(), ::toupper); } - -void ConvertStringToUpper(string & str) -{ - transform(str.begin(), str.end(), str.begin(), ::toupper); +void ConvertStringToLower(std::string &str) { + std::transform(str.begin(), str.end(), str.begin(), ::tolower); } - -StringTokenizer::StringTokenizer(const string &rStr, const string &rDelimiters) -{ - string::size_type lastPos(rStr.find_first_not_of(rDelimiters, 0)); - string::size_type pos(rStr.find_first_of(rDelimiters, lastPos)); - while (string::npos != pos || string::npos != lastPos) - { - push_back(rStr.substr(lastPos, pos - lastPos)); - lastPos = rStr.find_first_not_of(rDelimiters, pos); - pos = rStr.find_first_of(rDelimiters, lastPos); +StringTokenizer::StringTokenizer(const std::string &str, const std::string &delimiters) { + std::string::size_type lastPos(str.find_first_not_of(delimiters, 0)); + std::string::size_type pos(str.find_first_of(delimiters, lastPos)); + while (std::string::npos != pos || std::string::npos != lastPos) { + push_back(str.substr(lastPos, pos - lastPos)); + lastPos = str.find_first_not_of(delimiters, pos); + pos = str.find_first_of(delimiters, lastPos); } } Modified: trunk/CSP/SimCore/Util/StringTools.h =================================================================== --- trunk/CSP/SimCore/Util/StringTools.h 2004-09-26 06:00:09 UTC (rev 1251) +++ trunk/CSP/SimCore/Util/StringTools.h 2004-09-26 06:06:59 UTC (rev 1252) @@ -1,57 +1,51 @@ -// Combat Simulator Project - FlightSim Demo -// Copyright (C) 2002 The Combat Simulator Project +// Combat Simulator Project +// Copyright (C) 2002, 2004 The Combat Simulator Project // http://csp.sourceforge.net -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** - * @file Tools.h + * @file StringTools.h * **/ -#ifndef __TOOLS_H__ -#define __TOOLS_H__ +#ifndef __SIMCORE_UTIL_STRINGTOOLS_H__ +#define __SIMCORE_UTIL_STRINGTOOLS_H__ + #include <string> #include <deque> -#include <cstdio> -using namespace std; -typedef unsigned int uint; -typedef unsigned char uchar; -typedef unsigned short ushort; +/** Convert a string to uppercase (in place). + */ +void ConvertStringToUpper(std::string &str); +/** Convert a string to lowercase (in place). + */ +void ConvertStringToLower(std::string &str); -FILE* fileopen(const char *cFilename, const char *cMode); -void ConvertStringToUpper(string & str); - - -/** - * class StringTokenizer - * - * @author unknown +/** Tokenize a string, placing the tokens into a deque. */ -class StringTokenizer : public deque<string> -{ - public: - StringTokenizer(const string &rStr, const string &rDelimiters = " ,\n"); +class StringTokenizer: public std::deque<std::string> { +public: + StringTokenizer(const std::string &str, const std::string &delimiters = " ,\n"); }; -#endif // __TOOLS_H__ +#endif // __SIMCORE_UTIL_STRINGTOOLS_H__ |