UTString.h

Go to the documentation of this file.
00001 //==================================================================================================
00002 // Copyright (C) 2010  Brian Tietz    sdbtietz at yahoo dot com
00003 //
00004 // This program is free software; you can redistribute it and/or modify it under the terms of the
00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the
00006 // License.
00007 //
00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010 // General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License along with this program; if
00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00014 // 02110-1301, USA.
00015 //
00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com)
00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that
00018 // license as applied to the UT library in exchange for either substantial contributions to the
00019 // development of the UT library or other forms of compensation.  Any such waiver must be
00020 // established in writing between the copyright holder and the commercial entity obtaining such a
00021 // waiver.
00022 //==================================================================================================
00023 
00024 
00025 #ifndef _UT_STRING_H_
00026 #define _UT_STRING_H_
00027 
00028 
00029 //==================================================================================================
00030 //=== Project headers
00031 //==================================================================================================
00032 #include "UTBuffer.h"
00033 
00034 
00035 //==================================================================================================
00036 //=== Constants
00037 //==================================================================================================
00041 enum line_ending_type_t
00042 {
00043     eLINEENDING_unix,
00044     eLINEENDING_dos,
00045     eLINEENDING_native
00046 };
00047 
00048 
00049 //==================================================================================================
00050 class UT_EXPORT String_t
00051 //==================================================================================================
00052 : private Buffer_t
00063 {
00064     //----------------------------------------------------------------------------------------------
00065     public:
00066     //----------------------------------------------------------------------------------------------
00067     inline                  String_t();
00069 
00070     inline                  String_t( byte* buffer, int buffer_size );
00074 
00075                             String_t(stringliteral* string);
00084 
00085                             String_t(const utf8* string);
00089 
00090     inline                  String_t(const String_t& copy);
00094 
00095     inline                  String_t(const wchar_t* string);
00098 
00099     inline int              LengthBytes() const;
00104 
00105     inline int              LengthChars() const;
00110 
00111     inline bool             IsEmpty() const;
00113 
00114     inline void             MakeEmpty();
00116 
00117     inline bool             IsASCII() const;
00120 
00121     void                    ToASCII(    out SimpleTypedBuffer_t<ascii7>* buffer,
00122                                         bool escape_all,
00123                                         const ascii7* escape_also ) const;
00133 
00134     inline Status_t         FromEscapedASCII(   const ascii7* ascii,
00135                                                 ascii7 stop_at = 0,
00136                                                 int length = -1 );
00153 
00154     Status_t                AppendFromEscapedASCII( const ascii7* ascii,
00155                                                     ascii7 stop_at = 0,
00156                                                     int length = -1 );
00159 
00160     void                    ToWChar(out SimpleTypedBuffer_t<wchar_t>* buffer) const;
00166 
00167     inline const utf8*      UTF8() const;
00169 
00170     inline stringliteral*   ConstChars() const;
00173 
00174     inline                  operator const utf8*() const;
00177 
00178     void                    SetAndBorrow(stringliteral* set);
00187 
00188     inline Status_t         Set(stringliteral* set);
00194 
00195     inline const String_t&  operator =(stringliteral* set);
00203 
00204     Status_t                Set(const utf8* set);
00210 
00211     inline const String_t&  operator =(const utf8* set);
00219 
00220     void                    Set(const String_t& set);
00225 
00226     inline const String_t&  operator =(const String_t& set);
00231 
00232     Status_t                Set(const wchar_t* set);
00239 
00240     inline const String_t&  operator =(const wchar_t* set);
00249 
00250     Status_t                SetLengthLimited( const utf8* set, int num_chars );
00258 
00259     void                    GetLeft( int length_chars, out String_t* left ) const;
00264 
00265     void                    GetRight( int length_chars, out String_t* right ) const;
00270 
00271     String_t                Left(int length_chars) const;
00280 
00281     String_t                Right(int length_chars) const;
00290 
00291     inline bool             Printf( stringliteral* format, ... );
00304 
00305     inline bool             PrintfAppend( stringliteral* format, ... );
00319 
00320     inline bool             VPrintf( stringliteral* format, va_list args );
00334 
00335     inline bool             VPrintfAppend( stringliteral* format, va_list args );
00350 
00351     inline void             PrintByteArray( stringliteral* format,
00352                                             stringliteral* separator,
00353                                             const byte* data,
00354                                             int data_length );
00358 
00359     void                    PrintByteArrayAppend(   stringliteral* format,
00360                                                     stringliteral* separator,
00361                                                     const byte* data,
00362                                                     int data_length );
00367 
00368     inline void             PrintByteArray( stringliteral* format,
00369                                             stringliteral* separator,
00370                                             const Buffer_t& buffer );
00374 
00375     inline void             PrintByteArrayAppend(   stringliteral* format,
00376                                                     stringliteral* separator,
00377                                                     const Buffer_t& buffer );
00382 
00383     void                    SetLineEndings(line_ending_type_t line_ending_type);
00392 
00393     static bool             DoLineEndingsMatch( const utf8* string,
00394                                                 line_ending_type_t line_ending = eLINEENDING_native,
00395                                                 out bool* ended_with_line_ending = NULL );
00401 
00402     inline Status_t         Append(stringliteral* append);
00405 
00406     inline void             operator +=(stringliteral* append);
00412 
00413     Status_t                Append(const utf8* append);
00416 
00417     inline void             operator +=(const utf8* append);
00423 
00424     void                    Append(const String_t& append);
00426 
00427     inline void             operator +=(const String_t& append);
00429 
00430     inline String_t         operator +(stringliteral* append) const;
00439 
00440     inline String_t         operator +(const utf8* append) const;
00449 
00450     inline String_t         operator +(const String_t& append) const;
00455 
00456     inline Status_t         Prepend(stringliteral* prepend);
00460 
00461     Status_t                Prepend(const utf8* prepend);
00465 
00466     void                    Prepend(const String_t& prepend);
00468 
00469     void                    RemoveLeft(int length_chars);
00475 
00476     void                    RemoveRight(int length_chars);
00482 
00483     inline void             operator -=(int length_chars);
00489 
00490     inline String_t         operator -(int length_char) const;
00500 
00501     void                    Remove( const utf8* position_within_string, int bytes_to_remove );
00508 
00509     inline Status_t         ReplaceLeft( int remove_length_chars, stringliteral* replace );
00518 
00519     Status_t                ReplaceLeft( int remove_length_chars, const utf8* replace_with );
00528 
00529     void                    ReplaceLeft( int remove_length_chars, const String_t& replace_with );
00537 
00538     inline Status_t         ReplaceRight( int remove_length_chars, stringliteral* replace );
00547 
00548     Status_t                ReplaceRight( int remove_length_chars, const utf8* replace_with );
00557 
00558     void                    ReplaceRight( int remove_length_chars, const String_t& replace_with );
00566 
00567     void                    RemoveWhitespace( bool start = true, bool end = true );
00569 
00570     inline bool             Equals(stringliteral* compare) const;
00573 
00574     inline bool             operator ==(stringliteral* compare) const;
00577 
00578     inline bool             operator !=(stringliteral* compare) const;
00581 
00582     bool                    Equals(const utf8* compare) const;
00585 
00586     inline bool             operator ==(const utf8* compare) const;
00589 
00590     inline bool             operator !=(const utf8* compare) const;
00593 
00594     bool                    Equals(const String_t& compare) const;
00597 
00598     inline bool             operator ==(const String_t& compare) const;
00601 
00602     inline bool             operator !=(const String_t& compare) const;
00605 
00606     inline bool             EqualsIgnoreCase(stringliteral* compare) const;
00610 
00611     inline bool             EqualsIgnoreCase(const utf8* compare) const;
00615 
00616     bool                    EqualsIgnoreCase(const String_t& compare) const;
00620 
00621     inline bool             LeftEquals(stringliteral* compare) const;
00627 
00628     bool                    LeftEquals(const utf8* compare) const;
00634 
00635     inline bool             LeftEquals(const String_t& compare) const;
00641 
00642     inline bool             RightEquals(stringliteral* compare) const;
00648 
00649     inline bool             RightEquals(const utf8* compare) const;
00655 
00656     inline bool             RightEquals(const String_t& compare) const;
00662 
00663     inline bool             LeftEqualsIgnoreCase(stringliteral* compare) const;
00669 
00670     bool                    LeftEqualsIgnoreCase(const utf8* compare) const;
00676 
00677     inline bool             LeftEqualsIgnoreCase(const String_t& compare) const;
00683 
00684     inline bool             RightEqualsIgnoreCase(stringliteral* compare) const;
00690 
00691     inline bool             RightEqualsIgnoreCase(const utf8* compare) const;
00697 
00698     inline bool             RightEqualsIgnoreCase(const String_t& compare) const;
00704 
00705     inline int              Compare( stringliteral* compare, int char_limit = -1 ) const;
00711 
00712     int                     Compare( const utf8* compare, int char_limit = -1 ) const;
00718 
00719     inline int              Compare( const String_t& compare, int char_limit = -1 ) const;
00725 
00726     inline int              CompareIgnoreCase(  stringliteral* compare,
00727                                                 int char_limit = -1,
00728                                                 bool numeric_sort_numbers = true ) const;
00737 
00738     inline int              CompareIgnoreCase(  const utf8* compare,
00739                                                 int char_limit = -1,
00740                                                 bool numeric_sort_numbers = true ) const;
00749 
00750     inline int              CompareIgnoreCase(  const String_t& compare,
00751                                                 int char_limit = -1,
00752                                                 bool numeric_sort_numbers = true ) const;
00761 
00762     inline bool             operator <(const String_t& compare) const;
00767 
00768     inline bool             operator <=(const String_t& compare) const;
00774 
00775     inline bool             operator >(const String_t& compare) const;
00780 
00781     inline bool             operator >=(const String_t& compare) const;
00787 
00788     static int              CountUTF8Chars(
00789                                     const utf8* string,
00791                                     int stop_at_count = -1,
00798                                     out int* byte_count = NULL,
00803                                     bool stop_at_count_is_byte_limit = false
00806                                     );
00814 
00815     inline int              FindSubstringOffsetChars(   stringliteral* find,
00816                                                         bool case_sensitive = true,
00817                                                         int start_at_offset = 0,
00818                                                         bool front_to_back = true );
00828 
00829     int                     FindSubstringOffsetChars(   const utf8* find,
00830                                                         bool case_sensitive = true,
00831                                                         int start_at_offset = 0,
00832                                                         bool front_to_back = true );
00842 
00843     inline int              FindSubstringOffsetChars(   const String_t& find,
00844                                                         bool case_sensitive = true,
00845                                                         int start_at_offset = 0,
00846                                                         bool front_to_back = true );
00856 
00857     inline int              FindSubstringOffsetBytes(   stringliteral* find,
00858                                                         bool case_sensitive = true,
00859                                                         int start_at_offset = 0,
00860                                                         bool front_to_back = true );
00870 
00871     int                     FindSubstringOffsetBytes(   const utf8* find,
00872                                                         bool case_sensitive = true,
00873                                                         int start_at_offset = 0,
00874                                                         bool front_to_back = true );
00884 
00885     inline int              FindSubstringOffsetBytes(   const String_t& find,
00886                                                         bool case_sensitive = true,
00887                                                         int start_at_offset = 0,
00888                                                         bool front_to_back = true );
00898 
00899     //----------------------------------------------------------------------------------------------
00900     private:
00901     //----------------------------------------------------------------------------------------------
00902     static int              CountWChars( const wchar_t* string, int stop_at_count );
00903                                 // Counts the wchar_t's in a wchar_t* string.  If stop_at_count is
00904                                 // -1, all characters are counted up to the terminating null
00905                                 // character.  The terminating null character is not included in the
00906                                 // count.  If stop_at_count is not -1, the count will stop at and
00907                                 // return that character count.  If wchar_t is defined to be more
00908                                 // than 21 bits in size, CountWChars will return -1 if a character
00909                                 // is found which is out of bounds.
00910     bool                    VPrintfUtil( stringliteral* format, va_list args, bool append );
00911                                 // Utility function to handle the common implementation of the
00912                                 // variety (va_list and append) of Printf variants.
00913     void                    VPrintfIntegerUtil( uint64 value,
00914                                                 uint flags,     // STVP_FLAG_* in String.cpp
00915                                                 uint integer_base,
00916                                                 int minimum_field_width,
00917                                                 uint precision_value );
00918                                 // Utility function used by VPrintfUtil to handle rendering an
00919                                 // integer.
00920     void                    VPrintfStatusUtil(  const Status_t& status,
00921                                                 out Buffer_t* status_string_buffer );
00922                                 // Utility function used by VPrintfUtil to handle rendering a
00923                                 // Status_t.
00924     bool                    RightEqualsUtil(    const utf8* compare,
00925                                                 int right_char_count,
00926                                                 bool ignore_case ) const;
00927                                 // Utility function used by the various right comparison functions.
00928     static int              CompareUTF8IgnoreCase(  const utf8* self,
00929                                                     const utf8* compare,
00930                                                     bool stop_at_compare_end,
00931                                                     int char_limit,
00932                                                     bool numeric_sort_numbers );
00933                                 // Utility function used by the various case-insensitive comparison
00934                                 // functions.  If char_limit is not -1, the comparison stops and
00935                                 // returns 0 after the specified number of characters.
00936 
00937     //----------------------------------------------------------------------------------------------
00938     private:
00939     //----------------------------------------------------------------------------------------------
00940     int                     m_length_bytes;
00941     int                     m_length_chars;
00942     bool                    m_const;
00943     static const utf8       ms_empty[1];
00944 };
00945 
00946 
00947 //==================================================================================================
00948 class UT_EXPORT RefCountedString_t
00949 //==================================================================================================
00950 : public String_t
00958 {
00959     //----------------------------------------------------------------------------------------------
00960     public:
00961     //----------------------------------------------------------------------------------------------
00962     inline      RefCountedString_t(const utf8* string);
00967 
00968     inline      RefCountedString_t(stringliteral* string);
00977 
00978     inline      RefCountedString_t(const String_t& copy);
00983 
00984     inline void AddReference();
00989 
00990     inline void RemoveReference();
00996 
00997     //----------------------------------------------------------------------------------------------
00998     private:
00999     //----------------------------------------------------------------------------------------------
01000     int32       m_ref_count;
01001 };
01002 
01003 
01004 
01005 
01006 //==================================================================================================
01007 //==================================================================================================
01008 //===
01009 //=== Inline function implementations: class String_t
01010 //===
01011 //==================================================================================================
01012 //==================================================================================================
01013 inline
01014 String_t::String_t()
01015 : Buffer_t( const_cast<byte*>( reinterpret_cast<const byte*>(&ms_empty[0]) ), 1 )
01016 {
01017     m_length_bytes = 0;
01018     m_length_chars = 0;
01019     m_const = true;
01020 }
01021 
01022 
01023 inline
01024 String_t::String_t( byte* buffer, int buffer_size )
01025 : Buffer_t( buffer, buffer_size )
01026 {
01027     assert(buffer_size > 0);
01028     m_length_bytes = 0;
01029     m_length_chars = 0;
01030     Buffer(1)[0] = 0;
01031     m_const = false;
01032 }
01033 
01034 
01035 inline
01036 String_t::String_t(const String_t& copy)
01037 {
01038     m_length_bytes = copy.m_length_bytes;
01039     m_length_chars = copy.m_length_chars;
01040     m_const = false;
01041 
01042     utf8* dest = reinterpret_cast<utf8*>( Buffer(m_length_bytes+1) );
01043     memcpy( dest, copy.ReadOnlyBuffer(), m_length_bytes+1 );
01044 }
01045 
01046 
01047 inline
01048 String_t::String_t(const wchar_t* string)
01049 {
01050     m_const = false;
01051     Set(string);
01052 }
01053 
01054 
01055 inline int
01056 String_t::LengthBytes() const
01057 {
01058     return m_length_bytes;
01059 }
01060 
01061 
01062 inline int
01063 String_t::LengthChars() const
01064 {
01065     return m_length_chars;
01066 }
01067 
01068 
01069 inline bool
01070 String_t::IsEmpty() const
01071 {
01072     return (m_length_bytes == 0);
01073 }
01074 
01075 
01076 inline void
01077 String_t::MakeEmpty()
01078 {
01079     if(m_length_bytes)
01080         Set(ms_empty);
01081 }
01082 
01083 
01084 inline bool
01085 String_t::IsASCII() const
01086 {
01087     return (m_length_bytes == m_length_chars);
01088 }
01089 
01090 
01091 inline Status_t
01092 String_t::FromEscapedASCII( const ascii7* ascii,
01093                             ascii7 stop_at,
01094                             int length )
01095 {
01096     MakeEmpty();
01097     return AppendFromEscapedASCII( ascii, stop_at, length );
01098 }
01099 
01100 
01101 inline
01102 String_t::operator const utf8*() const
01103 {
01104     return reinterpret_cast<const utf8*>( ReadOnlyBuffer() );
01105 }
01106 
01107 
01108 inline const utf8*
01109 String_t::UTF8() const
01110 {
01111     return reinterpret_cast<const utf8*>( ReadOnlyBuffer() );
01112 }
01113 
01114 
01115 inline stringliteral*
01116 String_t::ConstChars() const
01117 {
01118     return reinterpret_cast<stringliteral*>( ReadOnlyBuffer() );
01119 }
01120 
01121 
01122 inline Status_t
01123 String_t::Set(stringliteral* set)
01124 {
01125     return Set( reinterpret_cast<const utf8*>(set) );
01126 }
01127 
01128 
01129 inline const String_t&
01130 String_t::operator =(stringliteral* set)
01131 {
01132     #if !DEBUG
01133         Set( reinterpret_cast<const utf8*>(set) );
01134     #else
01135         assert( Set( reinterpret_cast<const utf8*>(set) ).Success() );
01136     #endif
01137     return *this;
01138 }
01139 
01140 
01141 inline const String_t&
01142 String_t::operator =(const utf8* set)
01143 {
01144     #if !DEBUG
01145         Set(set);
01146     #else
01147         assert( Set(set).Success() );
01148     #endif
01149     return *this;
01150 }
01151 
01152 
01153 inline const String_t&
01154 String_t::operator =(const String_t& set)
01155 {
01156     Set(set);
01157     return *this;
01158 }
01159 
01160 
01161 inline const String_t&
01162 String_t::operator =(const wchar_t* set)
01163 {
01164     Set(set);
01165     return *this;
01166 }
01167 
01168 
01169 inline bool
01170 String_t::Printf( stringliteral* format, ... )
01171 {
01172     va_list args;
01173     va_start( args, format );
01174 
01175     return VPrintfUtil( format, args, false );
01176 }
01177 
01178 
01179 
01180 inline bool
01181 String_t::PrintfAppend( stringliteral* format, ... )
01182 {
01183     va_list args;
01184     va_start( args, format );
01185 
01186     return VPrintfUtil( format, args, true );
01187 }
01188 
01189 
01190 inline bool
01191 String_t::VPrintf( stringliteral* format, va_list args )
01192 {
01193     return VPrintfUtil( format, args, false );
01194 }
01195 
01196 
01197 inline bool
01198 String_t::VPrintfAppend( stringliteral* format, va_list args )
01199 {
01200     return VPrintfUtil( format, args, true );
01201 }
01202 
01203 
01204 inline void
01205 String_t::PrintByteArray(   stringliteral* format,
01206                             stringliteral* separator,
01207                             const byte* data,
01208                             int data_length )
01209 {
01210     MakeEmpty();
01211     PrintByteArrayAppend( format, separator, data, data_length );
01212 }
01213 
01214 
01215 inline void
01216 String_t::PrintByteArray(   stringliteral* format,
01217                             stringliteral* separator,
01218                             const Buffer_t& buffer )
01219 {
01220     MakeEmpty();
01221     PrintByteArrayAppend( format, separator, buffer.ReadOnlyBuffer(), buffer.ValidSize() );
01222 }
01223 
01224 
01225 inline void
01226 String_t::PrintByteArrayAppend( stringliteral* format,
01227                                 stringliteral* separator,
01228                                 const Buffer_t& buffer )
01229 {
01230     PrintByteArrayAppend( format, separator, buffer.ReadOnlyBuffer(), buffer.ValidSize() );
01231 }
01232 
01233 
01234 inline Status_t
01235 String_t::Append(stringliteral* append)
01236 {
01237     return Append( reinterpret_cast<const utf8*>(append) );
01238 }
01239 
01240 
01241 inline void
01242 String_t::operator +=(stringliteral* append)
01243 {
01244     #if !DEBUG
01245         Append( reinterpret_cast<const utf8*>(append) );
01246     #else
01247         assert( Append( reinterpret_cast<const utf8*>(append) ).Success() );
01248     #endif
01249 }
01250 
01251 
01252 inline void
01253 String_t::operator +=(const utf8* append)
01254 {
01255     #if !DEBUG
01256         Append(append);
01257     #else
01258         assert( Append(append).Success() );
01259     #endif
01260 }
01261 
01262 
01263 inline void
01264 String_t::operator +=(const String_t& append)
01265 {
01266     Append(append);
01267 }
01268 
01269 
01270 inline String_t
01271 String_t::operator +(stringliteral* append) const
01272 {
01273     String_t local_copy(*this);
01274     #if !DEBUG
01275         local_copy.Append(append);
01276     #else
01277         assert( local_copy.Append( reinterpret_cast<const utf8*>(append) ).Success() );
01278     #endif
01279     return local_copy;
01280 }
01281 
01282 
01283 inline String_t
01284 String_t::operator +(const utf8* append) const
01285 {
01286     String_t local_copy(*this);
01287     #if !DEBUG
01288         local_copy.Append(append);
01289     #else
01290         assert( local_copy.Append(append).Success() );
01291     #endif
01292     return local_copy;
01293 }
01294 
01295 
01296 inline String_t
01297 String_t::operator +(const String_t& append) const
01298 {
01299     String_t local_copy(*this);
01300     local_copy.Append(append);
01301     return local_copy;
01302 }
01303 
01304 
01305 inline Status_t
01306 String_t::Prepend(stringliteral* prepend)
01307 {
01308     return Prepend( reinterpret_cast<const utf8*>(prepend) );
01309 }
01310 
01311 
01312 inline void
01313 String_t::operator -=(int length_chars)
01314 {
01315     RemoveRight(length_chars);
01316 }
01317 
01318 
01319 inline String_t
01320 String_t::operator -(int length_char) const
01321 {
01322     String_t local_copy(*this);
01323     local_copy -= length_char;
01324     return local_copy;
01325 }
01326 
01327 
01328 inline Status_t
01329 String_t::ReplaceLeft( int remove_length_chars, stringliteral* replace )
01330 {
01331     return ReplaceLeft( remove_length_chars, reinterpret_cast<const utf8*>(replace) );
01332 }
01333 
01334 
01335 inline Status_t
01336 String_t::ReplaceRight( int remove_length_chars, stringliteral* replace )
01337 {
01338     return ReplaceRight( remove_length_chars, reinterpret_cast<const utf8*>(replace) );
01339 }
01340 
01341 
01342 inline bool
01343 String_t::Equals(stringliteral* compare) const
01344 {
01345     return Equals( reinterpret_cast<const utf8*>(compare) );
01346 }
01347 
01348 
01349 inline bool
01350 String_t::operator ==(stringliteral* compare) const
01351 {
01352     return Equals( reinterpret_cast<const utf8*>(compare) );
01353 }
01354 
01355 
01356 inline bool
01357 String_t::operator !=(stringliteral* compare) const
01358 {
01359     return !Equals( reinterpret_cast<const utf8*>(compare) );
01360 }
01361 
01362 
01363 inline bool
01364 String_t::operator ==(const utf8* compare) const
01365 {
01366     return Equals(compare);
01367 }
01368 
01369 
01370 inline bool
01371 String_t::operator !=(const utf8* compare) const
01372 {
01373     return !Equals(compare);
01374 }
01375 
01376 
01377 inline bool
01378 String_t::operator ==(const String_t& compare) const
01379 {
01380     return Equals(compare);
01381 }
01382 
01383 
01384 inline bool
01385 String_t::operator !=(const String_t& compare) const
01386 {
01387     return !Equals(compare);
01388 }
01389 
01390 
01391 inline bool
01392 String_t::EqualsIgnoreCase(stringliteral* compare) const
01393 {
01394     return (CompareUTF8IgnoreCase(  UTF8(),
01395                                     reinterpret_cast<const utf8*>(compare),
01396                                     false,
01397                                     -1,
01398                                     false ) == 0);
01399 }
01400 
01401 
01402 inline bool
01403 String_t::EqualsIgnoreCase(const utf8* compare) const
01404 {
01405     return (CompareUTF8IgnoreCase( UTF8(), compare, false, -1, false ) == 0);
01406 }
01407 
01408 
01409 inline bool
01410 String_t::LeftEquals(stringliteral* compare) const
01411 {
01412     return LeftEquals( reinterpret_cast<const utf8*>(compare) );
01413 }
01414 
01415 
01416 inline bool
01417 String_t::LeftEquals(const String_t& compare) const
01418 {
01419     return LeftEquals( compare.UTF8() );
01420 }
01421 
01422 
01423 inline bool
01424 String_t::RightEquals(stringliteral* compare) const
01425 {
01426     return RightEqualsUtil( reinterpret_cast<const utf8*>(compare),
01427                             CountUTF8Chars( reinterpret_cast<const utf8*>(compare) ),
01428                             false );
01429 }
01430 
01431 
01432 inline bool
01433 String_t::RightEquals(const utf8* compare) const
01434 {
01435     return RightEqualsUtil( compare, CountUTF8Chars(compare), false );
01436 }
01437 
01438 
01439 inline bool
01440 String_t::RightEquals(const String_t& compare) const
01441 {
01442     return RightEqualsUtil( compare.UTF8(), compare.LengthChars(), false );
01443 }
01444 
01445 
01446 inline bool
01447 String_t::LeftEqualsIgnoreCase(stringliteral* compare) const
01448 {
01449     return (CompareUTF8IgnoreCase(  UTF8(),
01450                                     reinterpret_cast<const utf8*>(compare),
01451                                     true,
01452                                     -1,
01453                                     false ) == 0);
01454 }
01455 
01456 
01457 inline bool
01458 String_t::LeftEqualsIgnoreCase(const String_t& compare) const
01459 {
01460     return (CompareUTF8IgnoreCase( UTF8(), compare.UTF8(), true, -1, false ) == 0);
01461 }
01462 
01463 
01464 inline bool
01465 String_t::RightEqualsIgnoreCase(stringliteral* compare) const
01466 {
01467     return RightEqualsUtil( reinterpret_cast<const utf8*>(compare),
01468                             CountUTF8Chars( reinterpret_cast<const utf8*>(compare) ),
01469                             true );
01470 }
01471 
01472 
01473 inline bool
01474 String_t::RightEqualsIgnoreCase(const utf8* compare) const
01475 {
01476     return RightEqualsUtil( compare, CountUTF8Chars(compare), true );
01477 }
01478 
01479 
01480 inline bool
01481 String_t::RightEqualsIgnoreCase(const String_t& compare) const
01482 {
01483     return RightEqualsUtil( compare.UTF8(), compare.LengthChars(), true );
01484 }
01485 
01486 
01487 inline int
01488 String_t::Compare( stringliteral* compare, int char_limit ) const
01489 {
01490     return Compare( reinterpret_cast<const utf8*>(compare), char_limit );
01491 }
01492 
01493 
01494 inline int
01495 String_t::Compare( const String_t& compare, int char_limit ) const
01496 {
01497     return Compare( compare.UTF8(), char_limit );
01498 }
01499 
01500 
01501 inline int
01502 String_t::CompareIgnoreCase(    stringliteral* compare,
01503                                 int char_limit,
01504                                 bool numeric_sort_numbers  ) const
01505 {
01506     return CompareUTF8IgnoreCase(   UTF8(),
01507                                     reinterpret_cast<const utf8*>(compare),
01508                                     false,
01509                                     char_limit,
01510                                     numeric_sort_numbers );
01511 }
01512 
01513 
01514 inline int
01515 String_t::CompareIgnoreCase(    const utf8* compare,
01516                                 int char_limit,
01517                                 bool numeric_sort_numbers ) const
01518 {
01519     return CompareUTF8IgnoreCase( UTF8(), compare, false, char_limit, numeric_sort_numbers );
01520 }
01521 
01522 
01523 inline int
01524 String_t::CompareIgnoreCase(    const String_t& compare,
01525                                 int char_limit,
01526                                 bool numeric_sort_numbers ) const
01527 {
01528     return CompareUTF8IgnoreCase( UTF8(), compare.UTF8(), false, char_limit, numeric_sort_numbers );
01529 }
01530 
01531 
01532 inline bool
01533 String_t::operator <(const String_t& compare) const
01534 {
01535     return (CompareUTF8IgnoreCase( UTF8(), compare.UTF8(), false, -1, true ) < 0);
01536 }
01537 
01538 
01539 inline bool
01540 String_t::operator <=(const String_t& compare) const
01541 {
01542     return (CompareUTF8IgnoreCase( UTF8(), compare.UTF8(), false, -1, true ) <= 0);
01543 }
01544 
01545 
01546 inline bool
01547 String_t::operator >(const String_t& compare) const
01548 {
01549     return (CompareUTF8IgnoreCase( UTF8(), compare.UTF8(), false, -1, true ) > 0);
01550 }
01551 
01552 
01553 inline bool
01554 String_t::operator >=(const String_t& compare) const
01555 {
01556     return (CompareUTF8IgnoreCase( UTF8(), compare.UTF8(), false, -1, true ) >= 0);
01557 }
01558 
01559 
01560 inline int
01561 String_t::FindSubstringOffsetChars( stringliteral* find,
01562                                     bool case_sensitive,
01563                                     int start_at_offset,
01564                                     bool front_to_back )
01565 {
01566     return FindSubstringOffsetChars(    reinterpret_cast<const utf8*>(find),
01567                                         case_sensitive,
01568                                         start_at_offset,
01569                                         front_to_back );
01570 }
01571 
01572 
01573 inline int
01574 String_t::FindSubstringOffsetChars( const String_t& find,
01575                                     bool case_sensitive,
01576                                     int start_at_offset,
01577                                     bool front_to_back )
01578 {
01579     return FindSubstringOffsetChars( find.UTF8(), case_sensitive, start_at_offset, front_to_back );
01580 }
01581 
01582 
01583 inline int
01584 String_t::FindSubstringOffsetBytes( stringliteral* find,
01585                                     bool case_sensitive,
01586                                     int start_at_offset,
01587                                     bool front_to_back )
01588 {
01589     return FindSubstringOffsetBytes(    reinterpret_cast<const utf8*>(find),
01590                                         case_sensitive,
01591                                         start_at_offset,
01592                                         front_to_back );
01593 }
01594 
01595 
01596 inline int
01597 String_t::FindSubstringOffsetBytes( const String_t& find,
01598                                     bool case_sensitive,
01599                                     int start_at_offset,
01600                                     bool front_to_back )
01601 {
01602     return FindSubstringOffsetBytes( find.UTF8(), case_sensitive, start_at_offset, front_to_back );
01603 }
01604 
01605 
01606 
01607 
01608 //==================================================================================================
01609 //==================================================================================================
01610 //===
01611 //=== Inline function implementations: class RefCountedString_t
01612 //===
01613 //==================================================================================================
01614 //==================================================================================================
01615 inline
01616 RefCountedString_t::RefCountedString_t(const utf8* string)
01617 : String_t(string)
01618 {
01619     m_ref_count = 1;
01620 }
01621 
01622 
01623 inline
01624 RefCountedString_t::RefCountedString_t(stringliteral* string)
01625 : String_t(string)
01626 {
01627     m_ref_count = 1;
01628 }
01629 
01630 
01631 inline
01632 RefCountedString_t::RefCountedString_t(const String_t& copy)
01633 : String_t(copy)
01634 {
01635     m_ref_count = 1;
01636 }
01637 
01638 
01639 inline void
01640 RefCountedString_t::AddReference()
01641 {
01642     atomic_add( &m_ref_count, 1 );
01643 }
01644 
01645 
01646 inline void
01647 RefCountedString_t::RemoveReference()
01648 {
01649     if(atomic_add( &m_ref_count, -1 ) == 0)
01650         delete this;
01651 }
01652 
01653 
01654 #endif // _UT_STRING_H_

Generated on Tue Dec 14 22:35:05 2010 for UT library by  doxygen 1.6.1