[Cppunit-cvs] cppunit2/include/cpptl conststring.h,1.5,1.6 conststring.py,1.1,1.2 stringtools.h,1.7,
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-07-02 20:27:49
|
Update of /cvsroot/cppunit/cppunit2/include/cpptl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14915/include/cpptl Modified Files: conststring.h conststring.py stringtools.h Log Message: * Added a simple test runner that does not rely on the open test framework to run cppunit2 tests. * added CppTL::ConstCharView to wrapper const char *strings. * added CppTL::quoteMultiLineString() * string assertion output actual and expected using quoteMultiLineString(). * added serialize unit test for basic Properties * opentest tests now use the LightTestRunner. Index: conststring.py =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/conststring.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** conststring.py 27 Feb 2005 09:53:20 -0000 1.1 --- conststring.py 2 Jul 2005 20:27:35 -0000 1.2 *************** *** 6,10 **** csz = 'const char *' std_string = 'const std::string &' ! types = [ csz, "const CppTL::ConstString &", "const CppTL::StringConcatenator &", "const CppTL::StringBuffer &" ] for left in xrange(0,len(types)): start = (left == 0) and 1 or 0 --- 6,10 ---- csz = 'const char *' std_string = 'const std::string &' ! types = [ csz, "const CppTL::ConstString &", "const CppTL::StringConcatenator &", "const CppTL::StringBuffer &", "const CppTL::ConstCharView &" ] for left in xrange(0,len(types)): start = (left == 0) and 1 or 0 Index: conststring.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/conststring.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** conststring.h 28 Feb 2005 20:32:35 -0000 1.5 --- conststring.h 2 Jul 2005 20:27:35 -0000 1.6 *************** *** 12,15 **** --- 12,77 ---- namespace CppTL { + class ConstCharView + { + public: + typedef unsigned int size_type; + typedef char value_type; + + ConstCharView() + : begin_( "" ) + , end_( begin_ ) + { + } + + ConstCharView( const value_type *czstr ) + : begin_( czstr ) + { + CPPTL_ASSERT_MESSAGE( czstr != 0, "Invalid zero terminated string" ); + end_ = begin_ + strlen( begin_ ); + } + + ConstCharView( const value_type *cbegin, size_type length ) + : begin_( cbegin ) + , end_( cbegin + length ) + { + } + + ConstCharView( const value_type *cbegin, const value_type *cend ) + : begin_( cbegin ) + , end_( cend ) + { + } + + size_type length() const + { + return end_ - begin_; + } + + size_type size() const + { + return length(); + } + + const value_type *c_str() const + { + return begin_; + } + + const value_type *begin() const + { + return begin_; + } + + const value_type *end() const + { + return end_; + } + + private: + const value_type *begin_; + const value_type *end_; + }; + + class StringConcatenator { *************** *** 26,29 **** --- 88,92 ---- SubString( const ConstString &string ); SubString( const StringBuffer &buffer ); + SubString( const ConstCharView &constCharView ); # ifndef CPPTL_CONSTSTRING_NO_STDSTRING SubString( const std::string &string ); *************** *** 40,43 **** --- 103,107 ---- string, stringBuffer, + constCharView, stdString } kind_; *************** *** 48,51 **** --- 112,116 ---- const ConstString *string_; const StringBuffer *buffer_; + const ConstCharView *constCharView_; # ifndef CPPTL_CONSTSTRING_NO_STDSTRING const std::string *stdString_; *************** *** 169,172 **** --- 234,238 ---- ConstString( const StringConcatenator &concatenator ); ConstString( const StringBuffer &buffer ); + ConstString( const ConstCharView &view ); # ifndef CPPTL_CONSTSTRING_NO_STDSTRING ConstString( const std::string &string ); *************** *** 180,183 **** --- 246,250 ---- ConstString &operator =( const StringConcatenator &concatenator ); ConstString &operator =( const StringBuffer &buffer ); + ConstString &operator =( const ConstCharView &view ); # ifndef CPPTL_CONSTSTRING_NO_STDSTRING ConstString &operator =( const std::string &other ); *************** *** 189,192 **** --- 256,260 ---- ConstString &operator +=( const StringConcatenator &concatenator ); ConstString &operator +=( const StringBuffer &buffer ); + ConstString &operator +=( const ConstCharView &view ); # ifndef CPPTL_CONSTSTRING_NO_STDSTRING ConstString &operator +=( const std::string &string ); *************** *** 257,260 **** --- 325,329 ---- StringBuffer &operator +=( const ConstString &other ); StringBuffer &operator +=( const char *other ); + StringBuffer &operator +=( const ConstCharView &other ); # ifndef CPPTL_CONSTSTRING_NO_STDSTRING StringBuffer &operator +=( const std::string &other ); *************** *** 282,290 **** // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// ! // operator +, in global namespace... // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// - inline CppTL::StringConcatenator operator +( const char *left, const CppTL::ConstString &right ) { --- 351,359 ---- // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// ! // operator +, in global namespace... ! // implementation generated by conststring.py // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// inline CppTL::StringConcatenator operator +( const char *left, const CppTL::ConstString &right ) { *************** *** 302,305 **** --- 371,379 ---- } + inline CppTL::StringConcatenator + operator +( const char *left, const CppTL::ConstCharView &right ) { + return CppTL::StringConcatenator( left, right ); + } + inline CppTL::StringConcatenator *************** *** 323,326 **** --- 397,405 ---- } + inline CppTL::StringConcatenator + operator +( const CppTL::ConstString &left, const CppTL::ConstCharView &right ) { + return CppTL::StringConcatenator( left, right ); + } + inline CppTL::StringConcatenator *************** *** 344,347 **** --- 423,431 ---- } + inline CppTL::StringConcatenator + operator +( const CppTL::StringConcatenator &left, const CppTL::ConstCharView &right ) { + return CppTL::StringConcatenator( left, right ); + } + inline CppTL::StringConcatenator *************** *** 365,368 **** --- 449,483 ---- } + inline CppTL::StringConcatenator + operator +( const CppTL::StringBuffer &left, const CppTL::ConstCharView &right ) { + return CppTL::StringConcatenator( left, right ); + } + + + inline CppTL::StringConcatenator + operator +( const CppTL::ConstCharView &left, const char *right ) { + return CppTL::StringConcatenator( left, right ); + } + + inline CppTL::StringConcatenator + operator +( const CppTL::ConstCharView &left, const CppTL::ConstString &right ) { + return CppTL::StringConcatenator( left, right ); + } + + inline CppTL::StringConcatenator + operator +( const CppTL::ConstCharView &left, const CppTL::StringConcatenator &right ) { + return CppTL::StringConcatenator( left, right ); + } + + inline CppTL::StringConcatenator + operator +( const CppTL::ConstCharView &left, const CppTL::StringBuffer &right ) { + return CppTL::StringConcatenator( left, right ); + } + + inline CppTL::StringConcatenator + operator +( const CppTL::ConstCharView &left, const CppTL::ConstCharView &right ) { + return CppTL::StringConcatenator( left, right ); + } + # ifndef CPPTL_CONSTSTRING_NO_STDSTRING *************** *** 383,386 **** --- 498,506 ---- inline CppTL::StringConcatenator + operator +( const CppTL::ConstCharView &left, const std::string &right ) { + return CppTL::StringConcatenator( left, right ); + } + + inline CppTL::StringConcatenator operator +( const std::string &left, const CppTL::ConstString &right ) { return CppTL::StringConcatenator( left, right ); *************** *** 397,400 **** --- 517,525 ---- } + inline CppTL::StringConcatenator + operator +( const std::string &left, const CppTL::ConstCharView &right ) { + return CppTL::StringConcatenator( left, right ); + } + # endif *************** *** 471,474 **** --- 596,608 ---- + inline + StringConcatenator::SubString::SubString( const ConstCharView &view ) + : kind_( constCharView ) + , constCharView_( &view ) + , length_( view.length() ) + { + } + + # ifndef CPPTL_CONSTSTRING_NO_STDSTRING inline *************** *** 501,504 **** --- 635,641 ---- length_ = buffer_->length(); break; + case constCharView: + length_ = constCharView_->length(); + break; # ifndef CPPTL_CONSTSTRING_NO_STDSTRING case stdString: *************** *** 506,511 **** break; # endif ! //default: ! // // unreachable } return length_; --- 643,649 ---- break; # endif ! default: ! CPPTL_ASSERT_MESSAGE( false, "unreachable" ); ! break; } return length_; *************** *** 529,532 **** --- 667,673 ---- memcpy( buffer, buffer_->c_str(), length() ); break; + case constCharView: + memcpy( buffer, constCharView_->begin(), length() ); + break; # ifndef CPPTL_CONSTSTRING_NO_STDSTRING case stdString: *************** *** 534,539 **** break; # endif ! //default: ! // // unreachable } } --- 675,681 ---- break; # endif ! default: ! CPPTL_ASSERT_MESSAGE( false, "unreachable" ); ! break; } } *************** *** 586,589 **** --- 728,741 ---- inline + ConstString::ConstString( const ConstCharView &view ) + : length_( view.length() ) + , buffer_( new value_type[view.length()+1] ) + { + memcpy( buffer_, view.begin(), view.length() ); + buffer_[ length_ ] = 0; + } + + + inline ConstString::ConstString( const StringConcatenator &concatenator ) : length_( concatenator.length() ) *************** *** 673,676 **** --- 825,837 ---- + inline ConstString & + ConstString::operator =( const ConstCharView &view ) + { + ConstString temp( view ); + swap( temp ); + return *this; + } + + # ifndef CPPTL_CONSTSTRING_NO_STDSTRING inline ConstString & *************** *** 712,715 **** --- 873,883 ---- + inline ConstString & + ConstString::operator +=( const ConstCharView &view ) + { + return *this = *this + view; + } + + # ifndef CPPTL_CONSTSTRING_NO_STDSTRING inline ConstString & *************** *** 1005,1008 **** --- 1173,1187 ---- + inline StringBuffer & + StringBuffer::operator +=( const ConstCharView &other ) + { + size_type newLength = length_ + other.length(); + prepareBuffer( newLength ); + memcpy( &buffer_[length_], other.begin(), other.length() ); + truncate(newLength); + return *this; + } + + # ifndef CPPTL_CONSTSTRING_NO_STDSTRING inline StringBuffer & Index: stringtools.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/stringtools.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** stringtools.h 5 Mar 2005 12:19:51 -0000 1.7 --- stringtools.h 2 Jul 2005 20:27:35 -0000 1.8 *************** *** 229,255 **** ! inline CppTL::ConstString ! escapeControl( char c ) { ! if ( c == '\n' ) ! return "\\n"; ! else if ( c == '\t' ) ! return "\\t"; ! else if ( c == '\r' ) ! return "\\r"; ! else if ( c == '\v' ) ! return "\\v"; ! return "\\x" + toHexaString( unsigned(c) ); } ! inline CppTL::ConstString ! escape( char c ) { ! if ( c >=0 && c < 32 ) ! return escapeControl( c ); ! else if ( c == '\\' ) ! return "\\\\"; ! return CppTL::ConstString( &c, 1 ); } --- 229,270 ---- ! inline void ! escapeControl( char c, CppTL::StringBuffer &escaped, const char *newLineEscape = "\\n" ) { ! switch ( c ) ! { ! case '\n': ! escaped += newLineEscape; ! break; ! case '\t': ! escaped += CppTL::ConstCharView( "\\t", 2 ); ! break; ! case '\r': ! escaped += CppTL::ConstCharView( "\\r", 2 ); ! break; ! case '\v': ! escaped += CppTL::ConstCharView( "\\v", 2 ); ! break; ! default: ! { ! char hexa[2]; ! hexa[0] = hexaDigit( (c >> 4) & 15 ); ! hexa[1] = hexaDigit( c & 15 ); ! escaped += CppTL::ConstCharView( "\\x", 2 ) ! + ConstCharView( hexa, hexa + sizeof(hexa) ); ! } ! break; ! } } ! inline void ! escape( char c, CppTL::StringBuffer &escaped, const char *newLineEscape = "\\n" ) { ! if ( c >=0 && c < 32 ) ! escapeControl( c, escaped, newLineEscape ); ! else if ( c == '\\' ) ! escaped += CppTL::ConstCharView( "\\\\", 2 ); ! escaped += CppTL::ConstCharView( &c, 1 ); } *************** *** 257,274 **** // need to expose some of those utility functions... inline CppTL::ConstString ! escape( const CppTL::ConstString &text ) { CppTL::StringBuffer escaped( size_type(text.length() * 1.2) + 64 ); ! CppTL::ConstString::const_iterator it = text.begin(); ! while ( it != text.end() ) ! escaped += escape( *it++ ); ! return escaped; } inline CppTL::ConstString ! quoteString( const CppTL::ConstString &str ) { ! return "\"" + escape(str) + "\""; } --- 272,302 ---- // need to expose some of those utility functions... inline CppTL::ConstString ! escape( const CppTL::ConstString &text, ! CppTL::StringBuffer &escaped, ! const char *newLineEscape = "\\n" ) ! { ! CppTL::ConstString::const_iterator it = text.begin(); ! while ( it != text.end() ) ! escape( *it++, escaped, newLineEscape ); ! return escaped; ! } ! ! ! inline CppTL::ConstString ! quoteString( const CppTL::ConstString &text, ! const char *newLineEscape = "\\n" ) { CppTL::StringBuffer escaped( size_type(text.length() * 1.2) + 64 ); ! escaped += CppTL::ConstCharView( "\"", 1 ); ! escape(text, escaped, newLineEscape ); ! escaped += CppTL::ConstCharView( "\"", 1 ); ! return escaped; } inline CppTL::ConstString ! quoteMultiLineString( const CppTL::ConstString &str ) { ! return quoteString( str, "\\n\n" ); } |