home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
ISTRING.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
55KB
|
1,092 lines
#ifndef _ISTRING_
#define _ISTRING_
/*******************************************************************************
* FILE NAME: istring.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IString - general-purpose string class *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#if !defined( _IBASE_ )
#include <ibase.hpp>
#endif
#ifndef _ISTRENUM_
#include <istrenum.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
extern "C"
{
#include <limits.h>
}
class IStringTest;
class IBuffer;
class ostream;
class istream;
class IString : public IBase {
/*******************************************************************************
* Objects of the IString class are arrays of characters. *
* *
* IStrings provide the following function beyond that available from the *
* standard C char* arrays and the string.h library functions: *
* o No restrictions on string contents. In other words, strings can *
* contain null characters. *
* o Automatic conversion from and to numeric types *
* o Automatic deletion of string buffer when the IString is destroyed *
* o Full support for the following: *
* - All comparison operators *
* - All bitwise operators *
* - Concatenation using the more natural "+" operator. *
* o String data testing, such as for characters, digits, and hexadecimal *
* digits *
* o A full complement of the following: *
* - String manipulation functions, such as center, left and right *
* justification, stripping of leading and trailing characters, *
* substring deletion, and insertion of strings *
* - Corresponding string manipulation functions that return a new *
* IString rather than modifying the receiver *
* - String searching functions, such as index of string and last *
* index of string. *
* o Word manipulation, such as index of word and search for word phrase *
* o Support for mixed strings that contain both single-byte character set *
* (SBCS) and double-byte character set (DBCS) characters. *
* *
* When a program using IStrings is run on OS/2J, the IString objects *
* support DBCS characters within the string contents. The various *
* IString searching functions will not accidentally match an SBCS *
* character with the second byte of a DBCS character that happens to *
* have the same value. Also, IString functions that modify IStrings, *
* such as subString, remove, and translate, will never separate two *
* bytes of a DBCS character. If one of the two bytes of a DBCS *
* character is removed, the remaining byte will be replaced with the *
* appropriate pad character (if the function performing the change has *
* one), or a blank. *
* *
* Care must be taken with IStrings that contain DBCS data to ensure that *
* the contents are not altered in such a way as to corrupt the data. *
* For example, the statement: *
* *
* aString[ n ] = 'x'; *
* *
* would be in error if the nth character of the IString was the first *
* or second byte of a DBCS character. *
*******************************************************************************/
public:
/*------------------------- Constructors/Destructor ----------------------------
| You can construct instances of this class in the following ways: |
| - Construct a null string. |
| - Construct a string with the ASCII representation of a given numeric |
| value, supporting all flavors of int and double. |
| - Construct a string with a copy of the given character data, supporting |
| ASCIIZ strings, characters, and IStrings. The character data passed |
| will be converted to its ASCII representation. |
| - Construct a string with contents that consist of copies of up to three |
| buffers of arbitrary data (void*). Optionally, only the length need |
| be provided, in which case the IString contents are initialized to a |
| given pad character. The default is a blank. |
------------------------------------------------------------------------------*/
IString ( );
IString ( const IString & );
IString ( int );
IString ( unsigned );
IString ( long );
IString ( unsigned long );
IString ( short );
IString ( unsigned short );
IString ( double );
IString ( char );
IString ( unsigned char );
IString ( signed char );
IString ( const char * );
IString ( const unsigned char * );
IString ( const signed char * );
IString ( const void *pBuffer1,
unsigned lenBuffer1,
char padCharacter = ' ' );
IString ( const void *pBuffer1,
unsigned lenBuffer1,
const void *pBuffer2,
unsigned lenBuffer2,
char padCharacter = ' ' );
IString ( const void *pBuffer1,
unsigned lenBuffer1,
const void *pBuffer2,
unsigned lenBuffer2,
const void *pBuffer3,
unsigned lenBuffer3,
char padCharacter = ' ' );
~IString ( );
/*-------------------------------- Stream I/O ----------------------------------
The following functions provide for reading and writing IStrings from and
to standard C++ streams:
operator << - Puts an IString's contents to an output stream.
operator >> - Puts the next whitespace-delimited word from an input
stream into an IString.
lineFrom - Static function that returns the next line from the
argument input stream. This function accepts an optional
line delimiter, which defaults to \n; the resulting IString
contains the characters up to the next occurrence of the
delimiter. The delimiter character is skipped.
------------------------------------------------------------------------------*/
friend ostream
&operator << ( ostream &aStream,
const IString &aString );
friend istream
&operator >> ( istream &aStream,
IString &aString );
static IString
lineFrom ( istream &aStream,
char delim = '\n' );
/*--------------------------------- Testing ------------------------------------
| The following functions test the characters that comprise the string: |
| isAlphanumeric - True if and only if all characters are in |
| {'A'-'Z','a'-'z','0'-'9'}. |
| isAlphabetic - True if and only if all characters are in |
| {'A'-'Z','a'-'z'}. |
| isASCII - True if and only if all characters are in {0x00-0x7F}. |
| isControl - True if and only if all characters are in |
| {0x00-0x1F,0x7F}. |
| isDigits - True if and only if all characters are in {'0'-'9'}. |
| isGraphics - True if and only if all characters are in {0x21-0x7E}. |
| isHexDigits - True if and only if all characters are in |
| {'0'-'9','A'-'F','a'-'f'}. |
| isBinaryDigits - True if and only if all characters are either '0' or |
| '1'. |
| isLowerCase - True if and only if all characters are in {'a'-'z'}. |
| isPrintable - True if and only if all characters are in {0x20-0x7E}. |
| isPunctuation - True if and only if none of the characters are |
| whitespace, control characters, or alphanumeric. |
| isWhiteSpace - True if and only if all characters are in |
| {0x09-0x0D,0x20}. |
| isUpperCase - True if and only if all characters are in {'A'-'Z'}. |
| isDBCS - True if and only if all characters are DBCS |
| (double-byte). |
| isSBCS - True if and only if all characters are SBCS |
| (single-byte). |
| isValidDBCS - True if and only if no DBCS characters have a 0 |
| second byte. |
| includesDBCS - True if and only if any characters are DBCS |
| (double-byte). |
| includesSBCS - True if and only if any characters are SBCS |
| (single-byte). |
| isLike - True if and only if the receiver matches the argument |
| pattern, which can contain wildcard characters. |
| isAbbreviationFor - True if the receiver is a valid abbreviation of the |
| argument string. |
| includes - True if the receiver contains the argument search |
| string. |
------------------------------------------------------------------------------*/
Boolean
isAlphanumeric ( ) const,
isAlphabetic ( ) const,
isASCII ( ) const,
isControl ( ) const,
isDigits ( ) const,
isGraphics ( ) const,
isHexDigits ( ) const,
isBinaryDigits ( ) const,
isLowerCase ( ) const,
isPrintable ( ) const,
isPunctuation ( ) const,
isUpperCase ( ) const,
isWhiteSpace ( ) const,
isDBCS ( ) const,
isSBCS ( ) const,
isValidDBCS ( ) const,
includesDBCS ( ) const,
includesSBCS ( ) const,
isLike ( const IString &aPattern,
char zeroOrMore = '*',
char anyChar = '?' ) const,
isLike ( const char *pPattern,
char zeroOrMore = '*',
char anyChar = '?' ) const,
isAbbreviationFor ( const IString &fullString,
unsigned minAbbrevLength = 0 ) const,
isAbbreviationFor ( const char *pFullString,
unsigned minAbbrevLength = 0 ) const,
includes ( const IString &aString ) const,
includes ( const char *pString ) const,
includes ( char aChar ) const,
includes ( const IStringTest &aTest ) const;
/*------------------------------- Comparison -----------------------------------
| All Boolean operators are defined for strings. The following functions |
| are overloaded so that IStrings can be compared to objects of type char*, |
| as well as to other IStrings. |
| operator == - True if and only if the strings are identical. |
| operator != - True if and only if the strings are not identical. |
| operator < - True if and only if the first string is less than the |
| second, applying the standard collating scheme (memcmp). |
| operator > - Equivalent to '!(string1 <= string2)'. |
| operator <= - Equivalent to '(string1 < string2) || (string1 == string2)'. |
| operator >= - Equivalent to '!(string1 < string2)'. |
------------------------------------------------------------------------------*/
friend Boolean
operator == ( const IString &string1,
const IString &string2 ),
operator == ( const IString &string1,
const char *pString2 ),
operator == ( const char *pString1,
const IString &string2 ),
operator != ( const IString &string1,
const IString &string2 ),
operator != ( const IString &string1,
const char *pString2 ),
operator != ( const char *pString1,
const IString &string2 ),
operator < ( const IString &string1,
const IString &string2 ),
operator < ( const IString &string1,
const char *pString2 ),
operator < ( const char *pString1,
const IString &string2 ),
operator <= ( const IString &string1,
const IString &string2 ),
operator <= ( const IString &string1,
const char *pString2 ),
operator <= ( const char *pString1,
const IString &string2 ),
operator > ( const IString &string1,
const IString &string2 ),
operator > ( const IString &string1,
const char *pString2 ),
operator > ( const char *pString1,
const IString &string2 ),
operator >= ( const IString &string1,
const IString &string2 ),
operator >= ( const IString &string1,
const char *pString2 ),
operator >= ( const char *pString1,
const IString &string2 );
/*------------------------------- Conversion -----------------------------------
| The following functions permit the conversion of a string to various other |
| data types. The types supported are the same set as are supported by the |
| IString constructors: |
| |
| operator char* - Returns a char* pointer to the string's |
| contents. |
| operator signed char* - Returns a signed char* pointer to the string's |
| contents. |
| operator unsigned char* - Returns an unsigned char* pointer to the |
| string's contents. |
| asString - Returns the string itself, so that IString |
| supports this common IBase protocol. |
| asDebugInfo - Returns information about the IString's |
| internal representation that can be used for |
| debugging. |
| asInt - Returns, as a long integer, the number that the |
| string represents. |
| asUnsigned - Returns, as an unsigned long, the number that |
| the string represents. |
| asDouble - Returns, as a double, the number that the |
| string represents. |
| |
| In addition, a complete set of functions is provided for converting a |
| String from any of the following formats to another format: |
| b - A string of binary digits ('0' and '1'). |
| c - A normal string of characters. |
| d - A string of decimal digits ('0' through '9'). |
| x - A string of hexadecimal digits ('0' through '9' and 'a/A' through |
| 'f/F'). |
| |
| The following functions work if isBinaryDigits() == true; if not, they |
| return a null string: |
| b2c - Changes '01' to '\x01', '00110011' to '3'. |
| b2d - Changes '00011001' to '25', '0001001000110100' to '4660'. |
| b2x - Changes '00011011' to '1b', '10001001000110100' to '11234'. |
| |
| The following functions always work: |
| c2b - Changes 'a' to '01010001', '12' to '11000100110010'. |
| c2d - Changes 'a' to '97', 'ab' to '24930'. |
| c2x - Changes 'a' to '61', 'ab' to '6162'. |
| |
| The following functions work if isDigits() == true; if not, they return a |
| null string: |
| d2b - Changes '12' to '1100', '123' to '1111011'. |
| d2c - Changes '12' to '\x0c', '56' to '8'. |
| d2x - Changes '12' to 'c', '123' to '7b'. |
| |
| The following functions work if isHexDigits() == true; if not, they return |
| a null string: |
| x2b - Changes 'a1c' to '101000011100', 'f3' to '11110011'. |
| x2c - Changes '8' to '\x08', '31393932' to '1992'. |
| x2d - Changes 'a1c' to '2588', '10000' to '65536'. |
| |
| Static functions by the same name can be applied to a String to return the |
| modified string, without changing the argument String. These functions |
| are used much like the similar REXX functions. For example: |
| |
| aString.c2b(); // Changes aString. |
| String binaryDigits = IString::c2b( aString ); // Leaves aString alone. |
------------------------------------------------------------------------------*/
operator char* ( ) const;
operator unsigned char* ( ) const;
operator signed char* ( ) const;
IString
asString ( ) const,
asDebugInfo ( ) const;
long
asInt ( ) const;
unsigned long
asUnsigned ( ) const;
double
asDouble ( ) const;
IString
&b2c ( ),
&b2d ( ),
&b2x ( ),
&c2b ( ),
&c2d ( ),
&c2x ( ),
&d2b ( ),
&d2c ( ),
&d2x ( ),
&x2b ( ),
&x2c ( ),
&x2d ( );
static IString
b2c ( const IString &aString ),
b2d ( const IString &aString ),
b2x ( const IString &aString ),
c2b ( const IString &aString ),
c2d ( const IString &aString ),
c2x ( const IString &aString ),
d2b ( const IString &aString ),
d2c ( const IString &aString ),
d2x ( const IString &aString ),
x2b ( const IString &aString ),
x2c ( const IString &aString ),
x2d ( const IString &aString );
/*------------------------- Manipulation Operators -----------------------------
| The following functions allow the string's contents to be manipulated. |
| All are overloaded so that standard C "strings" can be used efficiently, |
| without constructing an equivalent String first. |
| operator = - Replaces the contents of the string. |
| operator ~ - Returns bitwise negation (one's complement). |
| operator + - Concatenates two strings. |
| operator += - Concatenates and replaces. |
| operator & - Performs bitwise AND. |
| operator &= - Performs bitwise AND and replaces the receiver. |
| operator | - Performs bitwise OR. |
| operator |= - Performs bitwise OR and replaces the receiver. |
| operator ^ - Performs bitwise XOR. |
| operator ^= - Performs bitwise XOR and replaces the receiver. |
------------------------------------------------------------------------------*/
IString
&operator = ( const IString &aString ),
operator ~ ( ) const,
operator + ( const IString &aString ) const,
operator + ( const char *pString ) const,
&operator += ( const IString &aString ),
&operator += ( const char *pString ),
operator & ( const IString &aString ) const,
operator & ( const char *pString ) const,
&operator &= ( const IString &aString ),
&operator &= ( const char *pString ),
operator | ( const IString &aString ) const,
operator | ( const char *pString ) const,
&operator |= ( const IString &aString ),
&operator |= ( const char *pString ),
operator ^ ( const IString &aString ) const,
operator ^ ( const char *pString ) const,
&operator ^= ( const IString &aString ),
&operator ^= ( const char *pString );
friend IString
operator + ( const char *pString,
const IString &aString ),
operator & ( const char *pString,
const IString &aString ),
operator | ( const char *pString,
const IString &aString ),
operator ^ ( const char *pString,
const IString &aString );
/*------------------------------- Accessors ------------------------------------
| The following functions provide access to general information about the |
| string: |
| size - Returns the length of the string, not counting the |
| terminating null character. |
| length - Same as size. |
| subString - Returns a given substring of the receiver. |
| operator [] - Returns a reference to the nth character of the string. |
| NOTE: The non-const version of this function extends the |
| string if it is invoked with an index beyond the end. |
| charType - Returns the type of the character at the argument index. |
------------------------------------------------------------------------------*/
unsigned
size ( ) const,
length ( ) const;
IString
subString ( unsigned startPos ) const,
subString ( unsigned startPos,
unsigned length,
char padCharacter = ' ' ) const;
char
&operator [] ( unsigned index );
const char
&operator [] ( unsigned index ) const;
IStringEnum::CharType
charType ( unsigned index ) const;
/*------------------------------- Searching ------------------------------------
| The following functions permit searching the string in various ways: |
| indexOfAnyBut - Returns the index of the first character of the receiver |
| that is not in the argument set of characters; 0 is |
| returned if there are no characters. Alternatively, it |
| returns the index of the first character that fails the |
| test prescribed by an argument IStringTest object. |
| indexOfAnyOf - Returns the index of the first character of the receiver |
| that is a character in the argument set of characters; 0 |
| is returned if there are no characters. Alternatively, |
| it returns the index of the first character that passes |
| the test prescribed by an argument IStringTest object. |
| indexOf - Returns the index of the first occurrence of the |
| argument string within the receiver; 0 is returned if |
| there are no occurrences. The argument can also be a |
| single character or an IStringTest object. |
| occurrencesOf - Returns the number of occurrences of the argument |
| IString,char*,char,test. This is slower than indexOf if |
| you just want a Boolean test. |
| |
| You can specify an optional index that indicates where in the String the |
| search is to start. The default is to start at the beginning of the string. |
| |
| Each of the indexing functions also has a lastIndexOf version that returns |
| the index of the last character in the receiver IString that satisfies the |
| search criteria. These functions accept an optional argument that |
| specifies where the search is to begin. The default is to begin searching |
| at the end of the string. Searching proceeds from right to left for these |
| functions. |
| |
| lastIndexOf - Returns the index of the last occurrence of the |
| argument. |
| lastIndexOfAnyBut - Returns the index of the last character not in the |
| argument. |
| lastIndexOfAnyOf - Returns the index of the last character in the |
| argument. |
------------------------------------------------------------------------------*/
unsigned
indexOf ( const IString &aString,
unsigned startPos = 1 ) const,
indexOf ( const char *pString,
unsigned startPos = 1 ) const,
indexOf ( char aCharacter,
unsigned startPos = 1 ) const,
indexOf ( const IStringTest &aTest,
unsigned startPos = 1 ) const,
indexOfAnyBut ( const IString &validChars,
unsigned startPos = 1 ) const,
indexOfAnyBut ( const char *pValidChars,
unsigned startPos = 1 ) const,
indexOfAnyBut ( char validChar,
unsigned startPos = 1 ) const,
indexOfAnyBut ( const IStringTest &aTest,
unsigned startPos = 1 ) const,
indexOfAnyOf ( const IString &searchChars,
unsigned startPos = 1 ) const,
indexOfAnyOf ( const char *pSearchChars,
unsigned startPos = 1 ) const,
indexOfAnyOf ( char searchChar,
unsigned startPos = 1 ) const,
indexOfAnyOf ( const IStringTest &aTest,
unsigned startPos = 1 ) const,
lastIndexOf ( const IString &aString,
unsigned startPos = UINT_MAX ) const,
lastIndexOf ( const char *pString,
unsigned startPos = UINT_MAX ) const,
lastIndexOf ( char aCharacter,
unsigned startPos = UINT_MAX ) const,
lastIndexOf ( const IStringTest &aTest,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyBut ( const IString &validChars,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyBut ( const char *pValidChars,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyBut ( char validChar,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyBut ( const IStringTest &aTest,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyOf ( const IString &searchChars,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyOf ( const char *pSearchChars,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyOf ( char searchChar,
unsigned startPos = UINT_MAX ) const,
lastIndexOfAnyOf ( const IStringTest &aTest,
unsigned startPos = UINT_MAX ) const,
occurrencesOf ( const IString &aString,
unsigned startPos = 1 ) const,
occurrencesOf ( const char *pString,
unsigned startPos = 1 ) const,
occurrencesOf ( char aCharacter,
unsigned startPos = 1 ) const,
occurrencesOf ( const IStringTest &aTest,
unsigned startPos = 1 ) const;
/*-------------------------------- Editing -------------------------------------
| The following functions are used to edit the string. All return a |
| reference to the modified receiver. Many that are length related, such as |
| center and leftJustify, accept a pad character that defaults to a blank. |
| In all cases, argument strings can be specified as either objects of the |
| IString class or by using char*. |
| |
| Static functions by the same name can be applied to an IString to obtain |
| the modified IString without affecting the argument. For example: |
| |
| aString.change('\t', ' '); // Changes all tabs in aString to 3 blanks. |
| IString s = IString::change( aString, '\t', ' ' ); // Leaves aString as is.|
| |
| center - Centers the receiver within a string of the |
| specified length. |
| change - Changes occurrences of an argument pattern to an |
| argument replacement string. The number of changes |
| to perform can be specified. The default is to |
| change all occurrences of the pattern. You can |
| also specify the position in the receiver at which |
| to begin. |
| copy - Replaces the receiver's contents with a given |
| number of replications of itself. |
| remove - Deletes the specified substring from the receiver. |
| insert - Inserts an argument string at a given location. |
| leftJustify - Left-justifies the receiver in a string of the |
| specified length. |
| lowerCase - Translates all upper case letters in the receiver |
| to lower case. |
| overlayWith - Replaces a given portion of the receiver's contents |
| with an argument string. |
| reverse - Reverses the receiver's contents. |
| rightJustify - Right-justifies the receiver in a string of the |
| specified length. |
| strip - Strips both leading and trailing character or |
| characters; the character or characters can be |
| specified either as a single char, a String or |
| char* array, or with an IStringTest object. The |
| default is whitespace. |
| stripBlanks - Static function that strips both leading and |
| trailing whitespace. This function is the static |
| version of strip (renamed to avoid duplicate |
| definition). |
| stripLeading - Strips the leading character or characters. |
| stripLeadingBlanks - Static version of stripLeading (renamed to avoid |
| duplicate definition). |
| stripTrailing - Strips the trailing character or characters. |
| stripTrailingBlanks - Static version of stripTrailing (renamed to avoid |
| duplicate definition). |
| translate - Converts all of the receiver's characters that are |
| in one argument string to the corresponding |
| character in a second argument string. |
| upperCase - Translates all lower case letters in the receiver |
| to upper case. |
------------------------------------------------------------------------------*/
IString
¢er ( unsigned length,
char padCharacter = ' ' ),
&change ( const IString &inputString,
const IString &outputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
&change ( const IString &inputString,
const char *pOutputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
&change ( const char *pInputString,
const IString &outputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
&change ( const char *pInputString,
const char *pOutputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
© ( unsigned numCopies ),
&insert ( const IString &aString,
unsigned index = 0,
char padCharacter = ' ' ),
&insert ( const char *pString,
unsigned index = 0,
char padCharacter = ' ' ),
&leftJustify ( unsigned length,
char padCharacter = ' ' ),
&lowerCase ( ),
&overlayWith ( const IString &aString,
unsigned index = 1,
char padCharacter = ' ' ),
&overlayWith ( const char *pString,
unsigned index = 1,
char padCharacter = ' ' ),
&remove ( unsigned startPos ),
&remove ( unsigned startPos,
unsigned numChars ),
&reverse ( ),
&rightJustify ( unsigned length,
char padCharacter = ' ' ),
&strip ( ),
&strip ( char aCharacter ),
&strip ( const IString &aString ),
&strip ( const char *pString ),
&strip ( const IStringTest &aTest ),
&stripLeading ( ),
&stripLeading ( char aCharacter ),
&stripLeading ( const IString &aString ),
&stripLeading ( const char *pString ),
&stripLeading ( const IStringTest &aTest ),
&stripTrailing ( ),
&stripTrailing ( char aCharacter ),
&stripTrailing ( const IString &aString ),
&stripTrailing ( const char *pString ),
&stripTrailing ( const IStringTest &aTest ),
&translate ( const IString &inputChars,
const IString &outputChars,
char padCharacter = ' ' ),
&translate ( const IString &inputChars,
const char *pOutputChars,
char padCharacter = ' ' ),
&translate ( const char *pInputChars,
const IString &outputChars,
char padCharacter = ' ' ),
&translate ( const char *pInputChars,
const char *pOutputChars,
char padCharacter = ' ' ),
&upperCase ( );
static IString
center ( const IString &aString,
unsigned length,
char padCharacter = ' ' ),
change ( const IString &aString,
const IString &inputString,
const IString &outputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
change ( const IString &aString,
const IString &inputString,
const char *pOutputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
change ( const IString &aString,
const char *pInputString,
const IString &outputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
change ( const IString &aString,
const char *pInputString,
const char *pOutputString,
unsigned startPos = 1,
unsigned numChanges = UINT_MAX ),
copy ( const IString &aString,
unsigned numCopies ),
insert ( const IString &aString,
const IString &anInsert,
unsigned index = 0,
char padCharacter = ' ' ),
insert ( const IString &aString,
const char *pInsert,
unsigned index = 0,
char padCharacter = ' ' ),
leftJustify ( const IString &aString,
unsigned length,
char padCharacter = ' ' ),
lowerCase ( const IString &aString ),
overlayWith ( const IString &aString,
const IString &anOverlay,
unsigned index = 1,
char padCharacter = ' ' ),
overlayWith ( const IString &aString,
const char *pOverlay,
unsigned index = 1,
char padCharacter = ' ' ),
remove ( const IString &aString,
unsigned startPos ),
remove ( const IString &aString,
unsigned startPos,
unsigned numChars ),
reverse ( const IString &aString ),
rightJustify ( const IString &aString,
unsigned length,
char padCharacter = ' ' ),
stripBlanks ( const IString &aString ),
strip ( const IString &aString,
char aChar ),
strip ( const IString &aString,
const IString &aStringOfChars ),
strip ( const IString &aString,
const char *pStringOfChars ),
strip ( const IString &aString,
const IStringTest &aTest ),
stripLeadingBlanks ( const IString &aString ),
stripLeading ( const IString &aString,
char aChar ),
stripLeading ( const IString &aString,
const IString &aStringOfChars ),
stripLeading ( const IString &aString,
const char *pStringOfChars ),
stripLeading ( const IString &aString,
const IStringTest &aTest ),
stripTrailingBlanks ( const IString &aString ),
stripTrailing ( const IString &aString,
char aChar ),
stripTrailing ( const IString &aString,
const IString &aStringOfChars ),
stripTrailing ( const IString &aString,
const char *pStringOfChars ),
stripTrailing ( const IString &aString,
const IStringTest &aTest ),
translate ( const IString &aString,
const IString &inputChars,
const IString &outputChars,
char padCharacter = ' ' ),
translate ( const IString &aString,
const IString &inputChars,
const char *pOutputChars,
char padCharacter = ' ' ),
translate ( const IString &aString,
const char *pInputChars,
const IString &outputChars,
char padCharacter = ' ' ),
translate ( const IString &aString,
const char *pInputChars,
const char *pOutputChars,
char padCharacter = ' ' ),
upperCase ( const IString &aString );
/*----------------------------- Word Functions ---------------------------------
| The following functions operate on the string as a collection of words |
| separated by whitespace characters: |
| |
| indexOfPhrase - Returns the position of the first occurrence of the |
| argument phrase in the receiver. Returns 0 if the |
| phrase is not found. |
| indexOfWord - Returns the index of the nth whitespace-delimited |
| word in the receiver. Returns 0 if the word is not |
| found. |
| lengthOfWord - Returns the length of the nth whitespace-delimited |
| word in the receiver. |
| numWords - Returns the number of whitespace-delimited words in |
| the receiver. |
| removeWords - Deletes the specified words from the receiver's |
| contents; the words are specified by using a starting |
| word number and the number of words. The latter |
| defaults to the rest of the string. |
| NOTE: The static functions space and removeWords |
| obtain the same result, but do not affect the |
| String to which they are applied. |
| space - Modifies the receiver so that all words are separated |
| by the specified number of blanks. The default is |
| one blank. All whitespace is converted to simple |
| blanks. |
| NOTE: The static functions space and removeWords |
| obtain the same result, but do not affect the |
| String to which they are applied. |
| word - Returns a copy of the nth whitespace-delimited word |
| in the receiver. |
| wordIndexOfPhrase - Returns the word number of the first word in the |
| receiver that matches the argument phrase. It starts |
| searching with the word number in the startWord |
| argument, which defaults to 1. It returns 0 if the |
| phrase is not found. |
| words - Returns a substring of the receiver that starts at a |
| given word and is comprised of a given number of |
| words; the word separators are copied to the result |
| intact. |
------------------------------------------------------------------------------*/
IString
&removeWords ( unsigned firstWord ),
&removeWords ( unsigned firstWord,
unsigned numWords ),
&space ( unsigned numSpaces = 1,
char spaceChar = ' ' ),
word ( unsigned wordNumber ) const,
words ( unsigned firstWord ) const,
words ( unsigned firstWord,
unsigned numWords ) const;
unsigned
indexOfPhrase ( const IString &wordString,
unsigned startWord = 1 ) const,
indexOfWord ( unsigned wordNumber ) const,
lengthOfWord ( unsigned wordNumber ) const,
numWords ( ) const,
wordIndexOfPhrase ( const IString &aPhrase,
unsigned startWord = 1 ) const;
static IString
space ( const IString &aString,
unsigned numSpaces = 1,
char spaceChar = ' ' ),
removeWords ( const IString &aString,
unsigned startWord ),
removeWords ( const IString &aString,
unsigned startWord,
unsigned numWords );
protected:
/*------------------------------ Related Types ---------------------------------
The following enumeration types are defined to pass "modes" to various
implementation functions:
BitOperator - Enumeration that specifies the bit operator to apply to the
applyBitOp function. Valid bit operators are 'and', 'or',
and 'exclusiveOr'.
IndexType - Enumeration that specifies whether the result from the
findPhrase function is a word index or a character index.
The valid values are:
charIndex - Returns the result as the byte index within
the string.
wordIndex - Returns the result as the index of the
matching word. For example, the first word
is 1, the second word is 2, and so forth.
------------------------------------------------------------------------------*/
typedef enum
{
and,
or,
exclusiveOr
} BitOperator;
typedef enum
{
charIndex,
wordIndex
} IndexType;
/*--------------------------- Static Data Members ------------------------------
The following are static data members:
null - A string that contains no element.
zero - The number 0.
maxLong - The maximum value of a long, which is "2147483647" on
OS/2 with 32-bit unsigned long integers.
nullBuffer - A pointer to the null buffer's contents.
------------------------------------------------------------------------------*/
static const char
*null,
*zero,
*maxLong;
static char
*nullBuffer;
/*------------------------------ Implementation --------------------------------
The following functions are used to implement this class:
data - Returns the address of the contents of the IString.
setBuffer - Sets the private data member to point to a new IBuffer
object.
buffer - Returns the address of the IBuffer referred to by this
IString.
lengthOf - Returns the length of a plain C character array.
initBuffer - Resets the contents from an argument buffer or buffers.
defaultBuffer - Returns a pointer to the contents of the nullBuffer data
member.
The following are common implementations of various overloaded versions
of similarly named public functions:
occurrencesOf - See IString::occurrencesOf.
isLike - See IString::isLike.
isAbbrevFor - See IString::isAbbrevFor.
change - See IString::change.
insert - See IString::insert.
overlayWith - See IString::overlayWith.
strip - See IString::strip.
translate - See IString::translate.
indexOfWord - See IString::indexOfWord.
The following are used to implement various public functions of this class:
applyBitOp - Implements bitwise operators &, |, and ^.
findPhrase - Locates a given string of words for indexOfWord functions.
------------------------------------------------------------------------------*/
char
*data ( ) const;
IBuffer
*buffer ( ) const;
static unsigned
lengthOf ( const char *p );
static char
*defaultBuffer ( );
IString
&setBuffer ( IBuffer *ibuff ),
&initBuffer ( const void *p1,
unsigned len1,
const void *p2 = 0,
unsigned len2 = 0,
const void *p3 = 0,
unsigned len3 = 0,
char padChar = 0 ),
&initBuffer ( long n ),
&initBuffer ( unsigned long n ),
&initBuffer ( double d ),
&applyBitOp ( const char *pArg,
unsigned argLen,
BitOperator op ),
&change ( const char *pPattern,
unsigned patternLen,
const char *pReplacement,
unsigned replacementLen,
unsigned startPos,
unsigned numChanges ),
&insert ( const char *pInsert,
unsigned insertLen,
unsigned startPos,
char padCharacter ),
&overlayWith ( const char *pOverlay,
unsigned overlayLen,
unsigned index,
char padCharacter ),
&strip ( const char *p,
unsigned len,
IStringEnum::StripMode mode ),
&strip ( const IStringTest &aTest,
IStringEnum::StripMode mode ),
&translate ( const char *pInputChars,
unsigned inputLen,
const char *pOutputChars,
unsigned outputLen,
char padCharacter );
unsigned
indexOfWord ( unsigned wordNumber,
unsigned startPos,
unsigned numWords ) const,
occurrencesOf ( const char *pSearchString,
unsigned searchLen,
unsigned startPos ) const,
findPhrase ( const IString &aPhrase,
unsigned startWord,
IndexType charOrWord ) const;
Boolean
isLike ( const char *pPattern,
unsigned patternLen,
char zeroOrMore,
char anyChar ) const,
isAbbrevFor ( const char *pFullString,
unsigned fullLen,
unsigned minLen ) const;
private: /*------------------------ PRIVATE ----------------------------------*/
IString ( IBuffer *pBuffer );
void
binaryMath ( unsigned char newDigit ),
decimalMath ( unsigned char newDigit );
IString
&prepareToChange();
static void
setDefaultBuffer( char * );
char
*pBuffer;
friend class IBuffer;
}; // class IString
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <istring.inl>
#endif
#endif /* _ISTRING_ */