/***************************************************************************** # Copyright (C) 1994-2008 by David Gordon. # All rights reserved. # # This software is part of a beta-test version of the Consed/Autofinish # package. It should not be redistributed or # used for any commercial purpose, including commercially funded # sequencing, without written permission from the author and the # University of Washington. # # This software is provided ``AS IS'' and any express or implied # warranties, including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose, are disclaimed. # In no event shall the authors or the University of Washington be # liable for any direct, indirect, incidental, special, exemplary, or # consequential damages (including, but not limited to, procurement of # substitute goods or services; loss of use, data, or profits; or # business interruption) however caused and on any theory of liability, # whether in contract, strict liability, or tort (including negligence # or otherwise) arising in any way out of the use of this software, even # if advised of the possibility of such damage. # # Building Consed from source is error prone and not simple which is # why I provide executables. Due to time limitations I cannot # provide any assistance in building Consed. Even if you do not # modify the source, you may introduce errors due to using a # different version of the compiler, a different version of motif, # different versions of other libraries than I used, etc. For this # reason, if you discover Consed bugs, I can only offer help with # those bugs if you first reproduce those bugs with an executable # provided by me--not an executable you have built. # # Modifying Consed is also difficult. Although Consed is modular, # some modules are used by many other modules. Thus making a change # in one place can have unforeseen effects on many other features. # It may takes months for you to notice these other side-effects # which may not seen connected at all. It is not feasable for me to # provide help with modifying Consed sources because of the # potentially huge amount of time involved. # #*****************************************************************************/ #ifndef __RWCSTRING_H_ #define __RWCSTRING_H_ #ifndef WALRUS_BUILD #include #endif #include using namespace std; #include "bool.h" #include "rwdefs.h" class RWCSubString; class RWCRegexp; const int nDefaultMaxLength = 0; const float fDefaultResizeIncrement = 3.0; const float fDefaultInitialAdditionalFactor = 1.0; // remove temporarily until I've removed all of Rogue Wave typedef size_t RWSize_2T; // when I've removed all rogue wave, then I can remove this //#include // This allows us to call data() for a null RWCString and not get // a segmentation fault by the caller const char cCaseInsensitive = 'i'; const char cCaseSensitive = 's'; class RWCString { public: // ctors ~RWCString(); RWCString(); RWCString( const char c ); RWCString( const char* sz ); RWCString( const char* sz, size_t nNumberOfBytes ); RWCString( const char c, size_t nNumberOfCopies ); RWCString( const RWCString& so); RWCString( const size_t nMaxLength ); RWCString( const RWCSubString& sub ); RWCString( const long lNumberToConvert ); RWCString( const double dNumberToConvert, const int nPrecision = 6 ); // member functions and operators void append( const char* szStringToAppend ); void append( const RWCString& soStringToAppend ); void append( const char cCharToAppend ); void appendLotsOfCopies( const char cCharToAppend, const size_t nNumberOfCopies ); void appendFormat( const char *format, ... ); bool bContains( const RWCRegexp& regPattern ) const; bool bContains( const RWCString& soPattern, const char cCaseSensitivity = cCaseSensitive ) const; bool bContains( const char* sz ) const; bool bContainsAndRemoveToEnd( const RWCString& soLookForThis ); bool bContainsChar( const char c ) const; bool bContainsOnlyTheseCharacters( const RWCString& so ) const; bool bIsWhitespace(); bool bIsNull() const { return isNull(); } bool bStartsWith( const RWCString& soStartsWithThis ); bool bStartsWithAndRemove( const RWCString& soStartsWithThis ); bool bEndsWith( const RWCString& soEndsWithThis ); bool bEndsWithAndRemove( const RWCString& soEndsWithThis ); bool bStartsWithCaseInsensitive( const RWCString& soStartsWithThis ) const; size_t capacity( const size_t capac ) { increaseMaxLength( capac ); return( nMaxLength_ ); } char cGetLastChar() { if ( nCurrentLength_ == 0 ) return( 0 ); else return( sz_[ nCurrentLength_ - 1 ] ); } char cGetLastChar( const int nChar ); // this is to be like perl, where -1 is the last char, -2 is the // next to last, etc. // Rogue Wave used const char* but I was always (char*) to use it. char* data() const { static char szEmpty = '\0'; if ( sz_ ) return sz_; else return( &szEmpty ); } size_t first( char c ) const; void getField( char* pCharacterField, const int nLength ); void increaseButNotDecreaseMaxLength( const size_t nRequestedMaxLength ); void increaseMaxLength( const size_t nRequestedMaxLength ); void increaseMaxLengthIfNecessary( const size_t nExtraRoomNeeded ); // index finds the position within self of pattern // the start position is within self size_t index( const char* szPattern, const size_t nStartPosition = 0 ) const; size_t index( const char* szPattern, const size_t nPatternLength, const size_t nStartPosition ) const; size_t index( const RWCString& soPattern, const size_t nStartPosition = 0 ) const; // had to put the "2" because it couldn't be distinguished from // size_t index( const char* szPattern, const size_t nPatternLength, // const size_t nStartPosition ) const; size_t index2( const RWCString& soPattern, const size_t nStartPosition, const char cCaseSensitivity ) const; size_t index( const RWCRegexp& regPattern ) const; void insert( size_t nInsertBeforeThisPosition, const char* szToInsert ); bool isNull() const { if ( nCurrentLength_ == 0 ) return( true ); else return( false ); } size_t last( char c) const; int length() const { return( nCurrentLength_ ); } int nGetNumberOfCopiesOfChar( const char c ); int nGetNumberOfLinesOfText(); void operator=( char* sz ); void operator=( const RWCString& so ); RWCString& operator=( const RWCSubString& sub ); const RWCSubString operator()( size_t nStart, size_t nLength ) const; // version of subscripting operator that doesn't check the subscript inline char operator()( const size_t nPos ) const { return( sz_[ nPos ] ); } char operator[]( const size_t nPos ) const; char& operator[]( size_t nPos ); #ifdef INT_CHAR_OPERATOR char operator[]( const int nPos ) const; char& operator[]( int nPos ); #endif operator const char*() const; operator char*() const; // was RWCString& in Rogue Wave void operator+=( const RWCString& so ); RWCSubString operator()( const RWCRegexp& re ) const; RWCString soGetRestOfString( const size_t nStart ) const; // same as above, except parameter is the number of chars // to return rather than the position to start returning // chars RWCString soGetLastPart( const size_t nNumberOfChars ) const; // similar to soGetLastPart but modifies the object rather than // returning another void keepOnlyLastPartOfString( const size_t nNumberOfCharsToKeep ); RWCString soGetNextToken( size_t& nCurrentStringPosition ); void getNextToken( size_t& nCurrentStringPosition, RWCString& soToken ); void pad( const size_t nLength ); void padOnLeft( const size_t nLength ); // warning--puts "..." if it is truncated RWCString soPadOrTruncate( const size_t nLength ) const; istream& readLine( istream& iStream, bool bSkipWhite = true ); istream& readToDelim( istream& iStream, char cDelim = '\n' ); istream& readToken( istream& iStream ); // remove from nPos to the end of the string RWCString& remove( size_t nPos ); RWCString& remove( size_t nPositionToStartRemoving, size_t nLengthToRemove ); void removeAllCommas(); void removeSingleCharacterAllOccurrences( char cToRemove ); RWCString soRemoveFinalBases( const int nBasesToRemove ); void removeFinalCR(); void removeLastChar(); void removeLeadingKeyword( const RWCString& soKeyword ); // note: increases nCurrentLength_ and additional characters // will be garbage // What you probably want is increaseMaxLength // void resize( const size_t nRequestedMaxLength ); void replace( const size_t nPositionToStartReplacing, const RWCString& soReplacementString ); RWCString returnToLower(); RWCString returnToUpper(); void reverse(); void setBaseUnsafe( const int nPos, const char c ); void sortLetters(); enum stripType { LEADING = 0x1, TRAILING = 0x2, BOTH = 0x3 }; RWCSubString strip( stripType s = TRAILING, char c = ' '); void stripTrailingWhitespaceFast(); RWCSubString stripWhitespace( stripType s = TRAILING ); void stripAllWhitespaceIncludingInternal(); void stripAllWhitespaceExceptInternal(); void substitute( const RWCRegexp& regexp, const RWCString& soReplacement, const bool bAll ); void toLower(); void toUpper(); void translate( const RWCString& soOldCharacters, const RWCString& soNewCharacters ); void truncate( const size_t nLength ); public: char* sz_; // largest string length that can be accommodated // the actual buffer is 1 greater, for storing the 0 int nMaxLength_; int nCurrentLength_; }; #include "rwcsubstring.h" // global operators RWCString operator+( const RWCString& so1, const RWCString& so2 ); RWCString operator+( const RWCString& so1, const char* sz2 ); RWCString operator+( const RWCString& so1, const int n ); RWCString operator+( const char* sz1, const RWCString& so2 ); ostream& operator<<(ostream& oStream, const RWCString& so ); istream& operator>>(istream& iStream, RWCString& so ); bool operator==( const RWCString& so1, const RWCString& so2 ); bool operator==( const RWCString& so1, const char* sz2 ); bool operator==( const char* sz1, const RWCString& so2 ); bool operator%( const RWCString& so1, const RWCString& so2 ); bool operator%( const RWCString& so1, const char* sz2 ); bool operator%( const char* sz1, const RWCString& so2 ); bool operator!=( const char* sz1, const RWCString& so2 ); bool operator!=( const RWCString& so1, const char* sz2 ); bool operator!=( const RWCString& so1, const RWCString& so2 ); bool operator<( const RWCString& so1, const RWCString& so2 ); bool operator<( const char* sz1, const RWCString& so2 ); bool operator<( const RWCString& so1, const char* sz2 ); bool operator>( const RWCString& so1, const RWCString& so2 ); bool operator>( const char* sz1, const RWCString& so2 ); bool operator>( const RWCString& so1, const char* sz2 ); bool operator<=( const RWCString& so1, const RWCString& so2 ); bool operator<=( const char* sz1, const RWCString& so2 ); bool operator<=( const RWCString& so1, const char* sz2 ); bool operator>=( const RWCString& so1, const RWCString& so2 ); bool operator>=( const char* sz1, const RWCString& so2 ); bool operator>=( const RWCString& so1, const char* sz2 ); int nCompareRWCStringsForQSort( const RWCString* pString1, const RWCString* pString2 ); #endif