Revert "Update to version 2.6.2."
Have the fix things for some other branches.
This reverts commit c3bbea3c3cfee4908189a57b3fc54f105b78c59b.
Change-Id: I57e6ff5cecb0b0a73673b52d00b2549c3cd3615e
diff --git a/tinystr.h b/tinystr.h
index 89cca33..aedd2f9 100644
--- a/tinystr.h
+++ b/tinystr.h
@@ -1,5 +1,6 @@
/*
www.sourceforge.net/projects/tinyxml
+Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
@@ -21,6 +22,17 @@
distribution.
*/
+/*
+ * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
+ *
+ * - completely rewritten. compact, clean, and fast implementation.
+ * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
+ * - fixed reserve() to work as per specification.
+ * - fixed buggy compares operator==(), operator<(), and operator>()
+ * - fixed operator+=() to take a const ref argument, following spec.
+ * - added "copy" constructor with length, and most compare operators.
+ * - added swap(), clear(), size(), capacity(), operator+().
+ */
#ifndef TIXML_USE_STL
@@ -30,21 +42,6 @@
#include <assert.h>
#include <string.h>
-/* The support for explicit isn't that universal, and it isn't really
- required - it is used to check that the TiXmlString class isn't incorrectly
- used. Be nice to old compilers and macro it here:
-*/
-#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
- // Microsoft visual studio, version 6 and higher.
- #define TIXML_EXPLICIT explicit
-#elif defined(__GNUC__) && (__GNUC__ >= 3 )
- // GCC version 3 and higher.s
- #define TIXML_EXPLICIT explicit
-#else
- #define TIXML_EXPLICIT
-#endif
-
-
/*
TiXmlString is an emulation of a subset of the std::string template.
Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
@@ -56,7 +53,7 @@
{
public :
// The size type used
- typedef size_t size_type;
+ typedef unsigned int size_type;
// Error value for find primitive
static const size_type npos; // = -1;
@@ -68,21 +65,21 @@
}
// TiXmlString copy constructor
- TiXmlString ( const TiXmlString & copy) : rep_(0)
+ TiXmlString (const TiXmlString & copy)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString constructor, based on a string
- TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
+ TiXmlString (const char * copy)
{
init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
- TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
+ TiXmlString (const char * str, size_type len)
{
init(len);
memcpy(start(), str, len);
@@ -94,11 +91,13 @@
quit();
}
+ // = operator
TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
+ // = operator
TiXmlString& operator = (const TiXmlString & copy)
{
return assign(copy.start(), copy.length());
@@ -218,15 +217,7 @@
{
if (cap)
{
- // Lee: the original form:
- // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
- // doesn't work in some cases of new being overloaded. Switching
- // to the normal allocation, although use an 'int' for systems
- // that are overly picky about structure alignment.
- const size_type bytesNeeded = sizeof(Rep) + cap;
- const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
- rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
-
+ rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
}
@@ -240,9 +231,7 @@
{
if (rep_ != &nullrep_)
{
- // The rep_ is really an array of ints. (see the allocator, above).
- // Cast it back before delete, so the compiler won't incorrectly call destructors.
- delete [] ( reinterpret_cast<int*>( rep_ ) );
+ operator delete(rep_);
}
}