NewData.hxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:9k
- #ifndef NEWDATA_HXX_
- #define NEWDATA_HXX_
- /* ====================================================================
- * The Vovida Software License, Version 1.0
- *
- * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The names "VOCAL", "Vovida Open Communication Application Library",
- * and "Vovida Open Communication Application Library (VOCAL)" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact vocal@vovida.org.
- *
- * 4. Products derived from this software may not be called "VOCAL", nor
- * may "VOCAL" appear in their name, without prior written
- * permission of Vovida Networks, Inc.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
- * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
- * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
- * IN EXCESS OF $1,000, NOR FOR ANY 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.
- *
- * ====================================================================
- *
- * This software consists of voluntary contributions made by Vovida
- * Networks, Inc. and many individuals on behalf of Vovida Networks,
- * Inc. For more information on Vovida Networks, Inc., please see
- * <http://www.vovida.org/>.
- *
- */
- static const char* const NewData_hxx_Version =
- "$Id: NewData.hxx,v 1.12 2001/04/27 01:11:56 bko Exp $";
- //Authors: Sunitha Kumar, Cullen Jennings
- #if defined (__SUNPRO_CC)
- #define USE_HASH_MAP 0
- #else
- #define USE_HASH_MAP 1
- #endif
- #include <cstring>
- #include <string>
- #include "mstring.hxx"
- #include "VException.hxx"
- #include "DataException.hxx"
- /** This will eventually implemented the copy on write, reference
- counted smart buffer scheme
- */
- class NewData
- {
- public:
- static const int npos = INT_MAX;
- // creation members.
- ///
- //Data( const string& str);
- ///
- NewData( );
- ///
- NewData( const char* str );
- ///
- NewData( const char* buffer, int length );
- ///
- NewData( const NewData& data );
- ///
- NewData( const string& str);
- ///
- NewData( const mstring& mstr);
- ///
- NewData( const int value);
- ///
- ~NewData();
- ///
- bool operator>(const NewData& ) const ;
- ///
- bool operator<(const NewData& ) const;
- ///
- NewData& operator=(const char* str);
- ///
- NewData& operator=(const NewData& data);
- ///
- //Data& operator=(const string& str);
- /// getData returns a NUL terminated (e.g. a C string) buffer
- const char* getData() const;
- /** getDataBuf differs from getData in that the resultant buffer is NOT
- NUL terminated */
- const char* getDataBuf() const;
- ///
- //void substr( int start, int length , char* str) const;
- //char* substr( int start, int length ) const;
- ///
- char getChar( int i ) const; //return the i'th char of string.
- ///
- void setchar( int i, char c ); //write to the i'th char of string.
- ///
- char operator[]( int i ); //return the i'th char of string.
- ///
- int length() const;
- ///
- bool operator==( const char* str ) const;
- ///
- bool operator==( const NewData& data ) const;
- ///
- //bool operator==(const string& second );
- ///
- bool operator!=( const char* str ) const;
- ///
- bool operator!=( const NewData& data ) const;
- /// friend to compare a c-style string to a data (avoids conversion)
- friend bool operator==( const char* str, const NewData& d );
- /// friend to compare a c-style string to a data (avoids conversion)
- friend bool operator!=( const char* str, const NewData& d );
- ///
- int compare(const char* str, int length) const;
- ///
- int compare(const NewData& data) const;
- ///
- int compareNoCase(const char* str, int length) const;
- ///
- int compareNoCase(const NewData& data) const;
- ///
- NewData operator+( const NewData& data) const;
- ///
- NewData operator+( const char* str) const;
- //modification members
- ///
- void operator+=(const NewData&);
- ///
- void operator+=(const char*);
- ///
- void erase();
- /// convert Data to uppercase
- void lowercase();
- /// convert Data to lowercase
- void uppercase();
- // conversion operators
- ///
- operator string() const;
- ///
- operator const char*() const;
- ///
- operator mstring() const;
- ///
- operator int() const;
- /** match the string and return the text prior to the match.
- * If a match is found, this Data is set to the remainder
- * after the matched string.
- *
- * @param match the string to be matched
- * @param beforeMatch the data before the matched string
- * @param replace whether to replace the matched data
- * @param replaceWith the data to replace the matched data
- */
- int match(const char* match,
- NewData* data,
- bool replace = false,
- NewData replaceWith = "");
- /**
- match (and eat) the first contiguous block composed of the
- characters in match, which is outside of double quotes <">
- and angle brackets "<" and ">". Returned is the data
- before the matched characters. If no characters match,
- return the empty Data. If matchFail is set to a bool ptr,
- the bool *matchFail will be set to true if the match
- fails, and false otherwise.
- This is designed for use in separating a list of
- parameters at the commas (e.g. Contact:)
- */
- NewData parseOutsideQuotes(const char* match,
- bool useQuote,
- bool useAngle,
- bool* matchFail = 0 );
- /**
- match (and eat) the first contiguous block composed of the
- characters in match. Returned is the data before the
- matched characters. If no characters match, return the
- empty Data. If matchFail is set to a bool ptr, the bool
- *matchFail will be set to true if the match fails, and
- false otherwise.
- */
- NewData parse(const char* match, bool* matchFail = 0 );
- /** match (and eat) any one of the characters in match. If
- matchedChar points to a char, it will be set to the
- matching character, or