00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00022 #ifndef OSCL_STR_PTR_LEN_H_INCLUDED
00023 #define OSCL_STR_PTR_LEN_H_INCLUDED
00024
00025
00026 #ifndef OSCL_BASE_H_INCLUDED
00027 #include "oscl_base.h"
00028 #endif
00029
00030 #ifndef OSCL_STDSTRING_H_INCLUDED
00031 #include "oscl_stdstring.h"
00032 #endif
00033
00034
00035
00036
00037
00038
00039
00040
00041 const uint8 OSCL_ASCII_CASE_MAGIC_BIT = 0x20;
00042
00044
00047 typedef struct StrPtrLen
00048 {
00049 protected:
00050 const char* ptr;
00051 int32 len;
00052
00053 bool isLetter(const char c) const
00054 {
00055 return ((c >= 65 && c <= 90) || (c >= 97 && c <= 122));
00056 }
00057
00058 public:
00059
00060 StrPtrLen(const char* newPtr)
00061 : ptr(newPtr)
00062 {
00063 len = oscl_strlen(newPtr);
00064 }
00065
00066 StrPtrLen(const char* newPtr, uint32 newLen)
00067 : ptr(newPtr), len(newLen)
00068 {}
00069
00070 StrPtrLen()
00071 : ptr(""), len(0)
00072 {}
00073
00074 StrPtrLen(const StrPtrLen& rhs)
00075 : ptr(rhs.ptr), len(rhs.len)
00076 {}
00077
00078 const char* c_str() const
00079 {
00080 return ptr;
00081 }
00082
00083 int32 length() const
00084 {
00085 return len;
00086 }
00087
00088 int32 size() const
00089 {
00090 return len;
00091 }
00092
00093 void setPtrLen(const char* newPtr, uint32 newLen)
00094 {
00095 ptr = newPtr;
00096 len = newLen;
00097 }
00098
00099 c_bool isCIEquivalentTo(const StrPtrLen& rhs) const
00100 {
00101 if (len != rhs.len)
00102 {
00103 return false;
00104 }
00105
00106 return isCIPrefixOf(rhs);
00107 }
00108
00109 c_bool isCIPrefixOf(const StrPtrLen& rhs) const
00110 {
00111 if (len > rhs.len)
00112 {
00113 return false;
00114 }
00115
00116 for (int32 ii = 0; ii < len; ++ii)
00117 {
00118 if (ptr[ii] != rhs.ptr[ii])
00119 {
00120 if (!isLetter(ptr[ii]) ||
00121 (OSCL_ASCII_CASE_MAGIC_BIT != ((ptr[ii] ^ rhs.ptr[ii]) | OSCL_ASCII_CASE_MAGIC_BIT)))
00122 {
00123 return false;
00124 }
00125 }
00126 }
00127 return true;
00128 }
00129
00130 int32 operator==(const StrPtrLen& rhs) const
00131 {
00132 if (len != rhs.len)
00133 {
00134
00135 return false;
00136 }
00137
00138 return(!oscl_strncmp(ptr, rhs.ptr, rhs.len));
00139 }
00140
00141 int32 operator!=(const StrPtrLen& rhs) const
00142 {
00143 return !(*this == rhs);
00144 }
00145
00146 StrPtrLen &operator=(const StrPtrLen& rhs)
00147 {
00148 this->ptr = rhs.ptr;
00149 this->len = rhs.len;
00150 return *this;
00151 }
00152
00153 StrPtrLen &operator=(const char* rhs)
00154 {
00155 this->ptr = rhs;
00156 this->len = oscl_strlen(rhs);
00157 return *this;
00158 }
00159
00160 } StrPtrLen;
00161
00163
00166 typedef struct WStrPtrLen
00167 {
00168 protected:
00169 const oscl_wchar* ptr;
00170 int32 len;
00171
00172 public:
00173
00174 WStrPtrLen(const oscl_wchar* newPtr)
00175 : ptr(newPtr)
00176 {
00177 len = oscl_strlen(newPtr);
00178 }
00179
00180 WStrPtrLen(const oscl_wchar* newPtr, uint32 newLen)
00181 : ptr(newPtr), len(newLen)
00182 {}
00183
00184 WStrPtrLen()
00185 : ptr(NULL), len(0)
00186 {}
00187
00188 WStrPtrLen(const WStrPtrLen& rhs)
00189 : ptr(rhs.ptr), len(rhs.len)
00190 {}
00191
00192 const oscl_wchar* c_str() const
00193 {
00194 return ptr;
00195 }
00196
00197 int32 length() const
00198 {
00199 return len;
00200 }
00201
00202 int32 size() const
00203 {
00204 return len;
00205 }
00206
00207 void setPtrLen(const oscl_wchar* newPtr, uint32 newLen)
00208 {
00209 ptr = newPtr;
00210 len = newLen;
00211 }
00212
00213 c_bool isCIEquivalentTo(const WStrPtrLen& rhs) const
00214 {
00215 if (len != rhs.len)
00216 {
00217 return false;
00218 }
00219
00220 for (int32 ii = 0; ii < len; ++ii)
00221 {
00222 if (OSCL_ASCII_CASE_MAGIC_BIT != ((ptr[ii] ^ rhs.ptr[ii]) | OSCL_ASCII_CASE_MAGIC_BIT))
00223 {
00224 return false;
00225 }
00226 }
00227
00228 return true;
00229 }
00230
00231 int32 operator==(const WStrPtrLen& rhs) const
00232 {
00233 if (len != rhs.len)
00234 {
00235 return (len - rhs.len);
00236 }
00237 return(!oscl_strncmp(ptr, rhs.ptr, rhs.len));
00238 }
00239
00240 int32 operator!=(const WStrPtrLen& rhs) const
00241 {
00242 return !(*this == rhs);
00243 }
00244
00245 WStrPtrLen& operator=(const WStrPtrLen& rhs)
00246 {
00247 this->ptr = rhs.ptr;
00248 this->len = rhs.len;
00249 return *this;
00250 }
00251
00252 WStrPtrLen& operator=(const oscl_wchar* rhs)
00253 {
00254 this->ptr = rhs;
00255 this->len = oscl_strlen(rhs);
00256 return *this;
00257 }
00258
00259 } WStrPtrLen;
00260
00262 typedef struct StrCSumPtrLen : public StrPtrLen
00263 {
00264 public:
00265 typedef int16 CheckSumType;
00266
00267 protected:
00268 CheckSumType checkSum;
00269
00270 public:
00271
00272 void setPtrLen(const char* newPtr, uint32 newLen)
00273 {
00274 StrPtrLen::setPtrLen(newPtr, newLen);
00275 setCheckSum();
00276 }
00277
00278 CheckSumType getCheckSum() const
00279 {
00280 return checkSum;
00281 }
00282
00283 OSCL_IMPORT_REF void setCheckSum();
00284
00285 StrCSumPtrLen()
00286 : checkSum(0)
00287 {}
00288
00289 StrCSumPtrLen(const char* newPtr)
00290 : StrPtrLen(newPtr)
00291 {
00292 setCheckSum();
00293 }
00294
00295 StrCSumPtrLen(const char* newPtr, uint32 newLen)
00296 : StrPtrLen(newPtr, newLen)
00297 {
00298 setCheckSum();
00299 }
00300
00301 StrCSumPtrLen(const StrCSumPtrLen& rhs)
00302 : StrPtrLen(rhs), checkSum(rhs.checkSum)
00303 {}
00304
00305 StrCSumPtrLen(const StrPtrLen & rhs)
00306 : StrPtrLen(rhs)
00307 {
00308 setCheckSum();
00309 }
00310
00311
00312 c_bool isCIEquivalentTo(const StrCSumPtrLen& rhs) const
00313 {
00314 if (getCheckSum() != rhs.getCheckSum())
00315 {
00316 return false;
00317 }
00318
00319 return static_cast<const StrPtrLen&>(*this).isCIEquivalentTo(
00320 static_cast<const StrPtrLen&>(rhs));
00321 }
00322
00323 c_bool operator==(const StrCSumPtrLen& rhs) const
00324 {
00325 if (getCheckSum() != rhs.getCheckSum())
00326 {
00327 return false;
00328 }
00329
00330 return (static_cast<const StrPtrLen&>(*this)
00331 == static_cast<const StrPtrLen&>(rhs));
00332 }
00333
00334 c_bool operator!=(const StrCSumPtrLen& rhs) const
00335 {
00336 return !(*this == rhs);
00337 }
00338
00339 StrCSumPtrLen& operator=(const StrCSumPtrLen& rhs)
00340 {
00341 StrPtrLen::operator=(rhs);
00342 this->checkSum = rhs.checkSum;
00343 return *this;
00344 }
00345
00346 StrCSumPtrLen& operator=(const StrPtrLen& rhs)
00347 {
00348 StrPtrLen::operator=(rhs);
00349 setCheckSum();
00350 return *this;
00351 }
00352
00353 StrCSumPtrLen& operator=(const char* rhs)
00354 {
00355 StrPtrLen::operator=(rhs);
00356 setCheckSum();
00357 return *this;
00358 }
00359
00360 } StrCSumPtrLen;
00361
00362
00363 typedef WStrPtrLen OSCL_TStrPtrLen;
00364
00365 #endif // OSCL_STR_PTR_LEN_H_INCLUDED
00366