lugre_robstring.h

Go to the documentation of this file.
00001 /*
00002 http://www.opensource.org/licenses/mit-license.php  (MIT-License)
00003 
00004 Copyright (c) 2007 Lugre-Team
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022 THE SOFTWARE.
00023 */
00024 #ifndef LUGRE_ROBSTRING_H
00025 #define LUGRE_ROBSTRING_H
00026 
00027 #include <stdarg.h>
00028 #include <string.h>
00029 #include <string>
00030 #include <vector>
00031 #include <cstdio>
00032 #include <stdio.h>
00033 
00034 #ifdef WIN32
00035      #define vsnprintf     _vsnprintf
00036 #endif
00037 #define kRobStringBufferSize 1024*64
00038 
00039 namespace Lugre {
00040 
00041 extern char gRobStringBuffer[kRobStringBufferSize];
00042 
00043 // string generation
00044 inline std::string  strprintf   (const char* szFormat,...) { PROFILEH
00045     va_list ap;
00046     va_start(ap,szFormat);
00047     gRobStringBuffer[0] = 0;
00048     vsnprintf(gRobStringBuffer,kRobStringBufferSize-1,szFormat,ap);
00049     std::string s(gRobStringBuffer);
00050     va_end(ap);
00051     return s;
00052 }
00053 
00054 inline bool StringContains (std::string sHaystack,std::string sNeedle) { return sHaystack.find(sNeedle) != std::string::npos; }
00055 std::string strprintvf  (const char* szFormat,void* arglist);
00056 
00058 void    explodestr      (const char* separator,const char* str,std::vector<std::string>& res);
00059 
00060 // char-ranges
00061 bool    charmatchrange  (const char c,const char* r); // \ to escape, a-z as range
00062 int     cinrange        (const char* str,const char* range); // count chars in range
00063 int     coutrange       (const char* str,const char* range); // count chars out of range
00064 
00065 // string manipulation
00066 unsigned int    stringhash  (const char* str); // generate a hash value
00067 std::string     addslashes  (const char* str); // escape backslash and quotes
00068 
00069 // UPPERCASE
00070 inline std::string      strtoupper  (const char* str) { PROFILEH
00071     std::string res;
00072     res.reserve(strlen(str));
00073     for (;*str;str++) res += toupper(*str);
00074     return res;
00075 }
00076 
00077 // UPPERCASE
00078 inline std::string      strtoupper  (const std::string &sStr) { PROFILEH
00079     std::string res;
00080     res.reserve(sStr.size());
00081     for (const char* str=sStr.c_str();*str;str++) res += toupper(*str);
00082     return res;
00083 }
00084 
00085 // lowercase
00086 inline std::string      strtolower  (const char* str) { PROFILEH
00087     std::string res;
00088     res.reserve(strlen(str));
00089     for (;*str;str++) res += tolower(*str);
00090     return res;
00091 }
00092 
00093 // lowercase
00094 inline std::string      strtolower  (const std::string &sStr) { PROFILEH
00095     std::string res;
00096     res.reserve(sStr.size());
00097     for (const char* str=sStr.c_str();*str;str++) res += tolower(*str);
00098     return res;
00099 }
00100 
00101 // paths
00102 std::string     pathgetdir      (const std::string &path); // C:/zeug/grafik/datei.txt -> C:/zeug/grafik
00103 std::string     pathgetfile     (const std::string &path); // C:/zeug/grafik/datei.txt -> datei.txt
00104 std::string     pathgetext      (const std::string &path); // C:/zeug/grafik/datei.txt -> .txt
00105 char            pathgetdirslash (const std::string &path); // C:/zeug/grafik/datei.txt -> / 
00106 char            pathgetwindrive (const std::string &path); // C:/zeug/grafik/datei.txt -> C
00107 bool            pathisabsolute  (const std::string &path); // C:/zeug/grafik/datei.txt -> true
00108 std::string     pathadd         (const std::string &base,std::string &add);
00109 bool            pathissubpath   (const std::string &container,std::string &path);
00110 
00111 
00112 
00113 };
00114 
00115 #endif
00116 // ****** ****** ****** END
00117 

Generated on Wed May 23 06:00:13 2012 for cpp by  doxygen 1.5.6