![]() |
VR-Link API Documentation for HLA 1516
|
00001 /********************************************************************* 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 *********************************************************************/ 00009 #pragma once 00010 00011 #include <string> 00012 #include <sstream> 00013 #include <set> 00014 #include "vlString.h" 00015 00016 #ifdef DtUSE_UTILITIES_NAMESPACE 00017 namespace DtUSE_UTILITIES_NAMESPACE 00018 { 00019 #endif 00020 00022 typedef std::set<DtString> DtStringSet; 00023 00026 template<typename T> 00027 std::wstring DtToWString(const T &val); 00028 00031 inline std::wstring DtToWString(const std::string &val); 00032 00035 inline std::wstring DtToWString(const char *val); 00036 00039 inline std::wstring DtToWString(char *val); 00040 00043 inline std::wstring DtToWString(const DtString &val); 00044 00045 00049 template<typename T> 00050 std::string DtToString(const T &val); 00051 00056 inline std::string DtToString(const std::wstring &val); 00057 00060 inline std::string DtToString(const wchar_t *val); 00061 00063 inline DtString DtToLower(const char*); 00064 00066 inline DtString DtToLower(const DtString&); 00067 00069 inline DtString DtToUpper(const char*); 00070 00072 inline DtString DtToUpper(const DtString&); 00073 00075 DT_DLL_VLUTIL DtString DtFirstCharToLower(const DtString&); 00076 00078 DT_DLL_VLUTIL DtString DtFirstCharToUpper(const DtString&); 00079 00086 DT_DLL_VLUTIL DtString DtReplaceSubstring(const DtString& str, 00087 const DtString& searchFor, const DtString& replacement); 00088 00095 DT_DLL_VLUTIL DtString DtReplaceAllSubstrings(const DtString& str, 00096 const DtString& searchFor, const DtString& replacement); 00097 00101 DT_DLL_VLUTIL bool DtContainsSubstring(const DtString& str, 00102 const DtString& searchFor); 00103 00104 00105 //--------------------------------------------------------------- 00108 template<typename T> 00109 inline std::wstring DtToWString(const T &in_val) 00110 { 00111 std::wstringstream temp; 00112 temp << in_val; 00113 return temp.str(); 00114 } 00115 00116 inline std::wstring DtToWString(const std::string &in_val) 00117 { 00118 std::wstring temp; 00119 std::string::const_iterator b = in_val.begin(); 00120 const std::string::const_iterator e = in_val.end(); 00121 while (b != e) 00122 { 00123 temp += *b; 00124 ++b; 00125 } 00126 return temp; 00127 } 00128 00129 inline std::wstring DtToWString(const char * in_val) 00130 { 00131 std::wstring temp; 00132 while (*in_val != '\0') 00133 temp += *in_val++; 00134 return temp; 00135 } 00136 00137 inline std::wstring DtToWString(char * in_val) 00138 { 00139 std::wstring temp; 00140 while (*in_val != '\0') 00141 temp += *in_val++; 00142 return temp; 00143 } 00144 00145 inline std::wstring DtToWString(const DtString &val) 00146 { 00148 return DtToWString(val.c_str()); 00149 } 00150 00151 template<typename T> 00152 inline std::string DtToString(const T &in_val) 00153 { 00154 std::stringstream temp; 00155 temp << in_val; 00156 return temp.str(); 00157 } 00158 00159 inline std::string DtToString(const std::wstring &in_val) 00160 { 00161 return DtToString(in_val.c_str()); 00162 } 00163 00164 00165 inline std::string DtToString(const wchar_t * in_val) 00166 { 00167 std::string temp; 00168 while (*in_val != L'\0') 00169 { 00170 temp += *in_val++; 00171 } 00172 return temp; 00173 } 00174 00175 inline DtString DtToLower(const char* str) 00176 { 00177 DtString copy(str); 00178 copy.toLower(); 00179 return copy; 00180 } 00181 00182 inline DtString DtToLower(const DtString& str) 00183 { 00184 DtString copy(str); 00185 copy.toLower(); 00186 return copy; 00187 } 00188 00189 inline DtString DtToUpper(const char* str) 00190 { 00191 DtString copy(str); 00192 copy.toUpper(); 00193 return copy; 00194 } 00195 00196 inline DtString DtToUpper(const DtString& str) 00197 { 00198 DtString copy(str); 00199 copy.toUpper(); 00200 return copy; 00201 } 00202 00203 00211 class DT_DLL_VLUTIL DtStringPatternMatch 00212 { 00213 public: 00214 00216 DtStringPatternMatch(); 00217 00219 DtStringPatternMatch(const DtString & testStr, 00220 const DtString & pattern = DtString::nullString()); 00221 00222 private: 00224 DtStringPatternMatch(const DtStringPatternMatch& orig); 00225 00227 DtStringPatternMatch& operator=(const DtStringPatternMatch& orig); 00228 00229 public: 00230 00232 virtual void setPattern(const DtString & pattern); 00233 virtual const DtString & pattern()const; 00234 00236 virtual void setString(const DtString & testStr); 00237 virtual const DtString & string()const; 00238 00247 virtual int indexOfOccurence(const int start = 0); 00248 00250 virtual ~DtStringPatternMatch(); 00251 00252 protected: 00253 00255 void buildSkipTable(); 00256 00257 00258 DtString myStrCopy; 00259 DtString myPattern; 00260 int * mySkipTable; 00261 00262 static const int theSkipTableSize; 00263 }; 00264 00265 #ifdef DtUSE_UTILITIES_NAMESPACE 00266 } 00267 #endif