basestr.h File Reference

(r1785/r1283)

#include "ccobject.h"
#include "errors.h"

Go to the source code of this file.

Classes

class  StringBase

Defines

#define FIX_LEN_BUFM(x)   (((x)+1)*2)
 General-purpose string class. Overloads the C++ arithmetic operator += which for strings perform concatenation, together with the comparison operators <, >, !=, ==, etc, which will perform case-sensitive comparisons according to the local custom.
#define DEFINE_BUFSIZE(x)   const INT32 String_ ## x::FIX_LEN_BUFSIZE = FIX_LEN_BUFM(x);

Functions

INT32 CCAPI SmartLoadString (UINT32 modID, UINT32 resID, TCHAR *buf, INT32 size)
TCHARcc_camStrncpy (TCHAR *dest, const TCHAR *src, size_t n)
const TCHARcc_lstrstr (const TCHAR *String1, const TCHAR *String2)
 Read/write a string to/from a persistent stream, a.k.a. an archive, depending upon the value of ar.IsStoring(). Finds the first occurrence of string2 in string1 This version is case sensitive. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's, and also uses CompareString for multinational support.
TCHARcc_lstrchr (TCHAR *Str, TCHAR c)
 Searches a string for a given character, which may be the 0 character ''. This version is case sensitive. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's.
TCHARcc_lstrrchr (TCHAR *Str, TCHAR c)
 Finds the last occurrence of ch in string. The terminating 0 character is used as part of the search. This version is case sensitive. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's.
TCHARcc_lstrtok (TCHAR *String1, TCHAR *String2)
 strtok considers the string to consist of a sequence of zero or more text tokens separated by spans of one or more control chars. the first call, with string specified, returns a pointer to the first char of the first token, and will write a 0 char into string immediately following the returned token. subsequent calls with zero for the first argument (string) will work thru the string until no tokens remain. the control string may be different from call to call. when no tokens remain in string a 0 pointer is returned. remember the control chars with a bit map, one bit per ascii char. the 0 char is always a control char. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's. I'm not totally convinced it's going to work with DBCS, but if everyone uses it, at least we've got a single fix...
INT32 cc_lstrncmp (TCHAR *String1, TCHAR *String2, INT32 Count)
 Compares two strings for lexical order. The comparison stops after: (1) a difference between the strings is found, (2) the end of the strings is reached, or (3) count characters have been compared. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's, and also uses CompareString for multinational support.
size_t cc_strlenCharacters (const TCHAR *string)
 Returns the number of characters in a string - not necessaraily the length of the string.
size_t cc_strlenBytes (const TCHAR *string)
 Returns the number of bytes needed to store the given string. Dosen't include the terminator. Unicode and DBCS aware.
bool operator== (const StringBase &x, const TCHAR *y)
 Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.
bool operator== (const StringBase &x, const StringBase &y)
bool operator!= (const StringBase &x, const StringBase &y)
 Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.
bool operator!= (const StringBase &x, const TCHAR *y)
bool operator< (const StringBase &x, const StringBase &y)
 Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.
bool operator< (const StringBase &x, const TCHAR *y)
bool operator> (const StringBase &x, const StringBase &y)
 Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.
bool operator> (const StringBase &x, const TCHAR *y)
bool operator<= (const StringBase &x, const StringBase &y)
 Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.
bool operator<= (const StringBase &x, const TCHAR *y)
bool operator>= (const StringBase &x, const TCHAR *y)
 Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.
bool operator>= (const StringBase &x, const StringBase &y)
TCHARcc_camStrncpy (TCHAR *dest, const TCHAR *src, INT32 n)
 Replaces the Windows API function camStrncpy(), whose existence has been rewritten out of history. Does basically what the standard C library function memmove() does, only for TCHARs.

Variables

const size_t MAX_STRING_RES_LENGTH = 255
const INT32 str_MAXEXCEPTIONS = 30


Define Documentation

#define DEFINE_BUFSIZE  )     const INT32 String_ ## x::FIX_LEN_BUFSIZE = FIX_LEN_BUFM(x);
 

Definition at line 155 of file basestr.h.

#define FIX_LEN_BUFM  )     (((x)+1)*2)
 

General-purpose string class. Overloads the C++ arithmetic operator += which for strings perform concatenation, together with the comparison operators <, >, !=, ==, etc, which will perform case-sensitive comparisons according to the local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
22nd April 1993; ammended 6th August 1993
Other functions provided include Left(), Mid(), and Right(), for decomposing strings, plus Sub(), which returns the position of a string within another string. A new sprintf()-type member function has been provided, MakeMsg(), which performs internationally portable argument substitution according to a formatting string read from the application's resources.

The primary use of this class is to serve as a base for the derivation of fixed length StringBases. Derived String_N's, unlike their StringBase base classes, do not allocate a buffer for text on the heap, but within their class instance.

