#include <basestr.h>
Inheritance diagram for StringBase:

Public Member Functions | |
| StringBase () | |
| Default constructor for a StringBase. Sets the character buffer to 0 and the string length to zero. The user must call Alloc() before trying to use the StringBase. Scope: Public. | |
| virtual | ~StringBase () |
| Destroys & cleans up a string. | |
| virtual BOOL | Alloc (INT32 size) |
| Allocates space on the heap for a 0-terminated string of the passed size. This function should only be called for the StringBase base class, NOT for any of its fixed-length derivatives. | |
| BOOL | Load (UINT32 resID, UINT32 inst=0) |
| Extracts a string from the application's .EXE file, by default, or another module (eg. a dedicated DLL), overwriting the old contents of this StringBase object. | |
| INT32 | Length () const |
| Calculates the length of the string. | |
| INT32 | MaxLength () const |
| Calculates the longest allowed string that can be stored in this. | |
| BOOL | IsEmpty () const |
| Tests for the 0 string. | |
| INT32 | NextIndex (INT32 index) const |
| Find the next character index Notes: If string exceptions are enabled, an exception will be thrown if the index goes out of range. | |
| INT32 | PrevIndex (INT32 index) const |
| Find the previous character index Notes: If string exceptions are enabled, an exception will be thrown if the index goes out of range. | |
| BOOL | IsLegal (INT32 index) const |
| Check index for its legality. | |
| BOOL | IsIllegal (INT32 index) const |
| Check index for its legality. | |
| StringBase & | Empty () |
| Sets a string to the 0 string (zero-terminated but no characters, NOT A 0 POINTER!). | |
| StringBase & | toUpper () |
| Converts all lower-case letters in the string to upper-case. | |
| StringBase & | toLower () |
| Converts all upper-case letters to lower-case. | |
| StringBase & | toTitle () |
| Converts all the first letters of words to uppercase and the rest to lower case. | |
| INT32 __cdecl | MakeMsg (UINT32 resID...) |
| Internationally portable version of sprintf(...), eg. StringBase s; INT32 x, y, z; s.MakeMsg(_R(IDS_COORDFORMAT), x, y, z); TextOut(hdc, 20, 20, s, s.Length());. | |
| INT32 __cdecl | _MakeMsg (const TCHAR *fmt...) |
| Internationally portable version of sprintf(...), eg. UINT32 x; s._MakeMsg("#1%lu", x); TextOut(hdc, 20, 20, s, s.Length());. | |
| operator TCHAR * () | |
| Cast a string into a C-style pointer to array of characters. If you intend to use the subscript operator [] with the results of the cast remember that no range checking is performed. | |
| operator const TCHAR * () const | |
| Cast a string into a C-style pointer to array of constant characters. | |
| operator wxString () | |
| Cast a string into a wxString. | |
| operator const wxString () const | |
| Cast a string into a wxString. | |
| StringBase & | operator+= (const StringBase &rhs) |
| Append string y onto the end of string x, eg. x = TEXT("hello"); cout << (x += TEXT(" world!")) << endl;. | |
| StringBase & | operator+= (const TCHAR *s) |
| Append string y onto the end of string x, eg. x = TEXT("hello"); cout << (x += TEXT(" world!")) << endl;. | |
| StringBase & | operator+= (const TCHAR ch) |
| Appends this character to the end of this string. | |
| StringBase & | operator= (const StringBase &other) |
| Assignment (set equal to) operator, eg. StringBase x("rhubarb"); x = "custard";. | |
| StringBase & | operator= (const TCHAR *s) |
| Assignment (set equal to) operator, eg. StringBase x("rhubarb"); x = "custard";. | |
| StringBase & | operator= (const TCHAR ch) |
| Assigns the single character to this string. | |
| const StringBase & | Left (StringBase *out, UINT32 count) const |
| Similar to the BASIC Left$() string function. | |
| const StringBase & | Mid (StringBase *out, UINT32 first, UINT32 count) const |
| Similar to the BASIC Mid$() function. | |
| const StringBase & | Right (StringBase *out, UINT32 count) const |
| Similar to the BASIC Right$() function. | |
| void | Split (StringBase *pstrStart, StringBase *pstrEnd, INT32 iSplit, BOOL fIncludeSplitChar) |
| Splits a string into two separate strings at a given character. | |
| INT32 | Sub (const StringBase &mask, UINT32 from=0, TCHAR fuzz=0) const |
| Similar to the (non-standard) BASIC Instr$() function. Scope: Public. | |
| INT32 | SubWithoutCase (const StringBase &strToFind) const |
| Similar to the (non-standard) BASIC Instr$() function. Scope: Public. | |
| void | Remove (INT32 Position, INT32 Number) |
| Inserting a string into another one. Scope: Public. | |
| void | Insert (const StringBase &InsertString, INT32 Position) |
| Inserting a string into another one. Scope: Public. | |
| void | SwapChar (const TCHAR schar, const TCHAR rchar) |
| Exchange all schar characters in the string with rchar characters Scope: Public. | |
| INT32 | CountChar (const TCHAR tchar) |
| Count all tchar characters in the string Scope: Public. | |
| TCHAR | operator[] (const INT32 Index) |
| Extract single characters from the string... 0 is the first char, String.Length() is the terminating zero... | |
| const WCHAR | CharAt (const INT32 Index) const |
| Extract single characters from the string... 0 is the first char, String.Length() is the terminating zero... | |
| INT32 | SkipComma (INT32 pos=0) const |
| Find the next comma (starting from pos) and skip on to the next none space character beyond it. Notes: ** Throws an exception if string exceptions are enabled **. | |
| INT32 | SkipSpace (INT32 pos=0) const |
| Find the next non-space character starting from pos. If pos is a none space character, the function will simply return with the same index. Notes: ** Throws an exception if string exceptions are enabled **. | |
| INT32 | FindNextChar (INT32 position=0) const |
| Find the next none space character starting from pos. If pos is a none space character, the function will simply return with the same index. Notes: ** Throws an exception if string exceptions are enabled **. | |
| INT32 | FindNextChar (TCHAR c, INT32 position=0) const |
| Find the next character to match c starting from position. Notes: ** Throws an exception if string exceptions are enabled **. | |
| INT32 | ConvertToInteger (INT32 &position) const |
| Convert the sequence of characters starting from position into a numeric value. 32 bits of precision are returned and hence approx 10 digit numbers can be represented. If the numeric string is longer, the value 0x7FFFFFFF is returned (ie represting an overflow). If string exceptions are enabled, an exception will be thrown in this instance. All valid numeric digits will be read, no matter whether an overflow is immanent or not, hence you can safely continue to parse what is expected to be the next token along the string. The types of numbers allowed are +123686 -12394 124802398 but not 12439127397123. | |
| INT32 | ReverseFind (TCHAR cToFind) const |
| As above. | |
| virtual void | MakePercent (INT32 Value) |
| Set the string equal to the given argument + a % character, or however the current locale wants it Example: String_32 Str; Str.MakePercent(23); For UK, Str now equals "23%". | |
| virtual void | MakePercent (double Value) |
| virtual void | MakePercent (TCHAR *Value) |
| virtual void | FixFormat () |
| bool | IsIdentical (const TCHAR *other) const |
| Compare this StringBase object to another string. | |
| bool | IsIdentical (const StringBase &other) const |
| Compare this StringBase object to another string. | |
| INT32 | CompareTo (const TCHAR *other, BOOL CaseSensitive=TRUE) const |
| Compare this StringBase object to another string. This is mainly intended for use internally by the comparison operators, but may also come in handy in other places. | |
| INT32 | CompareTo (const StringBase &other, BOOL CaseSensitive=TRUE) const |
| Compare this StringBase object to another string. This is mainly intended for use internally by the comparison operators, but may also come in handy in other places. | |
Static Public Member Functions | |
| static BOOL | IsAlpha (TCHAR c) |
| Tests if the character is a-z, A-Z (or local equivalent). | |
| static BOOL | IsAlphaNumeric (TCHAR c) |
| Tests if the character is a-z, A-Z, 0-9, or local equivalent. | |
| static BOOL | IsNumeric (TCHAR c) |
| Tests if the character is 0-9, or local equivalent. | |
| static BOOL | IsLower (TCHAR c) |
| Tests if the character is a-z (or local equivalent). | |
| static BOOL | IsUpper (TCHAR c) |
| Tests if the character is A-Z, or local equivalent. | |
| static BOOL | IsSpace (TCHAR c) |
| static TCHAR * | SafeCat (TCHAR *pstr1, const TCHAR *pcstr2, UINT32 nchMax) |
| Appends string2 to the end of string1 and returns string1 as the result. The difference between this and camStrcat is the Max parameter which helps alleviate the buffer overwrite problems. Setting max to the length member of a stringbase will ERROR3IF that we don't go overwriting ends of buffers and suchlike... In such cases the result will be trucated. | |
| static BOOL | EnableExceptionHandler (BOOL PushNewHandler=TRUE) |
| This function adds a new exception handler to the string exception handler stack (if PushNewHandler is TRUE). Otherwise it will simply change the state of the most recently pushed handler. If there are no handlers and Push is FALSE, an ERROR3IF will be generated. | |
| static BOOL | DisableExceptionHandler (BOOL PopHandler=TRUE) |
| This function disables or completely removes the most previously enabled exception state. FALSE will be returned if the exception stack is empty. The default parameter allows you to temporarily disable the exception state without poping the handler. | |
| static BOOL | WillThrowException () |
| This function interogates the exceptions state stack and determins whether exceptions will be thrown or not. | |
Protected Attributes | |
| TCHAR * | text |
| UINT32 | length |
Private Member Functions | |
| INT32 | IllegalIndex () const |
| Generate an illegal index Notes: ** Can potentially throw a user exception **. | |
| INT32 | BuildList (const TCHAR *) |
| This private helper function scans the layout string, breaking it up into literal text and parameters, which are placed on an private list in the order they are encountered, together with their type and which argument passed to Format that they refer to. The formatting must be done in two passes as the order of the parameters is not known until the whole format string has been scanned. Scope: Private. | |
| INT32 | CCvsprintf (const TCHAR *, va_list) |
| This private helper function takes the list generated by StringBase::BuildList and scans through it, formatting stack-frame parameters according to their list entry. This produces another list, this time of formatted parameters, which is then concatenated to produce the final output. Scope: Private. | |
| StringBase (const StringBase &other) | |
| Copy constructor - this is made private (and unimplemented) as it will not work for base class strings, which must call Alloc() before they are used. Scope: Private. | |
Static Private Member Functions | |
| static INT32 | TCharToNum (TCHAR c) |
| Convert a TCHAR into a numeric value. The routine does not check for valid numeric characters, it just performs the conversion. Hence it is possibly for you to pass in the character 's' for instance and receive a >9 value back. | |
| static void | ThrowStringException () |
| Throws a 'User' exception if the string exception stack says 'Yes'. | |
Static Private Attributes | |
| static BOOL | ThrowExceptionStack [str_MAXEXCEPTIONS] |
| static INT32 | CurrEx = -1 |
Friends | |
| class | Error |
| bool | operator== (const StringBase &x, const TCHAR *y) |
| Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom. | |
| bool | operator== (const StringBase &x, const StringBase &y) |
| bool | operator< (const StringBase &x, const TCHAR *y) |
| bool | operator< (const StringBase &x, const StringBase &y) |
| Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom. | |
| bool | operator> (const StringBase &x, const TCHAR *y) |
| bool | operator> (const StringBase &x, const StringBase &y) |
| Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom. | |
| bool | operator!= (const StringBase &x, const TCHAR *y) |
| bool | operator!= (const StringBase &x, const StringBase &y) |
| Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom. | |
| bool | operator<= (const StringBase &x, const TCHAR *y) |
| bool | operator<= (const StringBase &x, const StringBase &y) |
| Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom. | |
| bool | operator>= (const StringBase &x, const TCHAR *y) |
| Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom. | |
| bool | operator>= (const StringBase &x, const StringBase &y) |
| std::istream & | operator>> (std::istream &is, StringBase &s) |
| Read a string from a (non-persistent) stream. The input is terminated by a newline character (NOT whitespace, cf. reading C-style character arrays). If the string is longer than MAX_STRING_RES_LENGTH get() will read as many characters as possible and put a newline at the end. | |
| std::ostream & | operator<< (std::ostream &os, const StringBase &s) |
| Write a string to a (non-persistent) stream. If the string is 0 then "[0]" is printed. | |
Definition at line 161 of file basestr.h.
|
|
Default constructor for a StringBase. Sets the character buffer to 0 and the string length to zero. The user must call Alloc() before trying to use the StringBase. Scope: Public.
Definition at line 340 of file basestr.h.
|
|
|
Destroys & cleans up a string.
Definition at line 375 of file basestr.h.
|
|
|
Copy constructor - this is made private (and unimplemented) as it will not work for base class strings, which must call Alloc() before they are used. Scope: Private.
Definition at line 360 of file basestr.h.
|
|
|
Internationally portable version of sprintf(...), eg. UINT32 x; s._MakeMsg("#1%lu", x); TextOut(hdc, 20, 20, s, s.Length());.
Definition at line 186 of file makemsg.cpp. 00187 { 00188 /* if (IsUserName("JustinF")) 00189 TRACE( _T("_MakeMsg called with format string %s\n"), fmt); 00190 */ 00191 ENSURE(text, "Call to StringBase::_MakeMsg for an unallocated String"); 00192 ENSURE(fmt, "Call to StringBase::_MakeMsg with a null format parameter"); 00193 00194 va_list ap; 00195 va_start(ap, fmt); 00196 00197 INT32 n = CCvsprintf(fmt, ap); 00198 00199 va_end(ap); 00200 return n; 00201 }
|
|
|
Allocates space on the heap for a 0-terminated string of the passed size. This function should only be called for the StringBase base class, NOT for any of its fixed-length derivatives.
Reimplemented in String_128, String_256, String_16, String_32, String_64, and String_8. Definition at line 142 of file basestr.cpp. 00143 { 00144 ERROR3IF(size < 0, "Attempt to ALLOCate a String of negative length"); 00145 if (text) delete[] text; 00146 #ifdef _UNICODE 00147 text = new TCHAR[length = size + 1]; 00148 #else 00149 text = new TCHAR[length = (size + 1) * 2]; // MBCS 00150 #endif 00151 ERRORIF(text == 0, _R(IDE_NOMORE_MEMORY), FALSE); 00152 *text = 0; 00153 return TRUE; 00154 }
|
|
|
This private helper function scans the layout string, breaking it up into literal text and parameters, which are placed on an private list in the order they are encountered, together with their type and which argument passed to Format that they refer to. The formatting must be done in two passes as the order of the parameters is not known until the whole format string has been scanned. Scope: Private.
Definition at line 284 of file makemsg.cpp. 00285 { 00286 /* if (IsUserName("JustinF")) 00287 TRACE( _T("\tBuildList called with format string %s\n"), format); 00288 */ 00289 ENSURE(format, "Null parameter passed to StringBase::BuildList"); 00290 const TCHAR* start = format; 00291 INT32 nArgs = 0; 00292 while (*start) 00293 { 00294 const TCHAR* next = start; 00295 // Look for a format specifier in the layout string 00296 if (*next == TEXT('#')) 00297 if (IsNumeric(*(++next))) 00298 { 00299 INT32 ArgPos = *next - TEXT('0'); // MS approved method - yuck!!! 00300 ENSURE(ArgPos >= 1 && ArgPos <= 9, 00301 "Illegal format string passed to MakeMsg!"); 00302 00303 if (*(++next) == TEXT('%')) 00304 { 00305 // Seem to have found the beginning of a specifier, 00306 // so try parsing it, to extract the type information 00307 if (*(++next) == TEXT('-')) next++; 00308 if (*next == TEXT('#')) next++; 00309 if (*next == TEXT('0')) next++; 00310 while (IsNumeric(*next)) next++; 00311 if (*next == TEXT('.')) 00312 while (IsNumeric(*++next)); 00313 00314 // Ok, we have skipped the width, precision etc. and 00315 // "next" should now be pointing at the type character(s) 00316 ArgType kind; 00317 if (*next == TEXT('l')) // an INT32 something or another? 00318 switch (*++next) 00319 { 00320 case TEXT('d'): case TEXT('i'): 00321 kind = SIGNED_INT32_ARG; 00322 break; 00323 case TEXT('u'): case TEXT('x'): case TEXT('X'): 00324 kind = UNSIGNED_INT32_ARG; 00325 break; 00326 default: // false alarm, can't be a specifier 00327 next = start + 1; 00328 goto not_format; 00329 } 00330 else 00331 switch (*next) // single type character 00332 { 00333 case TEXT('c'): 00334 kind = CHAR_ARG; 00335 break; 00336 case TEXT('d'): case TEXT('i'): 00337 kind = SIGNED_INT_ARG; 00338 break; 00339 case TEXT('p'): // a pointer 00340 kind = UINT_PTR_ARG; 00341 break; 00342 case TEXT('u'): case TEXT('x'): case TEXT('X'): 00343 kind = UNSIGNED_INT_ARG; 00344 break; 00345 case TEXT('s'): 00346 kind = CHAR_POINTER_ARG; 00347 break; 00348 case TEXT('S'): 00349 kind = STRING_POINTER_ARG; 00350 break; 00351 default: 00352 next = start + 1; 00353 goto not_format; // boo hiss hooray! 00354 } 00355 00356 // Successfully parsed the format specifier, so add 00357 // it to the Item list. Skip the leading #n of the specifier, 00358 // so (next) now points to the character following the '%X' 00359 // format specifier. 00360 next++; 00361 00362 // Extract the specifier. 00363 TCHAR temp[64]; 00364 INT32 len = next - start - 2; 00365 camStrncpy(temp, start + 2, len); 00366 temp[len] = 0; 00367 new Item(temp, ArgPos, kind); 00368 start = next; 00369 nArgs++; 00370 00371 /* if (IsUserName("JustinF")) 00372 { 00373 TRACE( _T("\tItem: (%d) at #%d %s\n"), kind, ArgPos, temp); 00374 TRACE( _T("\t\tRemaining: %s\n"), start); 00375 } 00376 */ 00377 continue; 00378 } 00379 else 00380 // Put back the previous character 00381 next--; 00382 } 00383 00384 not_format: 00385 // Scan a literal up to the next '#' or null, whichever is sooner 00386 while (*next && *next != TEXT('#')) next++; 00387 00388 TCHAR temp[256]; 00389 INT32 len = next - start; 00390 00391 camStrncpy(temp, start, len); 00392 temp[len] = 0; 00393 new Item(temp, 0, LITERAL); 00394 start = next; 00395 00396 /* if (IsUserName("JustinF")) 00397 { 00398 TRACE( _T("\tLiteral: %s\n"), temp); 00399 } 00400 */ 00401 } 00402 00403 return nArgs; 00404 }
|
|
||||||||||||
|
This private helper function takes the list generated by StringBase::BuildList and scans through it, formatting stack-frame parameters according to their list entry. This produces another list, this time of formatted parameters, which is then concatenated to produce the final output. Scope: Private.
Definition at line 425 of file makemsg.cpp. 00426 { 00427 /* if (IsUserName("JustinF")) 00428 TRACE( _T("CCvsprintf called with format string %s\n"), layout); 00429 */ 00430 INT32 n = BuildList(layout); 00431 for (INT32 i = 1; i <= n; i++) 00432 { 00433 for (Item* p = Item::head; p; p = p->next) 00434 if (p->pos != i) 00435 continue; 00436 else 00437 { // Found specifier i in the list, so grab from the stack 00438 // and call wsprintf() to convert to text. The converted 00439 // text is put in the temp[] buffer - note the enormous 00440 // size of this, in accordance with the C standard. 00441 TCHAR temp[512]; 00442 switch (p->type) 00443 { 00444 // type 'c' - single character 00445 case CHAR_ARG: 00446 #if defined(__WXMSW__) 00447 camSnprintf( temp, 512, p->str, va_arg(va, TCHAR) ); 00448 #else // TCHARs are promoted to INT32 when passed via ... under GCC 00449 camSnprintf( temp, 512, p->str, va_arg(va, INT32) ); 00450 #endif 00451 break; 00452 // type 'd' / 'i' - signed decimal integer 00453 case SIGNED_INT_ARG: 00454 camSnprintf(temp, 512, p->str, va_arg(va, INT32)); 00455 break; 00456 // type 'ld' / 'li' - signed decimal INT32 00457 case SIGNED_INT32_ARG: 00458 camSnprintf(temp, 512, p->str, va_arg(va, INT32)); 00459 break; 00460 // type 'u' - unsigned decimal integer 00461 case UNSIGNED_INT_ARG: 00462 camSnprintf(temp, 512, p->str, va_arg(va, UINT32)); 00463 break; 00464 // type 'lu' / 'lx' / 'lX' - unsigned decimal INT32 00465 case UNSIGNED_INT32_ARG: 00466 camSnprintf(temp, 512, p->str, va_arg(va, UINT32)); 00467 break; 00468 // type 's' - long pointer to array of (constant) char 00469 case CHAR_POINTER_ARG: 00470 camSnprintf(temp, 512, p->str, va_arg(va, LPCTSTR)); 00471 break; 00472 // type 'p' a pointer 00473 case UINT_PTR_ARG: 00474 camSnprintf(temp, 512, p->str, va_arg(va, UINT_PTR)); 00475 break; 00476 // type 'S' - a pointer to a StringBase. First change the 00477 // %S format specifier, which is our own, into a sprintf() 00478 // compatible %s. Note that the 'S' is always the last 00479 // character of the format specifier. 00480 case STRING_POINTER_ARG: 00481 (p->str)[camStrlen(p->str) - 1] = TEXT('s'); 00482 camSnprintf(temp, 512, p->str, LPCTSTR(va_arg(va, const StringBase*)->text)); 00483 break; 00484 default: 00485 break; 00486 } 00487 // Replace the format specifier with the formatted text 00488 delete[] p->str; 00489 camStrcpy(p->str = new TCHAR[camStrlen(temp) + 1], temp); 00490 break; 00491 } 00492 } 00493 00494 // Concatenate every string in the list, tidy up, and return in "this" string 00495 *text = 0; 00496 UINT32 NextChar = 0; 00497 INT32 Index = 0; 00498 for (Item* p = Item::head; (p != NULL && NextChar < length) ; p = p->next) 00499 { 00500 /* if (camStrlen(text) + camStrlen(p->str) < length) 00501 camStrcat(text, p->str); 00502 else 00503 { 00504 ENSURE(FALSE, "Call to String::MakeMsg will overflow - text has been truncated"); 00505 } 00506 */ 00507 for (Index = 0; p->str[Index] != 0 && NextChar < length; Index++) 00508 text[NextChar++] = p->str[Index]; 00509 } 00510 00511 if (NextChar > length) 00512 NextChar = length; 00513 text[NextChar] = TCHAR('\0'); 00514 00515 delete Item::head; 00516 return camStrlen(text); 00517 }
|
|
|
Extract single characters from the string... 0 is the first char, String.Length() is the terminating zero...
Definition at line 898 of file basestr.h. 00899 { 00900 #ifdef UNICODE 00901 ERROR3IF(!text, "Call to String::operator[] for an unALLOCated String"); 00902 TCHAR ch = (text && (Index <= (INT32)camStrlen(text))) ? text[Index] : 0; 00903 00904 return (WCHAR)ch; 00905 00906 #else 00907 PORTNOTETRACE("other", "WCHAR StringBase::CharAt does nothing in non-UNICODE builds!"); 00908 ERROR3("This function is unimplemented in non-UNICODE builds!"); 00909 return (WCHAR)0; 00910 #endif 00911 }
|
|
||||||||||||
|
Compare this StringBase object to another string. This is mainly intended for use internally by the comparison operators, but may also come in handy in other places.
Zero, if the strings are considered equal A positive value if this is considered 'greater than' other Notes: This function is VERY SLOW, but does proper comparisons for the locale to determine relative positioning of strings. Use StringBase::IsIdentical to see if 2 strings are exactly the same.
Definition at line 285 of file basestr.cpp. 00286 { 00287 ERROR3IF(text == 0 || other.text == 0, "StringBase::CompareTo: not ALLOCed"); 00288 PORTNOTE("other", "StringBase::CompareTo should be locale specific"); 00289 #if FALSE 00290 DWORD dw = NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH; 00291 if (!CaseSensitive) dw |= NORM_IGNORECASE; 00292 return CompareString(LOCALE_USER_DEFAULT, dw, text, -1, other.text, -1) - 2; 00293 #endif 00294 00295 if( CaseSensitive ) 00296 { 00297 return camStrcmp( text, other.text ); 00298 } 00299 else 00300 { 00301 return camStricmp( text, other.text ); 00302 } 00303 }
|
|
||||||||||||
|
Compare this StringBase object to another string. This is mainly intended for use internally by the comparison operators, but may also come in handy in other places.
Zero, if the strings are considered equal A positive value if this is considered 'greater than' other Notes: This function is VERY SLOW, but does proper comparisons for the locale to determine relative positioning of strings. Use StringBase::IsIdentical to see if 2 strings are exactly the same.
Definition at line 336 of file basestr.cpp. 00337 { 00338 ERROR3IF(text == 0 || other == 0, "StringBase::CompareTo: null buffers"); 00339 PORTNOTE("other", "StringBase::CompareTo should be locale specific"); 00340 #if FALSE 00341 DWORD dw = NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH; 00342 if (!CaseSensitive) dw |= NORM_IGNORECASE; 00343 return CompareString(LOCALE_USER_DEFAULT, dw, text, -1, other, -1) - 2; 00344 #endif 00345 00346 if( CaseSensitive ) 00347 { 00348 return camStrcmp( text, other ); 00349 } 00350 else 00351 { 00352 return camStricmp( text, other ); 00353 } 00354 }
|
|
|
Convert the sequence of characters starting from position into a numeric value. 32 bits of precision are returned and hence approx 10 digit numbers can be represented. If the numeric string is longer, the value 0x7FFFFFFF is returned (ie represting an overflow). If string exceptions are enabled, an exception will be thrown in this instance. All valid numeric digits will be read, no matter whether an overflow is immanent or not, hence you can safely continue to parse what is expected to be the next token along the string. The types of numbers allowed are +123686 -12394 124802398 but not 12439127397123.
Definition at line 1529 of file basestr.cpp. 01530 { 01531 ERROR3IF(!text, "Call to StringBase::ConvertToInteger for unALLOCated String"); 01532 01533 const TCHAR pos = TEXT('+'); 01534 const TCHAR neg = TEXT('-'); 01535 01536 INT32 value = 0; 01537 BOOL isneg = FALSE; 01538 INT32 maxdigs = 10; 01539 INT32 nchars = Length(); 01540 01541 position = SkipSpace(position); 01542 if (position>-1 && position<nchars) 01543 { 01544 isneg = (text[position]==neg); 01545 if (isneg || text[position]==pos) 01546 position=NextIndex(position); 01547 01548 while (position<nchars && IsNumeric(text[position])) 01549 { 01550 value = value*10 + (StringBase::TCharToNum(text[position])); 01551 position=NextIndex(position); 01552 maxdigs--; 01553 } 01554 01555 if (maxdigs<0) 01556 { 01557 TRACEUSER("Mike", wxT("Overflow during ConvertToInteger") ); 01558 StringBase::ThrowStringException(); 01559 return ((isneg) ? 0x80000000 : 0x7FFFFFFF); 01560 } 01561 01562 value = (isneg) ? (-value) : (value); 01563 } 01564 01565 return value; 01566 }
|
|
|
Count all tchar characters in the string Scope: Public.
Definition at line 975 of file basestr.cpp. 00976 { 00977 ERROR3IF(!text, "Call to String::CountChar for an unALLOCated String"); 00978 INT32 Count = 0; 00979 if (text) 00980 { 00981 TCHAR* pThis = text; 00982 while (*pThis != 0) 00983 { 00984 if (*pThis == tchar) 00985 Count ++; 00986 pThis = camStrinc(pThis); 00987 } 00988 } 00989 return Count; 00990 }
|
|
|
This function disables or completely removes the most previously enabled exception state. FALSE will be returned if the exception stack is empty. The default parameter allows you to temporarily disable the exception state without poping the handler.
Definition at line 1333 of file basestr.cpp. 01334 { 01335 ERROR2IF(CurrEx < 0, FALSE, "StringBase::DisableExceptions; Nothing on the exception stack!"); 01336 ThrowExceptionStack[CurrEx]=FALSE; 01337 if (PopHandler) CurrEx--; 01338 return TRUE; 01339 }
|
|
|
Sets a string to the 0 string (zero-terminated but no characters, NOT A 0 POINTER!).
Definition at line 719 of file basestr.h. 00720 { 00721 ERROR3IF(!text, "Attempt to EMPTY an unALLOCated String"); 00722 if (text) *text = 0; 00723 return *this; 00724 }
|
|
|
This function adds a new exception handler to the string exception handler stack (if PushNewHandler is TRUE). Otherwise it will simply change the state of the most recently pushed handler. If there are no handlers and Push is FALSE, an ERROR3IF will be generated.
Definition at line 1303 of file basestr.cpp. 01304 { 01305 if (PushNewHandler) CurrEx++; 01306 01307 ERROR2IF(CurrEx >= str_MAXEXCEPTIONS, FALSE, "StringBase::EnableExceptions overflow!"); 01308 ERROR2IF(CurrEx < 0, FALSE, "StringBase::EnableExceptions - handler does not exist"); 01309 01310 ThrowExceptionStack[CurrEx]=TRUE; 01311 return TRUE; 01312 }
|
|
||||||||||||
|
Find the next character to match c starting from position. Notes: ** Throws an exception if string exceptions are enabled **.
Definition at line 1455 of file basestr.cpp. 01456 { 01457 ERROR3IF(!text, "Call to StringBase::FindNextChar for unALLOCated String"); 01458 INT32 nchars = Length(); 01459 if (!text || position<0 || position>=nchars) 01460 return IllegalIndex(); 01461 01462 while ((text[position]!=c) && position<nchars) 01463 position=NextIndex(position); 01464 01465 return ((position==nchars) ? (IllegalIndex()) : (position)); 01466 }
|
|
|
Find the next none space character starting from pos. If pos is a none space character, the function will simply return with the same index. Notes: ** Throws an exception if string exceptions are enabled **.
Definition at line 1423 of file basestr.cpp. 01424 { 01425 ERROR3IF(!text, "Call to StringBase::FindNextChar for unALLOCated String"); 01426 01427 // get the length of this string in characters 01428 INT32 nchars = Length(); 01429 if (!text || position<0 || position>=nchars) 01430 return IllegalIndex(); 01431 01432 TCHAR c = TEXT(' '); 01433 while ((text[position]==c) && position<nchars) 01434 position=NextIndex(position); 01435 01436 return ((position==nchars) ? (IllegalIndex()) : (position)); 01437 }
|
|
|
Definition at line 1042 of file basestr.cpp. 01043 { 01044 #if FALSE 01045 #if 0 != wxUSE_UNICODE 01046 INT32 i=0; 01047 while ((i+1)<Length()) // Don't look at the last character 01048 { 01049 if ( (text[i]==_T('%')) && ( (text[i+1]==_T('s')) || (text[i+1]==_T('c')) ) ) 01050 { 01051 String_8 l(_T("l")); 01052 Insert(l, i+1); 01053 i++; // Skip over the inserted char too 01054 } 01055 i++; 01056 } 01057 #endif 01058 #endif 01059 }
|
|
|
Generate an illegal index Notes: ** Can potentially throw a user exception **.
Definition at line 567 of file basestr.h. 00568 { 00569 StringBase::ThrowStringException(); 00570 return -1; 00571 }
|
|
||||||||||||
|
Inserting a string into another one. Scope: Public.
|