You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/08/06 03:35:44 UTC

cvs commit: xml-xalan/c/src/XalanDOM XalanDOMString.cpp XalanDOMString.hpp

dbertoni    01/08/05 18:35:44

  Modified:    c/src/XalanDOM XalanDOMString.cpp XalanDOMString.hpp
  Log:
  Fixed some 64-bit issues.
  
  Revision  Changes    Path
  1.13      +57 -81    xml-xalan/c/src/XalanDOM/XalanDOMString.cpp
  
  Index: XalanDOMString.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanDOM/XalanDOMString.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XalanDOMString.cpp	2001/07/27 05:30:55	1.12
  +++ XalanDOMString.cpp	2001/08/06 01:35:44	1.13
  @@ -76,10 +76,8 @@
   
   
   XalanDOMString::XalanDOMString() :
  -	m_data()
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	, m_size(0)
  -#endif
  +	m_data(),
  +	m_size(0)
   {
   }
   
  @@ -89,10 +87,8 @@
   			const XalanDOMString&	theSource,
   			size_type				theStartPosition,
   			size_type				theCount) :
  -	m_data()
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	, m_size(0)
  -#endif
  +	m_data(),
  +	m_size(0)
   {
   	if (theSource.length() != 0)
   	{
  @@ -105,10 +101,8 @@
   XalanDOMString::XalanDOMString(
   			const XalanDOMChar*		theString,
   			size_type				theCount) :
  -	m_data()
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	, m_size(0)
  -#endif
  +	m_data(),
  +	m_size(0)
   {
   	assert(theString != 0);
   
  @@ -123,10 +117,8 @@
   XalanDOMString::XalanDOMString(
   			const char*		theString,
   			size_type		theCount) :
  -	m_data()
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	, m_size(0)
  -#endif
  +	m_data(),
  +	m_size(0)
   {
   	assert(theString != 0);
   
  @@ -143,21 +135,17 @@
   XalanDOMString::XalanDOMString(
   			size_type		theCount,
   			XalanDOMChar	theChar) :
  -	m_data()
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	, m_size(0)
  -#endif
  +	m_data(),
  +	m_size(0)
   {
   	if (theCount != 0)
   	{
  -		XalanDOMCharVectorType(theCount + 1, theChar).swap(m_data);
  +		XalanDOMCharVectorType(real_size_type(theCount) + 1, theChar).swap(m_data);
   
   		// Null-terminate it...
   		m_data.back() = 0;
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		m_size = theCount;
  -#endif
   	}
   
   	invariants();
  @@ -180,21 +168,19 @@
   		{
   			// If the string is of 0 length, resize but add an
   			// extra byte for the terminating byte.
  -			m_data.resize(theCount + 1, theChar);
  +			m_data.resize(real_size_type(theCount) + 1, theChar);
   		}
   		else
   		{
   			// If the string is not of 0 length, resize but
   			// put a copy of theChar where the terminating
   			// byte used to be.
  -			m_data.resize(theCount, theChar);
  +			m_data.resize(real_size_type(theCount), theChar);
   
  -			m_data[theOldSize] = theChar;
  +			m_data[real_size_type(theOldSize)] = theChar;
   		}
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		m_size = theCount;
  -#endif
   
   		// Terminate...
   		m_data.back() = 0;
  @@ -219,9 +205,7 @@
   	{
   		m_data.erase(m_data.begin(), m_data.end());
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		m_size = 0;
  -#endif
   	}
   	else
   	{
  @@ -229,8 +213,8 @@
   
   		m_data.erase(i, i + (theActualCount));
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -		const size_type		theNewSize = m_data.size();
  +		const size_type		theNewSize = size_type(m_data.size());
  +		assert(real_size_type(theNewSize) == m_data.size());
   
   		if (theNewSize < 2)
   		{
  @@ -240,7 +224,6 @@
   		{
   			m_size = theNewSize - 1;
   		}
  -#endif
   	}
   
   	invariants();
  @@ -280,15 +263,13 @@
   	{
   		if (m_data.size() == 0)
   		{
  -			m_data.reserve(theLength + 1);
  +			m_data.reserve(real_size_type(theLength) + 1);
   
   			m_data.insert(m_data.end(), theString, theString + theLength);
   
   			m_data.push_back(0);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   			m_size = theLength;
  -#endif
   
   			assert(length() == theLength);
   		}
  @@ -296,9 +277,7 @@
   		{
   			m_data.insert(getBackInsertIterator(), theString, theString + theLength);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   			m_size += theCount;
  -#endif
   		}
   	}
   
  @@ -357,12 +336,12 @@
   
   			doTranscode(theString, theLength, theTempVector);
   
  -			append(&*theTempVector.begin(), theTempVector.size());
  +			append(&*theTempVector.begin(), size_type(theTempVector.size()));
   		}
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -		m_size = m_data.size() - 1;
  -#endif
  +		m_size = size_type(m_data.size()) - 1;
  +
  +		assert(real_size_type(m_size) == m_data.size() - 1);
   	}
   
   	invariants();
  @@ -380,23 +359,19 @@
   
   	if (m_data.size() == 0)
   	{
  -		m_data.insert(m_data.end(), theCount + 1, theChar);
  +		m_data.insert(m_data.end(), real_size_type(theCount) + 1, theChar);
   
   		m_data.back() = 0;
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		m_size = theCount;
  -#endif
   
   		assert(length() == theCount);
   	}
   	else
   	{
  -		m_data.insert(getBackInsertIterator(), theCount, theChar);
  +		m_data.insert(getBackInsertIterator(), real_size_type(theCount), theChar);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		m_size += theCount;
  -#endif
   	}
   
   	invariants();
  @@ -416,9 +391,7 @@
   
   	m_data.insert(getIteratorForPosition(thePosition), theString, theString + theCount);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   	m_size += theCount;
  -#endif
   
   	invariants();
   
  @@ -435,11 +408,9 @@
   {
   	invariants();
   
  -	m_data.insert(getIteratorForPosition(thePosition), theCount, theChar);
  +	m_data.insert(getIteratorForPosition(thePosition), real_size_type(theCount), theChar);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   	m_size += theCount;
  -#endif
   
   	invariants();
   
  @@ -457,9 +428,7 @@
   
   	m_data.insert(thePosition, theChar);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   	++m_size;
  -#endif
   
   	invariants();
   
  @@ -476,11 +445,9 @@
   {
   	invariants();
   
  -	m_data.insert(thePosition, theCount, theChar);
  +	m_data.insert(thePosition, real_size_type(theCount), theChar);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   	m_size += theCount;
  -#endif
   
   	invariants();
   }
  @@ -497,10 +464,10 @@
   
   	m_data.insert(theInsertPosition, theFirstPosition, theLastPosition);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	m_size = m_data.size() - 1;
  -#endif
  +	m_size = size_type(m_data.size()) - 1;
   
  +	assert(real_size_type(m_size) == m_data.size() - 1);
  +
   	invariants();
   }
   
  @@ -619,7 +586,7 @@
   		theStringPointer++;
   	}
   
  -	return theStringPointer - theString;
  +	return XalanDOMString::size_type(theStringPointer - theString);
   }
   
   
  @@ -695,8 +662,10 @@
   XalanDOMString::length(const char*	theString)
   {
   	assert(theString != 0);
  +
  +	assert(strlen(theString) < npos);
   
  -	return strlen(theString);
  +	return size_type(strlen(theString));
   }
   
   
  @@ -803,12 +772,14 @@
   
   static bool
   doTranscodeToLocalCodePage(
  -			const XalanDOMChar*		theSourceString,
  -			unsigned int			theSourceStringLength,
  -			bool					theSourceStringIsNullTerminated,
  -			CharVectorType&			theTargetVector,
  -			bool					terminate)
  +			const XalanDOMChar*			theSourceString,
  +			XalanDOMString::size_type	theSourceStringLength,
  +			bool						theSourceStringIsNullTerminated,
  +			CharVectorType&				theTargetVector,
  +			bool						terminate)
   {
  +	typedef XalanDOMString::real_size_type	real_size_type;
  +
       // Short circuit if it's a null pointer, or of length 0.
       if (!theSourceString || (!theSourceString[0]))
       {
  @@ -858,14 +829,14 @@
   			theSourceStringLength = length(theSourceString);
   		}
   
  -		theTempSourceJanitor.reset(new wchar_t[theSourceStringLength + 1]);
  +		theTempSourceJanitor.reset(new wchar_t[real_size_type(theSourceStringLength) + 1]);
   
  -		for (unsigned int index = 0; index < theSourceStringLength; ++index)
  +		for (size_t	index = 0; index < size_t(theSourceStringLength); ++index)
   		{
   			theTempSourceJanitor[index] = wchar_t(theSourceString[index]);
   		}
   
  -		theTempSourceJanitor[theSourceStringLength] = 0;
  +		theTempSourceJanitor[size_t(theSourceStringLength)] = 0;
   
   		theTempSource = theTempSourceJanitor.get();
   	}
  @@ -905,10 +876,10 @@
   
   XALAN_DOM_EXPORT_FUNCTION(bool)
   TranscodeToLocalCodePage(
  -			const XalanDOMChar*		theSourceString,
  -			unsigned int			theSourceStringLength,
  -			CharVectorType&			theTargetVector,
  -			bool					terminate)
  +			const XalanDOMChar*			theSourceString,
  +			XalanDOMString::size_type	theSourceStringLength,
  +			CharVectorType&				theTargetVector,
  +			bool						terminate)
   {
   	return doTranscodeToLocalCodePage(theSourceString, theSourceStringLength, false, theTargetVector, terminate);
   }
  @@ -929,11 +900,13 @@
   static bool
   doTranscodeFromLocalCodePage(
   			const char*					theSourceString,
  -			unsigned int				theSourceStringLength,
  +			XalanDOMString::size_type	theSourceStringLength,
   			bool						theSourceStringIsNullTerminated,
   			XalanDOMCharVectorType&		theTargetVector,
   			bool						terminate)
   {
  +	typedef XalanDOMString::size_type	size_type;
  +
       // Short circuit if it's a null pointer, or of length 0.
       if (!theSourceString || (!theSourceString[0]))
       {
  @@ -964,11 +937,14 @@
   #else
   	if (theSourceStringIsNullTerminated == true)
   	{
  -		theSourceStringLength = strlen(theSourceString);
  +		assert(strlen(theSourceString) < XalanDOMString::npos);
  +
  +		theSourceStringLength = size_type(strlen(theSourceString));
   	}
   
       // See how many chars we need to transcode.
  -	const size_t	theTargetLength = ::mbstowcs(0, theSourceString, theSourceStringLength);
  +	const size_t	theTargetLength =
  +			::mbstowcs(0, theSourceString, size_t(theSourceStringLength));
   
   	if (theTargetLength == size_t(-1))
   	{
  @@ -990,7 +966,7 @@
   		wchar_t* const	theTargetPointer = &theTargetVector[0];
   #endif
   
  -		if (mbstowcs(theTargetPointer, theSourceString, theSourceStringLength) == size_t(-1))
  +		if (mbstowcs(theTargetPointer, theSourceString, size_t(theSourceStringLength)) == size_t(-1))
   		{
   			return false;
   		}
  @@ -1003,7 +979,7 @@
   
   			for(WideCharVectorType::size_type i = 0; i < theTempSize; ++i)
   			{
  -				theTargetVector.push_back(WideCharVectorType::value_type(theTempResult[i]));
  +				theTargetVector.push_back(theTempResult[i]);
   			}
   #endif
   
  @@ -1023,7 +999,7 @@
   XALAN_DOM_EXPORT_FUNCTION(bool)
   TranscodeFromLocalCodePage(
   			const char*					theSourceString,
  -			unsigned int				theSourceStringLength,
  +			XalanDOMString::size_type	theSourceStringLength,
   			XalanDOMCharVectorType&		theTargetVector,
   			bool						terminate)
   {
  
  
  
  1.19      +25 -42    xml-xalan/c/src/XalanDOM/XalanDOMString.hpp
  
  Index: XalanDOMString.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanDOM/XalanDOMString.hpp,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- XalanDOMString.hpp	2001/07/27 05:31:17	1.18
  +++ XalanDOMString.hpp	2001/08/06 01:35:44	1.19
  @@ -76,10 +76,6 @@
   
   
   
  -#define XALAN_DOMSTRING_CACHE_SIZE
  -
  -
  -
   #include <cassert>
   
   
  @@ -104,8 +100,9 @@
   
   	// We're stuck with 32-bit lengths because of the DOMs IDL
   	// bindings.  Ideally, we'ed like to re-visit this in the
  -	// future.
  +	// future.  See typedef below of real_size_type.
   	typedef unsigned int									size_type;
  +	typedef XalanDOMCharVectorType::size_type				real_size_type;
   
   	typedef XalanDOMCharVectorType::iterator				iterator;
   	typedef XalanDOMCharVectorType::const_iterator			const_iterator;
  @@ -113,7 +110,7 @@
   	typedef XalanDOMCharVectorType::const_reverse_iterator	const_reverse_iterator;
   
   #if defined(XALAN_INLINE_INITIALIZATION)
  -	static const size_type	npos = size_type(-1);
  +	static const size_type	npos = ~0u;
   #else
   	enum { npos = -1 };
   #endif
  @@ -205,11 +202,7 @@
   	{
   		invariants();
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		return m_size;
  -#else
  -		return m_data.empty() == true ? 0 : m_data.size() - 1;
  -#endif
   	}
   
   	size_type
  @@ -245,8 +238,10 @@
   	capacity() const
   	{
   		invariants();
  +
  +		assert(real_size_type(size_type(m_data.capacity())) == m_data.capacity());
   
  -		return m_data.capacity() - 1;
  +		return size_type(m_data.capacity()) - 1;
   	}
   
   	void
  @@ -254,7 +249,7 @@
   	{
   		invariants();
   
  -		m_data.reserve(theCount + 1);
  +		m_data.reserve(real_size_type(theCount) + 1);
   	}
   
   	void
  @@ -264,9 +259,7 @@
   
   		m_data.erase(m_data.begin(), m_data.end());
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		m_size = 0;
  -#endif
   
   		invariants();
   	}
  @@ -281,11 +274,7 @@
   	{
   		invariants();
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		return m_size == 0 ? true : false;
  -#else
  -		return m_data.size() < 2 ? true : false;
  -#endif
   	}
   
   	const_reference
  @@ -293,7 +282,7 @@
   	{
   		invariants();
   
  -		return m_data[theIndex];
  +		return m_data[real_size_type(theIndex)];
   	}
   
   	reference
  @@ -301,7 +290,7 @@
   	{
   		invariants();
   
  -		return m_data[theIndex];
  +		return m_data[real_size_type(theIndex)];
   	}
   
   #if 0
  @@ -312,7 +301,7 @@
   	{
   		invariants();
   
  -		return m_data.at(theIndex);
  +		return m_data.at(real_size_type(theIndex));
   	}
   
   	reference
  @@ -320,7 +309,7 @@
   	{
   		invariants();
   
  -		return m_data.at(theIndex);
  +		return m_data.at(real_size_type(theIndex));
   	}
   #endif
   
  @@ -351,13 +340,11 @@
   
   		m_data.swap(theOther.m_data);
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   #if defined(XALAN_NO_NAMESPACES)
   		::swap(m_size, theOther.m_size);
   #else
   		std::swap(m_size, theOther.m_size);
   #endif
  -#endif
   	}
   
   	XalanDOMString&
  @@ -461,9 +448,7 @@
   		{
   			m_data = theSource.m_data;
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   			m_size = theSource.m_size;
  -#endif
   		}
   
   		invariants();
  @@ -774,11 +759,7 @@
   	invariants() const
   	{
   #if !defined(NDEBUG)
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
   		assert((m_data.size() == 0 && m_size == 0) || m_size == m_data.size() - 1);
  -#endif
  -
   		assert(m_data.size() == 0 || m_data.back() == 0);
   #endif
   	}
  @@ -824,9 +805,7 @@
   
   	XalanDOMCharVectorType		m_data;
   
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -	unsigned long				m_size;
  -#endif
  +	size_type					m_size;
   
   	static const XalanDOMChar	s_empty;
   };
  @@ -976,10 +955,10 @@
    */
   XALAN_DOM_EXPORT_FUNCTION(bool)
   TranscodeToLocalCodePage(
  -			const XalanDOMChar*		theSourceString,
  -			unsigned int			theSourceStringLength,
  -			CharVectorType&			targetVector,
  -			bool					terminate = false);
  +			const XalanDOMChar*			theSourceString,
  +			XalanDOMString::size_type	theSourceStringLength,
  +			CharVectorType&				targetVector,
  +			bool						terminate = false);
   
   
   
  @@ -1071,8 +1050,8 @@
    */
   inline const XalanDOMString
   TranscodeFromLocalCodePage(
  -			const char*		theSourceString,
  -			unsigned int	theSourceStringLength = unsigned(-1))
  +			const char*					theSourceString,
  +			XalanDOMString::size_type	theSourceStringLength = XalanDOMString::npos)
   {
   	return XalanDOMString(theSourceString, theSourceStringLength);
   }
  @@ -1093,7 +1072,7 @@
   XALAN_DOM_EXPORT_FUNCTION(bool)
   TranscodeFromLocalCodePage(
   			const char*					theSourceString,
  -			unsigned int				theSourceStringLength,
  +			XalanDOMString::size_type	theSourceStringLength,
   			XalanDOMCharVectorType&		theTargetVector,
   			bool						terminate = false);
   
  @@ -1127,15 +1106,19 @@
   inline const XalanDOMString
   TranscodeFromLocalCodePage(const CharVectorType&	theSourceString)
   {
  +	typedef XalanDOMString::size_type		size_type;
  +	typedef XalanDOMString::real_size_type	real_size_type;
  +
   	const CharVectorType::size_type		theSize = theSourceString.size();
  +	assert(real_size_type(size_type(theSize)) == theSize);
   
   	if (theSourceString[theSize - 1] == CharVectorType::value_type(0))
   	{
  -		return TranscodeFromLocalCodePage(&*theSourceString.begin(), theSize - 1);
  +		return TranscodeFromLocalCodePage(&*theSourceString.begin(), size_type(theSize) - 1);
   	}
   	else
   	{
  -		return TranscodeFromLocalCodePage(&*theSourceString.begin(), theSize);
  +		return TranscodeFromLocalCodePage(&*theSourceString.begin(), size_type(theSize));
   	}
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org