Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeString.h

Go to the documentation of this file.
00001 //
00002 // CascadeString.h - header file for class CascadeString
00003 //
00004 // Copyright (c) 2002, Roku, LLC.  All rights reserved.
00005 //
00007 
00008 #ifndef _ROKU_INCLUDE_CASCADE_UTIL_CASCADESTRING_H
00009 #define _ROKU_INCLUDE_CASCADE_UTIL_CASCADESTRING_H
00010 
00011 #include <cascade/CascadeObject.h>
00012 
00025 class CascadeString : public CascadeObject
00026 {
00027 public:
00028         CascadeString();
00032     CascadeString(const CascadeString & string);
00037     CascadeString(const char * pString);
00043     virtual ~CascadeString();
00047 public:
00048     static bool SetSystemLanguage (const char * pLanguage);
00050     static bool GetSystemLanguage (char * pLanguageToSet, u32 nBuffLen);
00052     typedef bool (* LanguageEnumProc)(const CascadeString & lang, const CascadeString & friendlyLang, void * pClientData);
00053     static bool EnumerateStringResourceLanguages(class CascadeStream & stream, LanguageEnumProc callback, void * pClientData);
00060     static bool LoadStringResources(class CascadeStream & stream, const char * pLang = NULL, bool bClearFirst = true);
00086     static void ClearStringResources();
00091     static bool AddStringResource(const CascadeString & resourceID, const CascadeString & string);
00099     static bool RemoveStringResource(const CascadeString & resourceID);
00106     bool LoadString(const char * pResourceID);
00118 public:
00119     inline u32 GetLength() const { return m_nLength; }
00125     inline u32 GetTerminatedLength() const { return m_nLength + 1; }
00130     u32 CountChars() const;
00136     CascadeUnicodeChar ReadOneUnicodeChar( u32 &ioToken ) const;
00152     CascadeUnicodeChar ReadNthUnicodeChar( u32 inIdx ) const;
00164     void AppendUnicodeChar( CascadeUnicodeChar inCh );
00170     static CascadeUnicodeChar UnicodeCharToUpper( CascadeUnicodeChar inChar );
00181     static CascadeUnicodeChar UnicodeCharToLower( CascadeUnicodeChar inChar );
00192     static CascadeUnicodeChar UnicodeCharStripDiacritical( CascadeUnicodeChar inChar );
00207     static bool UnicodeCharIsAlpha( CascadeUnicodeChar inChar );
00215     static bool UnicodeCharIsDigit( CascadeUnicodeChar inChar );
00224     inline bool IsEmpty() const { return (0 == m_nLength); }
00229         void Empty();
00233         bool TrimAllocation();
00240     void Truncate(u32 nNewLength);
00250     u32 TruncateToByteLen(u32 nNewByteLength, bool bBreakOnChar = true);
00275     
00276     inline bool IsEqual(const char * pString, bool bCaseSensitive = true) const { return (0 == Compare(pString, bCaseSensitive)); }
00284     s32 Compare( const char * pString, 
00285                  bool bCaseSensitive = true,
00286                  bool bIgnoreDiacritical = false,
00287                  u32 nLen = 0xFFFFFFFF ) const;
00306     s32 CompareNBytes(const char * pString, 
00307                       u32 nBytes) const;
00321     
00322     bool Contains(const char * pString, 
00323                   bool bCaseSensitive = true,
00324                   bool bIgnoreDiacriticals = false) const;
00338     bool ContainsBytes( const char * pString ) const;
00347     void ToLower( bool bStripDiacriticals = false );
00356     void ToUpper( bool bStripDiacriticals = false );
00365     void StripDiacriticals();
00371     inline operator const char * () const { return ((NULL == m_pString) ? "" : m_pString); }
00406     const CascadeString & operator = (const char * pString);
00410     inline const CascadeString & operator = (const CascadeString & string) { return operator = (((const char *)string)); }
00414     const CascadeString & operator += (const char * pString);
00418     const CascadeString & operator += (char ch);
00422     inline char operator [] (u32 nIndex) { return ((nIndex < m_nLength) ? (*(m_pString + nIndex)) : 0); }
00432 private:
00433     operator const void * () const;
00434         // This private const void * casting operator (which is unimplemented)
00435         // exists to prevent the compiler from allowing this:
00436         // CascadeString string; delete string;
00437         // which it would otherwise allow due to the const char * casting operator.
00438 private:
00439     // Length of the string (excluding the NULL, like strlen)
00440     u32 m_nLength;
00441     // Size of the internal buffer, in bytes (used when appending, to
00442     // see if we need to allocate more memory).
00443     u32 m_nBuffSize;
00444     // The string data
00445     char * m_pString;
00446 };
00447 
00448 
00450 //  global operators dealing with class CascadeString
00451 //  NOTE: These operators are provided to remove ambiguity with the const char *
00452 //        casting operator which can lead to nasty results if the compiler auto-casts
00453 //        your CascadeString to a const char *
00454 
00455 CascadeString operator + (const CascadeString & string1, const CascadeString & string2);
00464 
00465 CascadeString operator + (const CascadeString & string, const char * pString);
00466 CascadeString operator + (const char * pString, const CascadeString & string);
00467 
00468 inline bool
00469 operator == (const CascadeString & string1, const CascadeString & string2)
00470 {
00471     return (0 == string1.Compare(string2));
00472 }
00479 
00480 inline bool
00481 operator == (const CascadeString & string, const char * pString)
00482 {
00483     return (0 == string.Compare(pString));
00484 }
00485 
00486 inline bool
00487 operator == (const char * pString, const CascadeString & string)
00488 {
00489     return (0 == string.Compare(pString));
00490 }
00491 
00492 inline bool
00493 operator != (const CascadeString & string1, const CascadeString & string2)
00494 {
00495     return (0 != string1.Compare(string2));
00496 }
00497 
00498 inline bool
00499 operator != (const CascadeString & string, const char * pString)
00500 {
00501     return (0 != string.Compare(pString));
00502 }
00503 
00504 inline bool
00505 operator != (const char * pString, const CascadeString & string)
00506 {
00507     return (0 != string.Compare(pString));
00508 }
00509 
00510 inline bool
00511 operator < (const CascadeString & string1, const CascadeString & string2)
00512 {
00513     return (string1.Compare(string2) < 0);
00514 }
00515 
00516 inline bool
00517 operator < (const CascadeString & string, const char * pString)
00518 {
00519     return (string.Compare(pString) < 0);
00520 }
00521 
00522 inline bool
00523 operator < (const char * pString, const CascadeString & string)
00524 {
00525     return (string.Compare(pString) > 0); // note intended reversed direction
00526 }
00527 
00528 inline bool
00529 operator > (const CascadeString & string1, const CascadeString & string2)
00530 {
00531     return (string1.Compare(string2) > 0);
00532 }
00533 
00534 inline bool
00535 operator > (const CascadeString & string, const char * pString)
00536 {
00537     return (string.Compare(pString) > 0);
00538 }
00539 
00540 inline bool
00541 operator > (const char * pString, const CascadeString & string)
00542 {
00543     return (string.Compare(pString) < 0); // note intended reversed direction
00544 }
00545 
00546 inline bool
00547 operator <= (const CascadeString & string1, const CascadeString & string2)
00548 {
00549     return (string1.Compare(string2) <= 0);
00550 }
00551 
00552 inline bool
00553 operator <= (const CascadeString & string, const char * pString)
00554 {
00555     return (string.Compare(pString) <= 0);
00556 }
00557 
00558 inline bool
00559 operator <= (const char * pString, const CascadeString & string)
00560 {
00561     return (string.Compare(pString) >= 0); // note intended reversed direction
00562 }
00563 
00564 inline bool
00565 operator >= (const CascadeString & string1, const CascadeString & string2)
00566 {
00567     return (string1.Compare(string2) >= 0);
00568 }
00569 
00570 inline bool
00571 operator >= (const CascadeString & string, const char * pString)
00572 {
00573     return (string.Compare(pString) >= 0);
00574 }
00575 
00576 inline bool
00577 operator >= (const char * pString, const CascadeString & string)
00578 {
00579     return (string.Compare(pString) <= 0); // note intended reversed direction
00580 }
00581 
00582 #endif // #ifndef _ROKU_INCLUDE_CASCADE_UTIL_CASCADESTRING_H
00583 
00585 // LOG
00587 //  20-Dec-02   dwoodward   created
00588 //  20-Jan-03   dwoodward       1.0 STATUS: 10% complete - GO MIKE!
00589 //  26-Jan-03   dwoodward   added GetLength() and const char * casting operator
00590 //  04-Feb-03   mjkobb      Added GetTerminatedLength(), Append(), Truncate(),
00591 //                          Copy(), char* copy constructor, = operator, and 
00592 //                          populated existing stubbed functions.  I will add
00593 //                          more functions as I find that I need them.  Please
00594 //                          ask if you want specific functionality.
00595 //                          1.0 STATUS: 60% complete.
00596 //  28-Apr-03   pellis      added operator== and IsEquals()
00597 //      28-May-03       pellis          added < <= > >=
00598 //  08-Jun-03   mjkobb      Doxygen
00599 //  25-Jun-03   dwoodward   added != operators
00600 //  20-Aug-03   dwoodward   revamped operators - made all comparison operators global
00601 //                          to avoid ambiguity with const char * casting operator
00602 //      19-Feb-04       dwoodward       added += operator for characters
00603 //      22-Feb-04       dwoodward       added string resource functions
00604 //  25-Feb-04   dwoodward   added AddStringResource() and RemoveStringResource()
00605 //  30-Mar-04   dwuertele   added CountChars(), SetSystemLanguage() and GetSystemLanguage()
00606 //  28-Sep-04   mjkobb      Added Contains, ToUpper, ToLower
00607 //  07-Oct-04   mjkobb      Added CompareFirstN
00608 //  10-Dec-04   dsletten    added EnumerateStringResourceLanguages()
00609 //  16-Mar-05   mjkobb      Added Unicode-aware Compare function, added Unicode
00610 //                          character utilities, added CompareNBytes, removed
00611 //                          CompareFirstN
00612 //  23-Mar-05   mjkobb      More UTF-8 savvy functions
00613 //  04-Apr-05   mjkobb      Clarify a comment
00614 //  13-May-05   dwoodward   don't include CascadeStream.h

Generated on Sun Jul 24 14:27:17 2005 for Cascade Library by  doxygen 1.4.1