basestr.cpp File Reference

(r1785/r1282)

#include "camtypes.h"
#include <iostream>
#include <stdarg.h>
#include "camelot.h"

Go to the source code of this file.

Functions

 DECLARE_SOURCE ("$Revision: 1282 $")
INT32 SmartLoadString (UINT32 modID, UINT32 resID, LPTCHAR buf, INT32 size)
 Loading a string resource, possibly from a .DLL. If modID is non-zero then that module is tried first, falling back to the main program if not found. Also has to work-around a nasty bug in Win32s LoadStringA. Also recognises Tool resource IDs and works out the module automatically (if modID is zero).
std::istream & operator>> (std::istream &is, StringBase &s)
 Read a string from a (non-persistent) stream. The input is terminated by a newline character (NOT whitespace, cf. reading C-style character arrays). If the string is longer than MAX_STRING_RES_LENGTH get() will read as many characters as possible and put a newline at the end.
std::ostream & operator<< (std::ostream &os, const StringBase &s)
 Write a string to a (non-persistent) stream. If the string is 0 then "[0]" is printed.
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.


Function Documentation

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 }

DECLARE_SOURCE "$Revision: 1282 $"   ) 
 

Definition of the string class, as declared in StringBase.h.

std::ostream& operator<< std::ostream &  os,
const StringBase s
 

Write a string to a (non-persistent) stream. If the string is 0 then "[0]" is printed.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
22nd April 1993
Parameters:
A reference to an output stream) and a reference to the constant string [INPUTS] to write to it.
Returns:
Reference to the output stream.
See also:
istream& operator>>(istream& is, StringBase& s)

Definition at line 1274 of file basestr.cpp.

01275 {
01276     ERROR3IF(!s.text, "Call to ostream << for an unALLOCated String");  
01277     os << (s.Length() ? s.text : TEXT("[0]"));
01278     return os;
01279 }

std::istream& operator>> std::istream &  is,
StringBase s
 

Read a string from a (non-persistent) stream. The input is terminated by a newline character (NOT whitespace, cf. reading C-style character arrays). If the string is longer than MAX_STRING_RES_LENGTH get() will read as many characters as possible and put a newline at the end.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
22nd April 1993
Parameters:
A reference to an input stream and a reference to the string whose [INPUTS] value is to be read.
Returns:
A reference to the input stream, which enables the chaining of stream operations.
See also:
ostream& operator<<(ostream& os, const StringBase& s)

Definition at line 1240 of file basestr.cpp.

01241 {
01242     ERROR3IF(!s.text, "Call to istream >> for an unALLOCated String");
01243 
01244     char                temp[MAX_STRING_RES_LENGTH];
01245     is >> std::ws;                              // skip any leading whitespace
01246     is.get(temp, MAX_STRING_RES_LENGTH);    // grab a chunk of input, up to a newline
01247     
01248     ERROR3IF( size_t(s.length) <= strlen(temp), "Call to istream >> will overflow String" );
01249 #if wxUSE_UNICODE
01250 PORTNOTE("other","This is not very efficient needs revisiting")
01251     TCHAR               ptsz[MAX_STRING_RES_LENGTH];
01252     mbstowcs( ptsz, temp, MAX_STRING_RES_LENGTH );
01253 #else
01254     s = temp;                               // NB. s.operator=(const TCHAR*)
01255 #endif
01256     return is;
01257 }

INT32 SmartLoadString UINT32  modID,
UINT32  resID,
LPTCHAR  buf,
INT32  size
 

Loading a string resource, possibly from a .DLL. If modID is non-zero then that module is tried first, falling back to the main program if not found. Also has to work-around a nasty bug in Win32s LoadStringA. Also recognises Tool resource IDs and works out the module automatically (if modID is zero).

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
Parameters:
modID (portable) module ID, or 0 for Kernel [INPUTS] resID ID of required string size byte size of return buffer
buf result buffer address [OUTPUTS]
Returns:
0 if failed to load, else number of bytes read
Actually when we say 'falling back to the main program' we really mean 'checking if it's in an external resources dll before falling back to the main program'. If no modID is given, we also check the external resource dll first. Well, actually that's not TRUE, since if it's a tool resource it's going to be in the tools dll rather than the resource only one, so we jump the queue a little there...

Returns:
Errors: Returns 0 if not found anywhere.

Definition at line 1090 of file basestr.cpp.

01091 {
01092     PORTNOTE("other","SmartLoadString - needs to be converted to GetText")
01093     ERROR3IF(resID == 0, "Zero string resource ID in SmartLoadString");
01094     ERROR3IF(buf == 0, "No output buffer in SmartLoadString");
01095     INT32 numchars = size/sizeof(TCHAR);
01096     ERROR3IF(numchars < 2, "Buffer too small in SmartLoadString");
01097 
01098     camStrncpy( buf, CamResource::GetText(resID), numchars ); // NB GetText cannot fail
01099     buf[numchars-1]=0; // ensure zero terminated
01100     return (camStrlen(buf)+1)*sizeof(TCHAR); // return number of bytes copied
01101 }


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