Note that these kind of base-class strings CAN be of an arbitrary length, but the user must call Alloc() to change the length - all member functions assume that the StringBase is long enough to cope with the operation of the function. Attempts to access past the end of the string will be trapped with ASSERTions.

Returns:
Errors: Most functions validate their parameters, eg. asking Left() to extract the leftmost 0 characters of a string will cause the function to return a 0 string.
Notes: As of 4th May 1993, all serialisation / archive support has been commented out, as this does not work and nobody seems to know why. This will be rectified when serialisation is needed (some time in the future).

Definition at line 152 of file basestr.h.


Function Documentation

TCHAR* cc_camStrncpy TCHAR dest,
const TCHAR src,
INT32  n
[inline]
 

Replaces the Windows API function camStrncpy(), whose existence has been rewritten out of history. Does basically what the standard C library function memmove() does, only for TCHARs.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
9th Feb 1994
Parameters:
destination,source,characters to copy [INPUTS]
- [OUTPUTS]
Returns:
destination

Definition at line 1121 of file basestr.h.

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 }

TCHAR* cc_camStrncpy TCHAR dest,
const TCHAR src,
size_t  n
 

TCHAR * cc_lstrchr TCHAR Str,
TCHAR  c
[inline]
 

Searches a string for a given character, which may be the 0 character ''. This version is case sensitive. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
21st November 1995
Parameters:
Str - String to search in [INPUTS] c - Character to search for
Returns:
returns pointer to the first occurence of c in string returns 0 if c does not occur in string

Definition at line 1352 of file basestr.h.

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 }

INT32 cc_lstrncmp TCHAR String1,
TCHAR String2,
INT32  Count
[inline]
 

Compares two strings for lexical order. The comparison stops after: (1) a difference between the strings is found, (2) the end of the strings is reached, or (3) count characters have been compared. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's, and also uses CompareString for multinational support.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
21st November 1995
Parameters:
String1 - string to compare [INPUTS] String2 - string to compare Count - maximum number of characters to compare
Returns:
returns <0 if first < last returns 0 if first == last returns >0 if first > last

Definition at line 1286 of file basestr.h.

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 }

TCHAR * cc_lstrrchr TCHAR Str,
TCHAR  c
[inline]
 

Finds the last occurrence of ch in string. The terminating 0 character is used as part of the search. This version is case sensitive. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
21st November 1995
Parameters:
Str - String to search in [INPUTS] c - Character to search for
Returns:
returns a pointer to the last occurrence of c in the given string returns 0 if ch does not occurr in the string

Definition at line 1151 of file basestr.h.

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 }

const TCHAR* cc_lstrstr const TCHAR String1,
const TCHAR String2
 

Read/write a string to/from a persistent stream, a.k.a. an archive, depending upon the value of ar.IsStoring(). Finds the first occurrence of string2 in string1 This version is case sensitive. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's, and also uses CompareString for multinational support.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
21st November 1995
Parameters:
String 1 - String to search in [INPUTS] String 2 - String to search for
Returns:
Returns a pointer to the first occurrence of string2 in string1, or 0 if string2 does not occur in string1

Definition at line 1632 of file basestr.cpp.

01633 {
01634     ERROR3IF(String1 == 0 || String2 == 0,
01635                 "0 (zero) parameters passed to cc_lstrstr");
01636 
01637     if (String1 == 0 || String2 == 0) return 0;
01638     if (!*String2) return String1;
01639     return camStrstr(String1, String2);
01640 
01641 //  TCHAR *cp = String1;
01642 //  TCHAR *s1;
01643 //  TCHAR *s2;
01644 
01645 //  while (*cp)
01646 //  {
01647 //      s1 = cp;
01648 //      s2 = String2;
01649 
01650 //      // DCBS compatible case sensitive string compare
01651 //      while(*s1 && *s2 && (CompareString(LOCALE_USER_DEFAULT,
01652 //          (NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH),
01653 //          s1, 1, s2, 1) == 2))
01654 //          s1++, s2++;
01655 //      if(!*s2)
01656 //          return(cp);
01657 //      cp++;
01658 //  }
01659 //
01660 //  return(0);
01661 }

TCHAR * cc_lstrtok TCHAR String1,
TCHAR String2
[inline]
 

strtok considers the string to consist of a sequence of zero or more text tokens separated by spans of one or more control chars. the first call, with string specified, returns a pointer to the first char of the first token, and will write a 0 char into string immediately following the returned token. subsequent calls with zero for the first argument (string) will work thru the string until no tokens remain. the control string may be different from call to call. when no tokens remain in string a 0 pointer is returned. remember the control chars with a bit map, one bit per ascii char. the 0 char is always a control char. Notes: Replaces the Windows API version which seems to be missing. Uses TCHAR's instead of char's. I'm not totally convinced it's going to work with DBCS, but if everyone uses it, at least we've got a single fix...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
21st November 1995
Parameters:
String1 - string to tokenize, or 0 to get next token [INPUTS] String2 - string of characters to use as delimiters
Returns:
returns pointer to first token in string, or if string was 0, to next token returns 0 when no more tokens remain.

