lugre_robstring.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00061 bool charmatchrange (const char c,const char* r);
00062 int cinrange (const char* str,const char* range);
00063 int coutrange (const char* str,const char* range);
00064
00065
00066 unsigned int stringhash (const char* str);
00067 std::string addslashes (const char* str);
00068
00069
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
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
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
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
00102 std::string pathgetdir (const std::string &path);
00103 std::string pathgetfile (const std::string &path);
00104 std::string pathgetext (const std::string &path);
00105 char pathgetdirslash (const std::string &path);
00106 char pathgetwindrive (const std::string &path);
00107 bool pathisabsolute (const std::string &path);
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
00117