basestr.h

Go to the documentation of this file.
00001 // $Id: basestr.h 1283 2006-06-09 10:45:34Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 /*******************************************************************************************
00099     
00100  ****************************************************************************************/ 
00101 
00102 /*******************************************************************************************
00103 >   class StringBase : public CCObject
00104 
00105     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00106     
00107     Created:    22nd April 1993; ammended 6th August 1993
00108     
00109     Purpose:    General-purpose string class.  Overloads the C++ arithmetic operator +=
00110                 which for strings perform concatenation, together with the
00111                 comparison operators <, >,  !=, ==, etc, which will perform
00112                 case-sensitive comparisons  according to the local custom.
00113     
00114                 Other functions provided include Left(), Mid(), and Right(), for
00115                 decomposing strings, plus Sub(), which returns the position of a string
00116                 within another string.  A new sprintf()-type member function has been
00117                 provided, MakeMsg(), which performs internationally portable argument
00118                 substitution according to a formatting string read from the application's
00119                 resources.
00120                 
00121                 The primary use of this class is to serve as a base for the derivation
00122                 of fixed length StringBases.  Derived String_N's, unlike their StringBase
00123                 base classes, do not allocate a buffer for text on the heap, but within
00124                 their class instance.
00125                 
00126                 Note that these kind of base-class strings CAN be of an arbitrary length,
00127                 but the user must call Alloc() to change the length - all member functions
00128                 assume that the StringBase is long enough to cope with the operation of the
00129                 function.  Attempts to access past the end of the string will be trapped
00130                 with ASSERTions.
00131     
00132     Errors:     Most functions validate their parameters, eg. asking Left() to extract
00133                 the leftmost 0 characters of a string will cause the function to return
00134                 a 0 string.
00135     
00136     Notes:      As of 4th May 1993, all serialisation / archive support has been commented
00137                 out, as this does not work and nobody seems to know why.  This will be
00138                 rectified when serialisation is needed (some time in the future).
00139 ********************************************************************************************/               
00140 
00141 
00142 #ifndef INC_STRINGBASE
00143 #define INC_STRINGBASE
00144 
00145 #include "ccobject.h"
00146 #include "errors.h"
00147 // #include <stdarg.h>
00148 
00149 #ifdef _UNICODE
00150 #define FIX_LEN_BUFM(x) ((x)+1)
00151 #else
00152 #define FIX_LEN_BUFM(x) (((x)+1)*2)
00153 #endif
00154 
00155 #define DEFINE_BUFSIZE(x) const INT32 String_ ## x::FIX_LEN_BUFSIZE = FIX_LEN_BUFM(x);
00156 
00157 // Maximum number of characters in a string resource.
00158 const size_t MAX_STRING_RES_LENGTH = 255;
00159 const INT32 str_MAXEXCEPTIONS = 30;
00160 
00161 class CCAPI StringBase : public CCObject
00162 {
00163     // Error class needs direct access
00164     friend class Error;
00165     
00166 public:
00167     // Constructors & destructor
00168     StringBase();
00169     virtual ~StringBase();
00170     
00171     // Utility functions
00172     virtual BOOL Alloc(INT32 size);             // get heap space for string
00173     BOOL Load(UINT32 resID, UINT32 inst = 0);       // Load StringBase from resources
00174     
00175     // Attributes.
00176     INT32 Length() const;                           // returns no. of characters
00177     INT32 MaxLength() const;                        // returns maximum allowed length
00178     BOOL IsEmpty() const;                       // returns TRUE if string is zero-length
00179     
00180     INT32 NextIndex(INT32 index) const;             // given a char index, return the next (-1 if none)
00181     INT32 PrevIndex(INT32 index) const;             // given a char index, return the prev (-1 if none)
00182     BOOL IsLegal(INT32 index) const;                // is the char index legal?
00183     BOOL IsIllegal(INT32 index) const;          // is the char index illegal?
00184     
00185     static BOOL IsAlpha(TCHAR c);               // tests a Unicode character.
00186     static BOOL IsAlphaNumeric(TCHAR c);
00187     static BOOL IsNumeric(TCHAR c);
00188     static BOOL IsLower(TCHAR c);
00189     static BOOL IsUpper(TCHAR c);
00190     static BOOL IsSpace(TCHAR c);
00191     
00192     // Operations.
00193     StringBase& Empty();                        // make this a 0 string
00194     StringBase& toUpper();                      // convert string to upper case
00195     StringBase& toLower();                      // convert to lower case
00196     StringBase& toTitle();                      // Graham 30/10/97: Converts first character to upper, all others to lower
00197 
00198     INT32 __cdecl MakeMsg(UINT32 resID ...);        // Like sprintf(...)
00199     INT32 __cdecl _MakeMsg(const TCHAR* fmt ...);   // Like the above without resources
00200 
00201     
00202     // Casting operators
00203     operator TCHAR*();                          // convert to a standard C (Unicode) string
00204     operator const TCHAR*() const;              // same, but for constant instances
00205 
00206     operator wxString();
00207     operator const wxString() const;
00208 
00209     // Assignment & concatenation operators
00210     StringBase& operator+=(const StringBase& rhs);
00211     StringBase& operator+=(const TCHAR* s);
00212     StringBase& operator+=(const TCHAR ch);
00213     StringBase& operator=(const StringBase& other);     
00214     StringBase& operator=(const TCHAR* s);          
00215     StringBase& operator=(const TCHAR ch);
00216 
00217     // non memory toasting += support function
00218     static TCHAR* SafeCat(TCHAR* pstr1, const TCHAR* pcstr2, UINT32 nchMax);
00219 
00220     // Functions to turn on exceptions in 'some' string functions
00221     static BOOL EnableExceptionHandler(BOOL PushNewHandler=TRUE);
00222     static BOOL DisableExceptionHandler(BOOL PopHandler=TRUE);
00223     static BOOL WillThrowException();
00224 
00225     // Character/substring manipulation functions
00226     const StringBase& Left(StringBase* out, UINT32 count) const;
00227     const StringBase& Mid(StringBase* out, UINT32 first, UINT32 count) const;
00228     const StringBase& Right(StringBase* out, UINT32 count) const;
00229 
00230     void Split(StringBase* pstrStart, StringBase* pstrEnd, INT32 iSplit, BOOL fIncludeSplitChar);
00231     INT32 Sub(const StringBase& mask, UINT32 from = 0, TCHAR fuzz = 0) const;
00232     INT32 SubWithoutCase(const StringBase& strToFind) const;
00233     void Remove(INT32 Position, INT32 Number);
00234     void Insert( const StringBase &InsertString, INT32 Position);
00235     void SwapChar(const TCHAR schar, const TCHAR rchar);
00236     INT32 CountChar(const TCHAR tchar);
00237     TCHAR operator[](const INT32 Index);
00238     const WCHAR CharAt(const INT32 Index) const;
00239     
00240     INT32 SkipComma(INT32 pos=0) const;
00241     INT32 SkipSpace(INT32 pos=0) const;
00242     INT32 FindNextChar(INT32 position=0) const;
00243     INT32 FindNextChar(TCHAR c, INT32 position=0) const;
00244     INT32 ConvertToInteger(INT32& position) const;
00245 
00246     //Graham 6/5/97
00247     INT32 ReverseFind(TCHAR cToFind) const;
00248 
00249 #if !defined(EXCLUDE_FROM_XARLIB)
00250     // Special internationalisation stuff...
00251     virtual void MakePercent(INT32 Value);
00252     virtual void MakePercent(double Value);
00253     virtual void MakePercent(TCHAR *Value);
00254     virtual void FixFormat();
00255 #endif
00256 
00257     // Comparison operators.
00258     bool IsIdentical(const TCHAR *other) const;
00259     bool IsIdentical(const StringBase &other) const;
00260         // Fast way of determining if strings are exactly equal
00261 
00262     INT32 CompareTo(const TCHAR *other, BOOL CaseSensitive = TRUE) const;
00263     INT32 CompareTo(const StringBase &other, BOOL CaseSensitive = TRUE) const;
00264         // Slower comparison - returns the locale-defined relative ordering of the 2 strings
00265 
00266     friend bool operator==(const StringBase& x, const TCHAR* y);
00267     friend bool operator==(const StringBase& x, const StringBase& y);
00268     friend bool operator<(const StringBase& x, const TCHAR* y);     
00269     friend bool operator<(const StringBase& x, const StringBase& y);
00270     friend bool operator>(const StringBase& x, const TCHAR* y);
00271     friend bool operator>(const StringBase& x, const StringBase& y);
00272     friend bool operator!=(const StringBase& x, const TCHAR* y);
00273     friend bool operator!=(const StringBase& x, const StringBase& y);
00274     friend bool operator<=(const StringBase& x, const TCHAR* y);
00275     friend bool operator<=(const StringBase& x, const StringBase& y);
00276     friend bool operator>=(const StringBase& x, const TCHAR* y);
00277     friend bool operator>=(const StringBase& x, const StringBase& y);
00278 
00279     // I/O (non-persistent) stream functions
00280     friend std::istream& operator>>(std::istream& is, StringBase& s);
00281     friend std::ostream& operator<<(std::ostream& os, const StringBase& s);
00282 
00283     // Overridden CCObject functions
00284 #ifdef _DEBUG
00285     virtual void AssertValid() const;           // checks if StringBase is valid
00286 PORTNOTE("other","Removed MFC CDumpContext")
00287 #ifndef EXCLUDE_FROM_XARALX
00288     virtual void Dump(CDumpContext& dc) const;  // dumps to debug terminal
00289 #endif
00290 #endif
00291 
00292 private:
00293     INT32  IllegalIndex() const;            // return an illegal index for this string
00294     static INT32 TCharToNum(TCHAR c);           // convert a digit char to a number (0..9)
00295 
00296     static void ThrowStringException();
00297     static BOOL ThrowExceptionStack[str_MAXEXCEPTIONS];
00298     static INT32 CurrEx;
00299 
00300     INT32 BuildList(const TCHAR*);                // break format string into parts
00301     INT32 CCvsprintf(const TCHAR*, va_list);        // substitute parameters
00302     StringBase(const StringBase& other);        // StringBase x(StringBase ...)
00303 
00304 protected:
00305     // Member data
00306     TCHAR* text;
00307     UINT32 length;
00308 };
00309 
00310 
00311 INT32 CCAPI SmartLoadString(UINT32 modID, UINT32 resID, TCHAR *buf, INT32 size);
00312 
00313 // This is our very own version of the Windows string function camStrncpy(), which
00314 // was mysteriously dropped from the Win32 API.  Using the standard C library function
00315 // strncpy() doesn't give quite the same results, so we must provide our own.
00316 TCHAR* cc_camStrncpy(TCHAR* dest, const TCHAR* src, size_t n);
00317 const TCHAR* cc_lstrstr(const TCHAR* String1, const TCHAR *String2);
00318 //TCHAR* cc_lstristr(LPCTSTR String1, LPCTSTR String2);
00319 TCHAR* cc_lstrchr(TCHAR* Src, TCHAR c);
00320 //TCHAR* cc_lstrichr(TCHAR* String1, TCHAR c);
00321 TCHAR* cc_lstrrchr(TCHAR* Src, TCHAR c);
00322 TCHAR* cc_lstrtok(TCHAR* String1, TCHAR* String2);
00323 INT32 cc_lstrncmp(TCHAR* String1, TCHAR* String2, INT32 Count);
00324 size_t cc_strlenCharacters( const TCHAR* string );
00325 size_t cc_strlenBytes( const TCHAR* string );
00326 
00327 
00328 
00329 /**************************************************************************************
00330 >   StringBase::StringBase()
00331 
00332     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00333     Created:    22nd April 1993
00334     Inputs:     -
00335     Purpose:    Default constructor for a StringBase.  Sets the character buffer to 0
00336                 and the string length to zero.  The user must call Alloc() before
00337                 trying to use the StringBase.
00338     Scope:      Public
00339 ***************************************************************************************/
00340 inline StringBase::StringBase()
00341   : text(0), length(0)
00342 {
00343     // Empty.
00344 }
00345 
00346 
00347     
00348     
00349 /**************************************************************************************
00350 >   StringBase::StringBase(const StringBase&)
00351 
00352     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00353     Created:    22nd April 1993
00354     Inputs:     Another StringBase object.
00355     Purpose:    Copy constructor - this is made private (and unimplemented) as it
00356                 will not work for base class strings, which must call Alloc() before
00357                 they are used.
00358     Scope:      Private
00359 ***************************************************************************************/
00360 inline StringBase::StringBase(const StringBase&)
00361 {
00362     // Empty.
00363 }
00364 
00365 
00366     
00367     
00368 /**************************************************************************************
00369 >   virtual StringBase::~StringBase()
00370 
00371     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00372     Created:    22nd April 1993
00373     Purpose:    Destroys & cleans up a string.
00374 ***************************************************************************************/
00375 inline StringBase::~StringBase()
00376 {
00377     if (text) delete[] text;
00378 }
00379 
00380 
00381 
00382 /**************************************************************************************
00383 >   INT32 StringBase::Length() const
00384 
00385     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00386     Created:    22nd April 1993
00387     Returns:    The number of characters in the string, excluding any terminating 0.
00388     Purpose:    Calculates the length of the string.
00389 ***************************************************************************************/
00390 inline INT32 StringBase::Length() const
00391 {
00392     ERROR3IF(!text, "Attempt to find the LENGTH of an unALLOCated String");
00393     return (text) ? camStrlen( text ) : 0;
00394 }
00395 
00396     
00397     
00398 /**************************************************************************************
00399 >   INT32 StringBase::MaxLength() const
00400 
00401     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00402     Created:    25th August 1993
00403     Returns:    The maximum number of characters the string can contain.
00404     Purpose:    Calculates the longest allowed string that can be stored in this.
00405 ***************************************************************************************/
00406 inline INT32 StringBase::MaxLength() const
00407 {
00408 #ifdef _UNICODE
00409     return length - 1;
00410 #else
00411     return (length / 2) - 1;        // MBCS - two chars per character
00412 #endif
00413 }
00414 
00415     
00416     
00417 /**************************************************************************************
00418 >   BOOL StringBase::IsEmpty() const
00419 
00420     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00421     Created:    25th August 1993
00422     Returns:    TRUE if the string has no length.
00423     Purpose:    Tests for the 0 string.
00424 ***************************************************************************************/
00425 inline BOOL StringBase::IsEmpty() const
00426 {
00427     return text == 0 || *text == 0;
00428 }
00429 
00430 
00431 
00432 /**************************************************************************************
00433 
00434 >   BOOL StringBase::IsIdentical(const StringBase &other) const
00435 
00436     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00437     Created:    23/4/96
00438 
00439     Inputs:     other - A string against which this one will be compared
00440 
00441     Returns:    TRUE if the strings are identical
00442                 FALSE if the strings are different in any way
00443 
00444     Purpose:    Compare this StringBase object to another string.
00445 
00446     Errors:     If either of the strings is 0, an ESNURE failure is generated
00447 
00448     Notes:      We define different versions of the function for UNICODE builds,
00449                 as camStrcmp is very slow compared to vanilla strcmp.
00450 
00451                 Note also that this is a very fast comparison compared to CompareTo.
00452                 It should be used in preference where relative ordering of strings
00453                 does not need to be determined.
00454 
00455     SeeAlso:    StringBase::CompareTo
00456 
00457 **************************************************************************************/
00458 
00459 inline bool StringBase::IsIdentical(const StringBase &other) const
00460 {
00461     ERROR3IF(text == 0 || other.text == 0, "StringBase::IsIdentical: not ALLOCed");
00462     return wxStrcmp(text, other.text) == 0;
00463 }
00464 
00465 
00466 
00467 /**************************************************************************************
00468 
00469 >   INT32 StringBase::IsIdentical(const TCHAR *other) const
00470 
00471     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00472     Created:    23/4/96
00473 
00474     Inputs:     other - A string against which this one will be compared
00475 
00476     Returns:    TRUE if the strings are identical
00477                 FALSE if the strings are different in any way
00478 
00479     Purpose:    Compare this StringBase object to another string.
00480 
00481     Errors:     If either of the strings is 0, an ESNURE failure is generated
00482 
00483     Notes:      We define different versions of the function for UNICODE builds,
00484                 as camStrcmp is very slow compared to vanilla strcmp.
00485 
00486                 Note also that this is a very fast comparison compared to CompareTo.
00487                 It should be used in preference where relative ordering of strings
00488                 does not need to be determined.
00489 
00490     SeeAlso:    StringBase::CompareTo
00491 
00492 **************************************************************************************/
00493 
00494 inline bool StringBase::IsIdentical(const TCHAR* other) const
00495 {
00496     ERROR3IF(text == 0 || other == 0, "StringBase::IsIdentical: null params");
00497     return wxStrcmp( text, other ) == 0;
00498 }
00499 
00500 
00501 
00502 /**************************************************************************************
00503 
00504 >   inline INT32 StringBase::NextIndex(INT32 index) const
00505 
00506     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00507     Created:    29/07/96
00508     Inputs:     index = the current character index
00509     Returns:    the next characater index after 'index'
00510                 -1 if there is no next index, OR an exception is thrown
00511     Purpose:    Find the next character index
00512     Notes:      If string exceptions are enabled, an exception will be thrown if the
00513                 index goes out of range.
00514 
00515 ***************************************************************************************/
00516 
00517 inline INT32 StringBase::NextIndex(INT32 index) const
00518 {
00519     INT32 i = index + 1;
00520     if (IsLegal(i)) return i;
00521     TRACEUSER( "Mike", wxT("String index overflow in StringBase::NextIndex()") );
00522     return IllegalIndex();
00523 }
00524 
00525 
00526 
00527 /**************************************************************************************
00528 
00529 >   inline INT32 StringBase::PrevIndex(INT32 index) const
00530 
00531     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00532     Created:    29/07/96
00533     Inputs:     index = the current character index
00534     Returns:    the previous characater index before 'index'
00535                 -1 if there is no previous index, OR an exception is thrown
00536     Purpose:    Find the previous character index
00537     Notes:      If string exceptions are enabled, an exception will be thrown if the
00538                 index goes out of range.
00539 
00540 ***************************************************************************************/
00541 
00542 inline INT32 StringBase::PrevIndex(INT32 index) const
00543 {
00544     INT32 i = index-1;
00545     if (IsLegal(i)) return i;
00546 
00547     TRACEUSER( "Mike", wxT("String index underflow in StringBase::PrevIndex()") );
00548     return IllegalIndex();
00549 }
00550 
00551 
00552 
00553 /**************************************************************************************
00554 
00555 >   inline INT32 StringBase::IllegalIndex() const
00556 
00557     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00558     Created:    29/07/96
00559     Inputs:     -
00560     Returns:    An illegal index ie -1 if exceptions are disabled, otherwise
00561                 an exception is thrown
00562     Purpose:    Generate an illegal index
00563     Notes:      ** Can potentially throw a user exception **
00564 
00565 ***************************************************************************************/
00566 
00567 inline INT32 StringBase::IllegalIndex() const
00568 {
00569     StringBase::ThrowStringException();
00570     return -1;
00571 }
00572 
00573 
00574 
00575 /**************************************************************************************
00576 
00577 >   inline BOOL StringBase::IsIllegal(INT32 index) const
00578 
00579     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00580     Created:    29/07/96
00581     Inputs:     index, a character index in this string
00582     Returns:    TRUE if index is illegal 
00583                 FALSE if not
00584     Purpose:    Check index for its legality
00585 
00586 ***************************************************************************************/
00587 
00588 inline BOOL StringBase::IsIllegal(INT32 index) const
00589 {
00590     return ((index<0) || index>(Length()));
00591 }
00592 
00593 
00594 
00595 /**************************************************************************************
00596 
00597 >   inline BOOL StringBase::IsLegal(INT32 index) const
00598 
00599     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00600     Created:    29/07/96
00601     Inputs:     index, a character index in this string
00602     Returns:    TRUE if index is llegal 
00603                 FALSE if its illegal
00604     Purpose:    Check index for its legality
00605 
00606 ***************************************************************************************/
00607 
00608 inline BOOL StringBase::IsLegal(INT32 index) const
00609 {
00610     return !IsIllegal(index);
00611 }
00612 
00613 
00614 
00615 /**************************************************************************************
00616 >   static BOOL StringBase::IsAlpha(TCHAR c)
00617 
00618     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00619     Created:    10th August 1993
00620     Inputs:     A Unicode character.
00621     Returns:    TRUE if the passed character is an alphabet letter.
00622     Purpose:    Tests if the character is a-z, A-Z (or local equivalent).
00623     
00624 ***************************************************************************************/
00625 inline BOOL StringBase::IsAlpha(TCHAR c)
00626 {
00627     return camIsalpha(c); // IsCharAlpha(c);
00628 }
00629 
00630 
00631 
00632 /**************************************************************************************
00633 >   static BOOL StringBase::IsAlphaNumeric(TCHAR c)
00634 
00635     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00636     Created:    10th August 1993
00637     Inputs:     A Unicode character
00638     Returns:    TRUE if the passed character is an alphabet letter or a digit.
00639     Purpose:    Tests if the character is a-z, A-Z, 0-9, or local equivalent.
00640 ***************************************************************************************/
00641 inline BOOL StringBase::IsAlphaNumeric(TCHAR c)
00642 {
00643     return camIsalnum(c);   //IsCharAlphaNumeric(c);
00644 }
00645 
00646 
00647 
00648 /**************************************************************************************
00649 >   static BOOL StringBase::IsNumeric(TCHAR c)
00650 
00651     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00652     Created:    10th August 1993
00653     Inputs:     A Unicode character
00654     Returns:    TRUE if the passed character is a digit.
00655     Purpose:    Tests if the character is 0-9, or local equivalent.
00656 ***************************************************************************************/
00657 inline BOOL StringBase::IsNumeric(TCHAR c)
00658 {
00659     return camIsalnum(c) && !camIsalpha(c);
00660 }
00661 
00662 
00663 
00664 /**************************************************************************************
00665 >   static BOOL StringBase::IsLower(TCHAR c)
00666 
00667     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00668     Created:    10th August 1993
00669     Inputs:     A Unicode character
00670     Returns:    TRUE if the passed character is a lower-case letter.
00671     Purpose:    Tests if the character is a-z (or local equivalent).
00672 ***************************************************************************************/
00673 inline BOOL StringBase::IsLower(TCHAR c)
00674 {
00675     return camIslower(c); // IsCharLower(c)
00676 }
00677 
00678 
00679 
00680 /**************************************************************************************
00681 >   static BOOL StringBase::IsUpper(TCHAR c)
00682 
00683     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00684     Created:    10th August 1993
00685     Inputs:     A Unicode character
00686     Returns:    TRUE if the passed character is an upper-case letter.
00687     Purpose:    Tests if the character is A-Z, or local equivalent.
00688 ***************************************************************************************/
00689 inline BOOL StringBase::IsUpper(TCHAR c)
00690 {
00691     return camIsupper(c); // IsCharUpper(c)
00692 }
00693 
00694 
00695 
00696 /**************************************************************************************
00697 >   static BOOL StringBase::IsSpace(TCHAR c)
00698 
00699     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00700     Created:    10th August 1993
00701     Inputs:     A Unicode character
00702     Returns:    TRUE if the passed character is whitespace.
00703 ***************************************************************************************/
00704 inline BOOL StringBase::IsSpace(TCHAR c)
00705 {
00706     return camIsspace(c);
00707 }
00708 
00709 
00710 
00711 /**************************************************************************************
00712 >   StringBase& StringBase::Empty()
00713 
00714     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00715     Created:    10th August 1993
00716     Purpose:    Sets a string to the 0 string (zero-terminated but no characters,
00717                 NOT A 0 POINTER!)
00718 ***************************************************************************************/
00719 inline StringBase& StringBase::Empty()
00720 {
00721     ERROR3IF(!text, "Attempt to EMPTY an unALLOCated String");
00722     if (text) *text = 0;
00723     return *this;
00724 }
00725     
00726     
00727 
00728 /**************************************************************************************
00729 >   StringBase& StringBase::toUpper()
00730 
00731     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00732     Created:    22nd April 1993
00733     Purpose:    Converts all lower-case letters in the string to upper-case.
00734 ***************************************************************************************/
00735 inline StringBase& StringBase::toUpper()
00736 {
00737     ERROR3IF(!text, "Call to TOUPPER for an unALLOCated String");
00738     if (text) CharUpper(text);                          // get Windows API to convert
00739     return *this;
00740 }
00741 
00742 /**************************************************************************************
00743 >   StringBase& StringBase::toLower()
00744 
00745     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00746     Created:    22nd April 1993
00747     Purpose:    Converts all upper-case letters to lower-case.
00748 ***************************************************************************************/
00749 inline StringBase& StringBase::toLower()
00750 {
00751     ERROR3IF(!text, "Call to TOLOWER for an unALLOCated String");
00752     if (text) CharLower(text);
00753     return *this;
00754 }
00755 
00756 
00757     
00758     
00759 /**************************************************************************************
00760 >   StringBase::operator TCHAR*()
00761 
00762     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00763     Created:    22nd April 1993
00764     Returns:    Not applicable!
00765     Purpose:    Cast a string into a C-style pointer to array of characters.  If you
00766                 intend to use the subscript operator [] with the results of the cast
00767                 remember that no range checking is performed.
00768 ***************************************************************************************/
00769 inline StringBase::operator TCHAR*()
00770 {
00771     return text;
00772 }
00773 
00774 
00775     
00776     
00777 /**************************************************************************************
00778 >   StringBase::operator const TCHAR*() const
00779 
00780     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00781     Created:    22nd April 1993
00782     Returns:    N/A
00783     Purpose:    Cast a string into a C-style pointer to array of constant characters.
00784     SeeAlso:    StringBase::operator TCHAR*()
00785 ***************************************************************************************/
00786 inline StringBase::operator const TCHAR*() const
00787 {
00788     return text;
00789 }
00790 
00791 
00792     
00793     
00794 /**************************************************************************************
00795 >   StringBase::operator wxString()
00796 
00797     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00798     Created:    28th January 2006
00799     Returns:    Not applicable!
00800     Purpose:    Cast a string into a wxString
00801 ***************************************************************************************/
00802 inline StringBase::operator wxString()
00803 {
00804     return wxString(text);
00805 }
00806 
00807 
00808     
00809     
00810 /**************************************************************************************
00811 >   StringBase::operator const wxString&() const
00812 
00813     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00814     Created:    28th January 2006
00815     Returns:    N/A
00816     Purpose:    Cast a string into a wxString
00817     SeeAlso:    StringBase::operator TCHAR*()
00818 ***************************************************************************************/
00819 inline StringBase::operator const wxString() const
00820 {
00821     return wxString(text);
00822 }
00823 
00824 
00825     
00826     
00827 /**************************************************************************************
00828 >   StringBase& StringBase::operator+=(const StringBase& rhs)
00829 
00830     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00831     Created:    22nd April 1993
00832     Inputs:     The string to add to the end of this string.
00833     Returns:    A reference to the lhs, ie. this StringBase as an lvalue.
00834     Purpose:    Append string y onto the end of string x, eg.
00835                     x = TEXT("hello");
00836                     cout << (x += TEXT(" world!")) << endl;
00837 ***************************************************************************************/
00838 inline StringBase& StringBase::operator+=(const StringBase& rhs)
00839 {
00840     ERROR3IF(!text || !rhs.text, "Call to String::operator+= for an unALLOCated String");
00841 /*  ERROR3IF(camStrlen(text) + camStrlen(rhs.text) >= length,
00842             "Call to String::operator+= will result in overflow");*/
00843 
00844     if (text && rhs.text) SafeCat(text, rhs.text, length-1);
00845     return *this;
00846 }
00847 
00848 
00849 
00850 /**************************************************************************************
00851 >   StringBase& StringBase::operator=(const TCHAR ch)
00852 
00853     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00854     Created:    11/12/1995
00855     Inputs:     ch - a single character
00856     Returns:    A reference to this.
00857     Purpose:    Assigns the single character to this string
00858 ***************************************************************************************/
00859 inline StringBase& StringBase::operator=(const TCHAR ch)
00860 {
00861     ERROR3IF(text == 0, "Call to String::operator= for an unALLOCated String");
00862     text[0] = ch;
00863     text[1] = 0;
00864     return *this;
00865 }
00866 
00867 
00868 
00869 
00870 /**************************************************************************************
00871 >   TCHAR StringBase::operator[](const INT32 Index);
00872 
00873     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00874     Created:    22nd November 1995
00875     Returns     The character at offset Index into the string... Or 0 if there were
00876                 problems (or if the character was 0 of course).
00877     Purpose:    Extract single characters from the string...
00878                 0 is the first char, String.Length() is the terminating zero...
00879 **************************************************************************************/
00880 inline TCHAR StringBase::operator[](const INT32 Index)
00881 {
00882     ERROR3IF(!text, "Call to String::operator[] for an unALLOCated String");
00883     return (text && (Index <= (INT32)camStrlen(text))) ? text[Index] : 0;
00884 }
00885 
00886 
00887 
00888 /**************************************************************************************
00889 >   const WCHAR StringBase::CharAt(const INT32 Index);
00890 
00891     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00892     Created:    22nd November 1995
00893     Returns     The character at offset Index into the string... Or 0 if there were
00894                 problems (or if the character was 0 of course).
00895     Purpose:    Extract single characters from the string...
00896                 0 is the first char, String.Length() is the terminating zero...
00897 **************************************************************************************/
00898 inline const WCHAR StringBase::CharAt(const INT32 Index) const
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 }
00912 
00913 
00914 
00915 /**************************************************************************************
00916 >   INT32 operator==(const StringBase& lhs, const StringBase& rhs)
00917 
00918     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
00919     Created:    22nd April 1993 (24/5/94) (23/4/96)
00920     Returns     Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of
00921                 two strings.
00922     Purpose:    Comparison (logical) operators, eg.
00923                     x = "alpha";
00924                     y = "beta";
00925                     cout << "First is " << (x < y ? x : y) << endl;
00926                 These functions will work according to local custom.
00927 
00928     Notes:      Now uses IsIdentical to compare the strings, which is 12 times faster
00929                 than the new internationalised CompareTo.
00930 **************************************************************************************/
00931 
00932 inline bool operator==(const StringBase& x, const TCHAR* y)
00933 {
00934     return x.IsIdentical(y);
00935 }
00936 
00937 
00938 inline bool operator==(const StringBase& x, const StringBase& y)
00939 {
00940     return x.IsIdentical(y);
00941 }
00942 
00943     
00944     
00945 /**************************************************************************************
00946 >   INT32 operator!=(const StringBase& lhs, const StringBase& rhs)
00947 
00948     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
00949     Created:    22nd April 1993 (24/5/94) (23/4/96)
00950     Returns     Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of
00951                 two strings.
00952     Purpose:    Comparison (logical) operators, eg.
00953                     x = "alpha";
00954                     y = "beta";
00955                     cout << "First is " << (x < y ? x : y) << endl;
00956                 These functions will work according to local custom.
00957 
00958     Notes:      Now uses IsIdentical to compare the strings, which is 12 times faster
00959                 than the new internationalised CompareTo.
00960 **************************************************************************************/
00961 inline bool operator!=(const StringBase& x, const StringBase& y)
00962 {
00963     return !x.IsIdentical(y);
00964 }
00965 
00966 
00967 inline bool operator!=(const StringBase& x, const TCHAR* y)
00968 {
00969     return !x.IsIdentical(y);
00970 }
00971 
00972 
00973 
00974 /**************************************************************************************
00975 <   INT32 operator<(const StringBase& lhs, const StringBase& rhs)
00976 
00977     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
00978     Created:    22nd April 1993 (24/5/94)
00979     Returns     Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of
00980                 two strings.
00981     Purpose:    Comparison (logical) operators, eg.
00982                     x = "alpha";
00983                     y = "beta";
00984                     cout << "First is " << (x < y ? x : y) << endl;
00985                 These functions will work according to local custom.
00986 **************************************************************************************/
00987 inline bool operator<(const StringBase& x, const StringBase& y)
00988 {
00989     return x.CompareTo(y) < 0;
00990 }
00991 
00992 
00993 inline bool operator<(const StringBase& x, const TCHAR* y)
00994 {
00995     return x.CompareTo(y) < 0;
00996 }
00997 
00998 
00999 
01000     
01001 /**************************************************************************************
01002 >   INT32 operator>(const StringBase& lhs, const StringBase& rhs)
01003 
01004     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
01005     Created:    22nd April 1993 (24/5/94)
01006     Returns     Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of
01007                 two strings.
01008     Purpose:    Comparison (logical) operators, eg.
01009                     x = "alpha";
01010                     y = "beta";
01011                     cout << "First is " << (x < y ? x : y) << endl;
01012                 These functions will work according to local custom.
01013 **************************************************************************************/
01014 inline bool operator>(const StringBase& x, const StringBase& y)
01015 {
01016     return x.CompareTo(y) > 0;
01017 }
01018 
01019 
01020 inline bool operator>(const StringBase& x, const TCHAR* y)
01021 {
01022     return x.CompareTo(y) > 0;
01023 }
01024 
01025 
01026     
01027     
01028 /**************************************************************************************
01029 <   INT32 operator<=(const StringBase& lhs, const StringBase& rhs)
01030 
01031     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
01032     Created:    22nd April 1993 (24/5/94)
01033     Returns     Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of
01034                 two strings.
01035     Purpose:    Comparison (logical) operators, eg.
01036                     x = "alpha";
01037                     y = "beta";
01038                     cout << "First is " << (x < y ? x : y) << endl;
01039                 These functions will work according to local custom.
01040 **************************************************************************************/
01041 inline bool operator<=(const StringBase& x, const StringBase& y)
01042 {
01043     return x.CompareTo(y) <= 0;
01044 }
01045     
01046 
01047 inline bool operator<=(const StringBase& x, const TCHAR* y)
01048 {
01049     return x.CompareTo(y) <= 0;
01050 }
01051 
01052     
01053 
01054 
01055 /**************************************************************************************
01056 >   INT32 operator>=(const StringBase& lhs, const StringBase& rhs)
01057             ... etc.
01058 
01059     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
01060     Created:    22nd April 1993 (24/5/94)
01061     Returns     Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of
01062                 two strings.
01063     Purpose:    Comparison (logical) operators, eg.
01064                     x = "alpha";
01065                     y = "beta";
01066                     cout << "First is " << (x < y ? x : y) << endl;
01067                 These functions will work according to local custom.
01068 **************************************************************************************/
01069 inline bool operator>=(const StringBase& x, const TCHAR* y)
01070 {
01071     return x.CompareTo(y) >= 0;
01072 }
01073 
01074 
01075 
01076 inline bool operator>=(const StringBase& x, const StringBase& y)
01077 {
01078     return x.CompareTo(y) >= 0;
01079 }
01080 
01081 
01082 /**************************************************************************************
01083 
01084 >   static INT32 StringBase::TCharToNum(TCHAR c)
01085 
01086     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
01087     Created:    29/07/96
01088     Inputs:     c, a character
01089     Returns:    If c turns out to be a numeric character, its numeric value 0..9
01090     Purpose:    Convert a TCHAR into a numeric value. The routine does not check for
01091                 valid numeric characters, it just performs the conversion. Hence it
01092                 is possibly for you to pass in the character 's' for instance and receive
01093                 a >9 value back
01094 
01095 ***************************************************************************************/
01096 
01097 inline INT32 StringBase::TCharToNum(TCHAR c)
01098 {
01099     return c - TEXT('0');
01100 }
01101 
01102 
01103 
01104 
01105 /**************************************************************************************
01106 >   TCHAR* cc_camStrncpy(TCHAR* dest, const TCHAR* src, size_t n)
01107 
01108     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01109     Created:    9th Feb 1994
01110 
01111     Inputs:     destination, source, characters to copy
01112     Outputs:    -
01113 
01114     Returns:    destination
01115 
01116     Purpose:    Replaces the Windows API function camStrncpy(), whose existence has been
01117                 rewritten out of history.  Does basically what the standard C library
01118                 function memmove() does, only for TCHARs.
01119 ***************************************************************************************/
01120 
01121 inline TCHAR* cc_camStrncpy(TCHAR* dest, const TCHAR* src, INT32 n)
01122 {
01123     ERROR3IF(src == 0 || dest == 0 || n <= 0,
01124                 "0 (zero) parameters passed to cc_camStrncpy!");
01125     return camStrncpy(dest, src, n + 1);        // +1 as camStrncpy includes the terminator.
01126 }
01127 
01128 
01129 
01130 /**************************************************************************************
01131 
01132 >   TCHAR* cc_lstrrchr(TCHAR *Str, TCHAR c)
01133 
01134     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01135     Created:    21st November 1995
01136 
01137     Inputs:     Str - String to search in
01138                 c   - Character to search for
01139 
01140     Returns:    returns a pointer to the last occurrence of c in the given string
01141                 returns 0 if ch does not occurr in the string
01142 
01143     Purpose:    Finds the last occurrence of ch in string.  The terminating
01144                 0 character is used as part of the search.
01145                 This version is case sensitive.
01146     Notes:      Replaces the Windows API version which seems to be missing. Uses TCHAR's
01147                 instead of char's
01148 
01149 ***************************************************************************************/
01150 
01151 inline TCHAR* cc_lstrrchr(TCHAR *Str, TCHAR c)
01152 {
01153     ERROR3IF(Str == 0, "0 (zero) parameters passed to cc_lstrrchr");
01154     return (Str != 0) ? camStrrchr(Str, c) : 0;
01155 
01156 //  TCHAR *start = Str;
01157 //
01158 //  /* find end of string */
01159 //  while (*Str++);
01160 //
01161 //  /* search towards front */
01162 //  while (--Str != start && *Str != c);
01163 //
01164 //  /* char found ? */
01165 //  if (*Str == c)
01166 //      return(Str);
01167 //
01168 //  return(0);
01169 }
01170 
01171 
01172 /**************************************************************************************
01173 
01174 >   TCHAR* cc_lstrtok(TCHAR *String1, TCHAR *String2)
01175 
01176     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01177     Created:    21st November 1995
01178 
01179     Inputs:     String1 - string to tokenize, or 0 to get next token
01180                 String2 - string of characters to use as delimiters
01181     Returns:    returns pointer to first token in string, or if string
01182                 was 0, to next token
01183                 returns 0 when no more tokens remain.
01184 
01185     Purpose:    strtok considers the string to consist of a sequence of zero or more
01186                 text tokens separated by spans of one or more control chars. the first
01187                 call, with string specified, returns a pointer to the first char of the
01188                 first token, and will write a 0 char into string immediately
01189                 following the returned token. subsequent calls with zero for the first
01190                 argument (string) will work thru the string until no tokens remain. the
01191                 control string may be different from call to call. when no tokens remain
01192                 in string a 0 pointer is returned. remember the control chars with a
01193                 bit map, one bit per ascii char. the 0 char is always a control char.
01194     Notes:      Replaces the Windows API version which seems to be missing. Uses TCHAR's
01195                 instead of char's. I'm not totally convinced it's going to work with
01196                 DBCS, but if everyone uses it, at least we've got a single fix...
01197 
01198 ***************************************************************************************/
01199 
01200 // Only briefly tested...
01201 inline TCHAR* cc_lstrtok(TCHAR *String1, TCHAR *String2)
01202 {
01203     return NULL;
01204     
01205 //  return _tcstok(String1, String2);
01206 
01207 //  TCHAR *string = String1;
01208 //  TCHAR *str;
01209 //  TCHAR *ctrl = String2;
01210 //
01211 //  TCHAR map[32];
01212 //  INT32 count;
01213 //
01214 //  static TCHAR nextoken[256];
01215 //
01216 //  /* Clear control map */
01217 //  for (count = 0; count < 32; count++)
01218 //      map[count] = 0;
01219 //
01220 //  /* Set bits in delimiter table */
01221 //  do
01222 //  {
01223 //      map[*ctrl >> 3] |= (1 << (*ctrl & 7));
01224 //  } while (*ctrl++);
01225 //
01226 //  /* Initialize str. If string is 0, set str to the saved
01227 //   * pointer (i.e., continue breaking tokens out of the string
01228 //   * from the last strtok call) */
01229 //  if (string)
01230 //      str = string;
01231 //  else
01232 //      str = (TCHAR *)nextoken;
01233 //
01234 //  /* Find beginning of token (skip over leading delimiters). Note that
01235 //   * there is no token iff this loop sets str to point to the terminal
01236 //   * 0 (*str == '\0') */
01237 //  while ( (map[*str >> 3] & (1 << (*str & 7))) && *str )
01238 //          str++;
01239 //
01240 //  string = str;
01241 //
01242 //  /* Find the end of the token. If it is not the end of the string,
01243 //   * put a 0 there. */
01244 //  for ( ; *str ; str++ )
01245 //      if ( map[*str >> 3] & (1 << (*str & 7)) )
01246 //      {
01247 //          *str++ = '\0';
01248 //          break;
01249 //      }
01250 //
01251 //  /* Update nextoken (or the corresponding field in the per-thread data
01252 //   * structure */
01253 //  camStrcpy(nextoken, str);
01254 //
01255 //  /* Determine if a token has been found. */
01256 //  if ( string == str )
01257 //      return 0;
01258 //  else
01259 //      return string;
01260 }
01261 
01262 /**************************************************************************************
01263 
01264 >   INT32 cc_lstrncmp(TCHAR *String1, TCHAR *String2, INT32 Count)
01265 
01266     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01267     Created:    21st November 1995
01268 
01269     Inputs:     String1 - string to compare
01270                 String2 - string to compare
01271                 Count   - maximum number of characters to compare
01272 
01273     Returns:    returns <0 if first < last
01274                 returns  0 if first == last
01275                 returns >0 if first > last
01276 
01277     Purpose:    Compares two strings for lexical order.  The comparison stops
01278                 after: (1) a difference between the strings is found, (2) the end
01279                 of the strings is reached, or (3) count characters have been
01280                 compared.
01281     Notes:      Replaces the Windows API version which seems to be missing. Uses TCHAR's
01282                 instead of char's, and also uses CompareString for multinational support
01283 
01284 ***************************************************************************************/
01285 
01286 inline INT32 cc_lstrncmp(TCHAR *String1, TCHAR *String2, INT32 Count)
01287 {
01288     ERROR3IF(String1 == 0 || String2 == 0,
01289         "INT32 cc_lstrncmp(TCHAR *String1, TCHAR *String2, INT32 Count) given 0 params");
01290     return (Count != 0) ? camStrncmp(String1, String2, Count) : 0;
01291 }
01292 
01293 
01294 
01295 /**************************************************************************************
01296 >   size_t cc_strlenCharacters( const TCHAR* string )
01297 
01298     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01299     Created:    5/8/96
01300     Inputs:     string - pointer to a string
01301     Returns:    The number of *characters* in a string
01302     Purpose:    Returns the number of characters in a string - not necessaraily the 
01303                 length of the string.
01304     SeeAlso:    cc_strlenBytes
01305 ***************************************************************************************/
01306 inline size_t cc_strlenCharacters( const TCHAR* string )
01307 {
01308     return camStrclen(string);
01309 }
01310 
01311 
01312 
01313 /**************************************************************************************
01314 >   size_t cc_strlenBytes( const TCHAR* string )
01315 
01316     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01317     Created:    5/8/96
01318     Inputs:     string - pointer to a string
01319     Returns:    The length of a string in bytes
01320     Purpose:    Returns the number of bytes needed to store the given string.  Dosen't
01321                 include the terminator.  Unicode and DBCS aware.
01322     SeeAlso:    camStrclen
01323 ***************************************************************************************/
01324 inline size_t cc_strlenBytes( const TCHAR* string )
01325 {
01326     return camStrlen(string)*sizeof(TCHAR);
01327 }
01328 
01329 
01330 
01331 /**************************************************************************************
01332 
01333 >   TCHAR* cc_lstrchr(TCHAR *Str, TCHAR c)
01334 
01335     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01336     Created:    21st November 1995
01337 
01338     Inputs:     Str - String to search in
01339                 c   - Character to search for
01340 
01341     Returns:    returns pointer to the first occurence of c in string
01342                 returns 0 if c does not occur in string
01343 
01344     Purpose:    Searches a string for a given character, which may be the
01345                 0 character '\0'.
01346                 This version is case sensitive.
01347     Notes:      Replaces the Windows API version which seems to be missing. Uses TCHAR's
01348                 instead of char's
01349 
01350 ***************************************************************************************/
01351 
01352 inline TCHAR* cc_lstrchr(TCHAR *Str, TCHAR c)
01353 {
01354     ERROR3IF(Str == 0, "0 (zero) parameters passed to cc_lstrchr");
01355     return (Str != 0) ? camStrchr(Str, c) : 0;
01356 
01357 //  while (*Str && *Str != c)
01358 //      Str++;
01359 //
01360 //  if (*Str == c)
01361 //      return(Str);
01362 //  return(0);
01363 }
01364 
01365 
01366 /**************************************************************************************
01367 
01368 >   INT32 StringBase::SkipSpace(INT32 pos=0) const
01369 
01370     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
01371     Created:    29/07/96
01372     Inputs:     pos = the character index from which to start
01373     Returns:    the index of the next none space character
01374                 -1 if none, OR an exception is thrown
01375     Purpose:    Find the next non-space character starting from pos. If pos is a
01376                 none space character, the function will simply return with the same
01377                 index.
01378     Notes:      ** Throws an exception if string exceptions are enabled **
01379 
01380 ***************************************************************************************/
01381 
01382 inline INT32 StringBase::SkipSpace(INT32 pos) const
01383 {
01384     return FindNextChar(pos);
01385 }
01386 
01387 #endif  // INC_STRINGBASE

Generated on Sat Nov 10 03:48:04 2007 for Camelot by  doxygen 1.4.4