home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
I0STRING.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
18KB
|
358 lines
#ifndef _I0STRING_
#define _I0STRING_
/*******************************************************************************
* FILE NAME: i0string.hpp *
* *
* DESCRIPTION: *
* This file contains the declaration(s) of the class(es): *
* I0String - Derivative of class IString supporting 0-based indexing. *
* *
* 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. *
* *
*******************************************************************************/
#ifndef _ISTRING_
#include <istring.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class IStringTest;
class I0String : public IString {
/*******************************************************************************
* Objects of this class are functionally equivalent to objects of class *
* IString with one major distinction: I0Strings are indexed starting at *
* 0 instead of 1. *
* *
* This class is intended to be used by programmers more comfortable with *
* such an indexing scheme. Note that a consequence of starting indices at *
* 0 means that the search functions no longer can be used as if they *
* were Boolean. That is: *
* *
* a0String.indexOf( anotherString ) != a0String.includes( anotherString ). *
* *
* IStrings and I0Strings can be freely intermixed in a program. Objects of *
* one class can be assigned values of the other type. Objects of either *
* class can be passed as arguments to functions requiring the other type. *
* *
* See the descriptions for class IString in ISTRING.HPP *
* *
* WARNING: UINT_MAX is a reserved value for I0String. Unpredictable results *
* can occur if used for the startPos argument in I0String functions. *
*******************************************************************************/
public:
/*------------------------------- Constructors ---------------------------------
You can construct instances of this class in the following ways:
1. Construct a null string.
2. Construct a string with the ASCII representation of a given numeric
value, supporting all flavors of int and double.
3. Construct a string with a copy of the given character data, supporting
ASCIIZ strings, characters, and I0Strings.
4. 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 I0String contents are initialized to a
given pad character. The default is a blank.
------------------------------------------------------------------------------*/
I0String ( );
I0String ( const IString &aString );
I0String ( int );
I0String ( unsigned );
I0String ( long );
I0String ( unsigned long );
I0String ( short );
I0String ( unsigned short );
I0String ( double );
I0String ( char );
I0String ( unsigned char );
I0String ( signed char );
I0String ( const char * );
I0String ( const unsigned char * );
I0String ( const signed char * );
I0String ( const void *pBuffer1,
unsigned lenBuffer1,
char padCharacter = ' ' );
I0String ( const void *pBuffer1,
unsigned lenBuffer1,
const void *pBuffer2,
unsigned lenBuffer2,
char padCharacter = ' ' );
I0String ( const void *pBuffer1,
unsigned lenBuffer1,
const void *pBuffer2,
unsigned lenBuffer2,
const void *pBuffer3,
unsigned lenBuffer3,
char padCharacter = ' ' );
/*------------------------------- Accessors ------------------------------------
| These functions are overridden to permit specification of the index |
| as a 0-based value: |
| 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. |
------------------------------------------------------------------------------*/
I0String
subString ( unsigned startPos ) const,
subString ( unsigned startPos,
unsigned len,
char padCharacter = ' ' ) const;
char
&operator [] ( unsigned index );
const char
&operator [] ( unsigned index ) const;
IStringEnum::CharType
charType ( unsigned index ) const;
/*------------------------------- Searching ------------------------------------
| These functions are re-implemented to treat the starting position of the |
| search as a 0-based index. |
| 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. |
| 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 proscribed 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 proscribed by an |
| argument IStringTest object. |
| 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. |
| occurrencesOf - Returns the number of occurrences of the argument |
| 'I0String,char*,char,test'. This is slower than |
| 'indexOf' if you just want a Boolean test. |
------------------------------------------------------------------------------*/
unsigned
indexOf ( const IString &aString,
unsigned startPos = 0 ) const,
indexOf ( const char *pString,
unsigned startPos = 0 ) const,
indexOf ( char aCharacter,
unsigned startPos = 0 ) const,
indexOf ( const IStringTest &aTest,
unsigned startPos = 0 ) const,
indexOfAnyBut ( const IString &aString,
unsigned startPos = 0 ) const,
indexOfAnyBut ( const char *pValidChars,
unsigned startPos = 0 ) const,
indexOfAnyBut ( char validChar,
unsigned startPos = 0 ) const,
indexOfAnyBut ( const IStringTest &aTest,
unsigned startPos = 0 ) const,
indexOfAnyOf ( const IString &searchChars,
unsigned startPos = 0 ) const,
indexOfAnyOf ( const char *pSearchChars,
unsigned startPos = 0 ) const,
indexOfAnyOf ( char searchChar,
unsigned startPos = 0 ) const,
indexOfAnyOf ( const IStringTest &aTest,
unsigned startPos = 0 ) const,
lastIndexOf ( const IString &aString,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOf ( const char *pString,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOf ( char aCharacter,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOf ( const IStringTest &aTest,
unsigned startPos = UINT_MAX-1 ) const,
lastIndexOfAnyBut ( const IString &validChars,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOfAnyBut ( const char *pValidChars,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOfAnyBut ( char validChar,
unsigned startPos = UINT_MAX-1 ) const,
lastIndexOfAnyBut ( const IStringTest &aTest,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOfAnyOf ( const IString &searchChars,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOfAnyOf ( const char *pSearchChars,
unsigned endPos = UINT_MAX-1 ) const,
lastIndexOfAnyOf ( char searchChar,
unsigned startPos = UINT_MAX-1 ) const,
lastIndexOfAnyOf ( const IStringTest &aTest,
unsigned endPos = UINT_MAX-1 ) const,
occurrencesOf ( const IString &aString,
unsigned startPos = 0 ) const,
occurrencesOf ( const char *pString,
unsigned startPos = 0 ) const,
occurrencesOf ( char aCharacter,
unsigned startPos = 0 ) const,
occurrencesOf ( const IStringTest &aTest,
unsigned startPos = 0 ) const;
/*-------------------------------- Editing -------------------------------------
| These editing functions are re-implemented to treat the position |
| arguments as 0-based: |
| 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. |
| insert - Inserts an argument string at a given location. |
| overlayWith - Replaces a given portion of the receiver's contents |
| with an argument string. |
| remove - Deletes the specified substring from the receiver. |
------------------------------------------------------------------------------*/
I0String
&change ( const IString &aPattern,
const IString &aReplacement,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
&change ( const IString &aPattern,
const char *pReplacement,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
&change ( const char *pPattern,
const IString &aReplacement,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
&change ( const char *pPattern,
const char *pReplacement,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
&insert ( const IString &aString,
unsigned index = UINT_MAX,
char padCharacter = ' ' ),
&insert ( const char *pString,
unsigned index = UINT_MAX,
char padCharacter = ' ' ),
&overlayWith ( const IString &aString,
unsigned index = 0,
char padCharacter = ' ' ),
&overlayWith ( const char *pString,
unsigned index = 0,
char padCharacter = ' ' ),
&remove ( unsigned startPos ),
&remove ( unsigned startPos,
unsigned numChars );
static I0String
change ( const IString &aString,
const IString &inputString,
const IString &outputString,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
change ( const IString &aString,
const IString &inputString,
const char *pOutputString,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
change ( const IString &aString,
const char *pInputString,
const IString &outputString,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
change ( const IString &aString,
const char *pInputString,
const char *pOutputString,
unsigned startPos = 0,
unsigned numChanges = UINT_MAX ),
insert ( const IString &aString,
const IString &anInsert,
unsigned index = UINT_MAX,
char padCharacter = ' ' ),
insert ( const IString &aString,
const char *pInsert,
unsigned index = UINT_MAX,
char padCharacter = ' ' ),
overlayWith ( const IString &aString,
const IString &anOverlay,
unsigned index = 0,
char padCharacter = ' ' ),
overlayWith ( const IString &aString,
const char *pOverlay,
unsigned index = 0,
char padCharacter = ' ' ),
remove ( const IString &aString,
unsigned startPos ),
remove ( const IString &aString,
unsigned startPos,
unsigned numChars );
/*----------------------------- Word Functions ---------------------------------
| These two word search functions are re-implemented to treat the result |
| index as 0-based. |
| indexOfPhrase - Returns the position of the first occurrence of the |
| argument phrase in the receiver. |
| indexOfWord - Returns the index of the nth whitespace-delimited |
| word in the receiver. |
------------------------------------------------------------------------------*/
unsigned
indexOfPhrase ( const IString &wordString,
unsigned startWord = 1 ) const,
indexOfWord ( unsigned wordNumber ) const;
/*----------------------------- Class Constants --------------------------------
| The following static function can be used in conjunction with the searching
| functions:
| notFound - Specifies the value returned by searching functions to indicate |
| that the search failed. |
------------------------------------------------------------------------------*/
static const unsigned
notFound;
protected:
/*------------------------------ Implementation --------------------------------
| These functions provide various utilities used to implement this class: |
| adjustArg - Adjusts an argument index from 0- to 1-based. |
| adjustResult - Adjusts a function result from 1- to 0-based. |
------------------------------------------------------------------------------*/
static unsigned
adjustArg ( unsigned index ),
adjustResult ( unsigned index );
private: /*------------------------ PRIVATE ----------------------------------*/
}; // class I0String
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <i0string.inl>
#endif
#endif /* _I0STRING_ */