Definition at line 1201 of file basestr.h.

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 }

size_t cc_strlenBytes const TCHAR string  )  [inline]
 

Returns the number of bytes needed to store the given string. Dosen't include the terminator. Unicode and DBCS aware.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/8/96
Parameters:
string - pointer to a string [INPUTS]
Returns:
The length of a string in bytes
See also:
camStrclen

Definition at line 1324 of file basestr.h.

01325 {
01326     return camStrlen(string)*sizeof(TCHAR);
01327 }

size_t cc_strlenCharacters const TCHAR string  )  [inline]
 

Returns the number of characters in a string - not necessaraily the length of the string.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/8/96
Parameters:
string - pointer to a string [INPUTS]
Returns:
The number of *characters* in a string
See also:
cc_strlenBytes

Definition at line 1306 of file basestr.h.

01307 {
01308     return camStrclen(string);
01309 }

bool operator!= const StringBase x,
const TCHAR y
[inline]
 

Definition at line 967 of file basestr.h.

00968 {
00969     return !x.IsIdentical(y);
00970 }

bool operator!= const StringBase x,
const StringBase y
[inline]
 

Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
22nd April 1993 (24/5/94) (23/4/96) Returns Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of two strings.
Notes: Now uses IsIdentical to compare the strings, which is 12 times faster than the new internationalised CompareTo.

Definition at line 961 of file basestr.h.

00962 {
00963     return !x.IsIdentical(y);
00964 }

bool operator< const StringBase x,
const TCHAR y
[inline]
 

Definition at line 993 of file basestr.h.

00994 {
00995     return x.CompareTo(y) < 0;
00996 }

bool operator< const StringBase x,
const StringBase y
[inline]
 

Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
22nd April 1993 (24/5/94) Returns Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of two strings.

Definition at line 987 of file basestr.h.

00988 {
00989     return x.CompareTo(y) < 0;
00990 }

bool operator<= const StringBase x,
const TCHAR y
[inline]
 

Definition at line 1047 of file basestr.h.

01048 {
01049     return x.CompareTo(y) <= 0;
01050 }

bool operator<= const StringBase x,
const StringBase y
[inline]
 

Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
22nd April 1993 (24/5/94) Returns Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of two strings.

Definition at line 1041 of file basestr.h.

01042 {
01043     return x.CompareTo(y) <= 0;
01044 }

bool operator== const StringBase x,
const StringBase y
[inline]
 

Definition at line 938 of file basestr.h.

00939 {
00940     return x.IsIdentical(y);
00941 }

bool operator== const StringBase x,
const TCHAR y
[inline]
 

Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
22nd April 1993 (24/5/94) (23/4/96) Returns Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of two strings.
Notes: Now uses IsIdentical to compare the strings, which is 12 times faster than the new internationalised CompareTo.

Definition at line 932 of file basestr.h.

00933 {
00934     return x.IsIdentical(y);
00935 }

bool operator> const StringBase x,
const TCHAR y
[inline]
 

Definition at line 1020 of file basestr.h.

01021 {
01022     return x.CompareTo(y) > 0;
01023 }

bool operator> const StringBase x,
const StringBase y
[inline]
 

Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
22nd April 1993 (24/5/94) Returns Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of two strings.

Definition at line 1014 of file basestr.h.

01015 {
01016     return x.CompareTo(y) > 0;
01017 }

bool operator>= const StringBase x,
const StringBase y
[inline]
 

Definition at line 1076 of file basestr.h.

01077 {
01078     return x.CompareTo(y) >= 0;
01079 }

bool operator>= const StringBase x,
const TCHAR y
[inline]
 

Comparison (logical) operators, eg. x = "alpha"; y = "beta"; cout << "First is " << (x < y ? x : y) << endl; These functions will work according to local custom.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
22nd April 1993 (24/5/94) Returns Return 0 (FALSE) or 1 (TRUE) according to the relative lexical order of two strings.

Definition at line 1069 of file basestr.h.

01070 {
01071     return x.CompareTo(y) >= 0;
01072 }

INT32 CCAPI SmartLoadString UINT32  modID,
UINT32  resID,
TCHAR buf,
INT32  size
 


Variable Documentation

const size_t MAX_STRING_RES_LENGTH = 255
 

Definition at line 158 of file basestr.h.

const INT32 str_MAXEXCEPTIONS = 30
 

Definition at line 159 of file basestr.h.


Generated on Sat Nov 10 03:49:27 2007 for Camelot by  doxygen 1.4.4