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 2002/04/02 08:10:06 UTC

cvs commit: xml-xalan/c/src/PlatformSupport URISupport.cpp URISupport.hpp

dbertoni    02/04/01 22:10:06

  Modified:    c/src/PlatformSupport URISupport.cpp URISupport.hpp
  Log:
  Added new overloads for more efficiency.
  
  Revision  Changes    Path
  1.17      +58 -81    xml-xalan/c/src/PlatformSupport/URISupport.cpp
  
  Index: URISupport.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/URISupport.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- URISupport.cpp	23 Feb 2002 04:17:46 -0000	1.16
  +++ URISupport.cpp	2 Apr 2002 06:10:06 -0000	1.17
  @@ -105,46 +105,29 @@
   
   
   URISupport::URLAutoPtrType
  -URISupport::getURLFromString(const XalanDOMString&	urlString)
  -{
  -	return getURLFromString(c_wstr(urlString));
  -}
  -
  -
  -
  -URISupport::URLAutoPtrType
   URISupport::getURLFromString(const XalanDOMChar*	urlString)
   {
   	URLAutoPtrType	url(new XMLURL);
   
  -	url->setURL(c_wstr(getURLStringFromString(urlString)));
  +	url->setURL(getURLStringFromString(urlString).c_str());
   
   	return url;
   }
   
   
   
  -XalanDOMString
  -URISupport::getURLStringFromString(const XalanDOMString&	urlString)
  -{
  -	return getURLStringFromString(c_wstr(urlString));
  -}
  -
  -
  -
  -XalanDOMString
  -URISupport::getURLStringFromString(const XalanDOMChar*	urlString)
  +void
  +URISupport::getURLStringFromString(
  +			const XalanDOMChar*			urlString,
  +			XalanDOMString::size_type	len,
  +			XalanDOMString&				theNormalizedURI)
   {
   	assert(urlString != 0);
   
  -	XalanDOMString	theNormalizedURI(urlString);
  -
   	// Let's see what sort of URI we have...
  -	const XalanDOMString::size_type		len = length(theNormalizedURI);
  -
   	if (len != 0)
   	{
  -		const XalanDOMString::size_type		index = indexOf(theNormalizedURI, XalanUnicode::charColon);
  +		const XalanDOMString::size_type		index = indexOf(urlString, XalanUnicode::charColon);
   
   		bool	protocolPresent = false;
   
  @@ -152,7 +135,7 @@
   		{
   			// $$$ ToDo: XMLURL::lookupByName() is supposed to be static, but is not.
   			const XMLURL::Protocols		theProtocol =
  -				XMLURL().lookupByName(c_wstr(substring(theNormalizedURI, 0 , index)));
  +					XMLURL().lookupByName(c_wstr(substring(urlString, 0 , index)));
   
   			if (theProtocol != XMLURL::Unknown)
   			{
  @@ -162,97 +145,81 @@
   
   		if (protocolPresent == true)
   		{
  +			theNormalizedURI = urlString;
  +
   			NormalizeURIText(theNormalizedURI);
   		}
   		else
   		{
   			// Assume it's a file specification...
  -			const XalanArrayAutoPtr<XalanDOMChar>	theFullPath(XMLPlatformUtils::getFullPath(c_wstr(urlString)));
  -			assert(theFullPath.get() != 0);
  +			const XalanArrayAutoPtr<XalanDOMChar>	theFullPathGuard(XMLPlatformUtils::getFullPath(c_wstr(urlString)));
   
  -			theNormalizedURI = theFullPath.get();
  -			assert(length(theNormalizedURI) > 0);
  +			const XalanDOMChar* const	theFullPath = theFullPathGuard.get();
  +			assert(theFullPath != 0);
   
  -			NormalizeURIText(theNormalizedURI);
  +			const XalanDOMString::size_type		theFullPathLength =
  +				XalanDOMString::length(theFullPath);
   
  -			if (indexOf(theNormalizedURI, XalanUnicode::charSolidus) == 0)
  +			assert(theFullPathLength > 0);
  +
  +			if (theFullPath[0] == XalanDOMChar(XalanUnicode::charSolidus))
   			{
  -				insert(theNormalizedURI, 0, &s_fileProtocolString1[0]);
  +				const size_t	theSize = sizeof(s_fileProtocolString1) / sizeof(s_fileProtocolString1[0]) - 1;
  +
  +				theNormalizedURI.reserve(theFullPathLength + theSize);
  +
  +				theNormalizedURI.assign(s_fileProtocolString1, theSize);
   			}
   			else
   			{
  -				insert(theNormalizedURI, 0, &s_fileProtocolString2[0]);
  -			}
  -		}
  -	}
  -
  -	return theNormalizedURI;
  -}
  +				const size_t	theSize = sizeof(s_fileProtocolString2) / sizeof(s_fileProtocolString2[0]) - 1;
   
  +				theNormalizedURI.reserve(theFullPathLength + theSize);
   
  +				theNormalizedURI.assign(s_fileProtocolString2, theSize);
  +			}
   
  -URISupport::URLAutoPtrType
  -URISupport::getURLFromString(
  -			const XalanDOMString&	urlString,
  -			const XalanDOMString&	base)
  -{	
  -	return getURLFromString(getURLStringFromString(urlString, base));
  -}
  -
  -
  +			theNormalizedURI.append(theFullPath, theFullPathLength);
   
  -XalanDOMString
  -URISupport::getURLStringFromString(
  -			const XalanDOMString&	urlString,
  -			const XalanDOMString&	base)
  -{
  -	return getURLStringFromString(c_wstr(urlString), c_wstr(base));
  +			NormalizeURIText(theNormalizedURI);
  +		}
  +	}
   }
   
   
   
  -XalanDOMString
  +void
   URISupport::getURLStringFromString(
  -			const XalanDOMChar*		urlString,
  -			const XalanDOMChar*		base)
  +			const XalanDOMChar*			urlString,
  +			XalanDOMString::size_type	urlStringLen,
  +			const XalanDOMChar*			base,
  +			XalanDOMString::size_type	baseLen,
  +			XalanDOMString&				theNormalizedURI)
   {
  -	XalanDOMString	context(base);
  +	XalanDOMString	context(base, baseLen);
   
   	NormalizeURIText(context);
   
  -	const XalanDOMString::size_type		theContextLength = length(context);
  -
  -	const XalanDOMString::size_type		indexOfSlash = theContextLength == 0 ?
  +	const XalanDOMString::size_type		indexOfSlash = baseLen == 0 ?
   							0 :
   							lastIndexOf(context, XalanUnicode::charSolidus);
   
  -	bool				hasPath = true;
  +	const bool	hasPath = indexOfSlash < baseLen ? true : false;
   
  -	if (indexOfSlash < theContextLength)
  +	if (hasPath == true)
   	{
  -		context = substring(context, 0, indexOfSlash + 1);
  -	}
  -	else
  -	{
  -		hasPath = false;
  +		// Strip off file name from context...
  +		substring(context, context, 0, indexOfSlash + 1);
   	}
   
   	// OK, now let's look at the urlString...
   
   	// Is there a colon, indicating some sort of drive spec, or protocol?
  -	const XalanDOMString::size_type		theURLStringLength = length(urlString);
   	const XalanDOMString::size_type		theColonIndex = indexOf(urlString, XalanUnicode::charColon);
   
  -	if (theColonIndex == theURLStringLength)
  +	if (theColonIndex == urlStringLen)
   	{
   		// No colon, so just use the urlString as is...
  -
  -		// Strip off file name from context...
  -		if (indexOfSlash < theContextLength)
  -		{
  -			context = substring(context, 0, indexOfSlash + 1);
  -		}
  -
   		if (hasPath == true)
   		{
   			context += urlString;
  @@ -291,7 +258,7 @@
   				// Check if this is an absolute URI (starts with a leading '//')
   				const XalanDOMString::size_type		protoLength = length(theProtocolString);
   
  -				if (protoLength + 3 <= theURLStringLength &&
  +				if (protoLength + 3 <= urlStringLen &&
   					urlString[protoLength + 1] == XalanUnicode::charSolidus &&
   					urlString[protoLength + 2] == XalanUnicode::charSolidus)
   				{
  @@ -301,20 +268,20 @@
   				else
   				{
   					// Strip off file name from context...
  -					if (indexOfSlash < theContextLength)
  +					if (indexOfSlash < baseLen)
   					{
   						context = substring(context, 0, indexOfSlash + 1);
   					}
   
   					// OK, everything looks good, so strip off the protocol 
   					// and colon...
  -					context += substring(urlString, theColonIndex + 1, theURLStringLength);
  +					context += substring(urlString, theColonIndex + 1, urlStringLen);
   				}
   			}
   		}
   	}
   
  -	return getURLStringFromString(context);
  +	getURLStringFromString(context, theNormalizedURI);
   }
   
   
  @@ -332,6 +299,15 @@
   
   	if (index != len)
   	{
  +#if 1
  +		// Start replacing at the index point, since that's the
  +		// first one...
  +		replace(
  +				uriString.begin(),
  +				uriString.end(),
  +				XalanDOMChar(XalanUnicode::charReverseSolidus),
  +				XalanDOMChar(XalanUnicode::charSolidus));
  +#else
   		XalanDOMCharVectorType	theVector =
   			MakeXalanDOMCharVector(uriString);
   
  @@ -344,6 +320,7 @@
   				XalanDOMCharVectorType::value_type(XalanUnicode::charSolidus));
   
   		uriString = XalanDOMString(&theVector[0]);
  +#endif
   	}
   
   	return uriString;
  
  
  
  1.8       +180 -13   xml-xalan/c/src/PlatformSupport/URISupport.hpp
  
  Index: URISupport.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/URISupport.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- URISupport.hpp	23 Feb 2002 04:17:46 -0000	1.7
  +++ URISupport.hpp	2 Apr 2002 06:10:06 -0000	1.8
  @@ -93,34 +93,47 @@
   	 * @return auto pointer to fully qualified URI
   	 */
   	static URLAutoPtrType
  -	getURLFromString(const XalanDOMString&	urlString);
  +	getURLFromString(const XalanDOMString&	urlString)
  +	{
  +		return getURLFromString(urlString.c_str());
  +	}
   
   	/**
   	 * Determine the fully qualified URI for a string.
   	 *
   	 * @param urlString string to qualify
  -	 * @return auto pointer to fully qualified URI
  +	 * @param url to update with the qualified string.
   	 */
  -	static URLAutoPtrType
  -	getURLFromString(const XalanDOMChar*	urlString);
  +	static void
  +	getURLFromString(
  +			const XalanDOMString&	urlString,
  +			XMLURL&					url)
  +	{
  +		getURLFromString(urlString.c_str(), url);
  +	}
   
   	/**
   	 * Determine the fully qualified URI for a string.
   	 *
   	 * @param urlString string to qualify
  -	 * @return string to fully qualified URI
  +	 * @return auto pointer to fully qualified URI
   	 */
  -	static XalanDOMString
  -	getURLStringFromString(const XalanDOMString&	urlString);
  +	static URLAutoPtrType
  +	getURLFromString(const XalanDOMChar*	urlString);
   
   	/**
   	 * Determine the fully qualified URI for a string.
   	 *
   	 * @param urlString string to qualify
  -	 * @return string to fully qualified URI
  +	 * @param url to update with the qualified string.
   	 */
  -	static XalanDOMString
  -	getURLStringFromString(const XalanDOMChar*	urlString);
  +	static void
  +	getURLFromString(
  +			const XalanDOMChar*		urlString,
  +			XMLURL&					url)
  +	{
  +		url.setURL(getURLStringFromString(urlString).c_str());
  +	}
   
   	/**
   	 * Determine the fully qualified URI for a string.
  @@ -132,7 +145,10 @@
   	static URLAutoPtrType
   	getURLFromString(
   			const XalanDOMString&	urlString,
  -			const XalanDOMString&	base);
  +			const XalanDOMString&	base)
  +	{
  +		return getURLFromString(getURLStringFromString(urlString, base));
  +	}
   
   	/**
   	 * Determine the fully qualified URI for a string.
  @@ -150,13 +166,119 @@
   	 * Determine the fully qualified URI for a string.
   	 *
   	 * @param urlString string to qualify
  +	 * @return string to fully qualified URI
  +	 */
  +	static XalanDOMString
  +	getURLStringFromString(const XalanDOMString&	urlString)
  +	{
  +		XalanDOMString	result;
  +
  +		getURLStringFromString(urlString.c_str(), urlString.length(), result);
  +
  +		return result;
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @return string to fully qualified URI
  +	 */
  +	static void
  +	getURLStringFromString(
  +			const XalanDOMString&	urlString,
  +			XalanDOMString&			theNormalizedURI)
  +	{
  +		getURLStringFromString(urlString.c_str(), urlString.length(), theNormalizedURI);
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @return string to fully qualified URI
  +	 */
  +	static XalanDOMString
  +	getURLStringFromString(const XalanDOMChar*	urlString)
  +	{
  +		XalanDOMString	theNormalizedURI;
  +
  +		getURLStringFromString(urlString, theNormalizedURI);
  +
  +		return theNormalizedURI;
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @param theNormalizedURI fully qualified URI
  +	 */
  +	static void
  +	getURLStringFromString(
  +			const XalanDOMChar*			urlString,
  +			XalanDOMString&				theNormalizedURI)
  +	{
  +		assert(urlString != 0);
  +
  +		getURLStringFromString(
  +			urlString,
  +			XalanDOMString::length(urlString),
  +			theNormalizedURI);
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @param len the length of urlString
  +	 * @param theNormalizedURI fully qualified URI
  +	 */
  +	static void
  +	getURLStringFromString(
  +			const XalanDOMChar*			urlString,
  +			XalanDOMString::size_type	len,
  +			XalanDOMString&				theNormalizedURI);
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
   	 * @param base base location for URI
   	 * @return string to fully qualified URI
   	 */
   	static XalanDOMString
   	getURLStringFromString(
   			const XalanDOMString&	urlString,
  -			const XalanDOMString&	base);
  +			const XalanDOMString&	base)
  +	{
  +		XalanDOMString	theNormalizedURI;
  +
  +		getURLStringFromString(
  +			urlString.c_str(),
  +			urlString.length(),
  +			base.c_str(),
  +			base.length(),
  +			theNormalizedURI);
  +
  +		return theNormalizedURI;
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @param base base location for URI
  +	 * @param theNormalizedURI fully qualified URI
  +	 */
  +	static void
  +	getURLStringFromString(
  +			const XalanDOMString&	urlString,
  +			const XalanDOMString&	base,
  +			XalanDOMString&			theNormalizedURI)
  +	{
  +		getURLStringFromString(urlString.c_str(), base.c_str(), theNormalizedURI);
  +	}
   
   	/**
   	 * Determine the fully qualified URI for a string.
  @@ -168,7 +290,52 @@
   	static XalanDOMString
   	getURLStringFromString(
   			const XalanDOMChar*		urlString,
  -			const XalanDOMChar*		base);
  +			const XalanDOMChar*		base)
  +	{
  +		XalanDOMString	theNormalizedURI;
  +
  +		getURLStringFromString(urlString, base, theNormalizedURI);
  +
  +		return theNormalizedURI;
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @param base base location for URI
  +	 * @param theNormalizedURI fully qualified URI
  +	 */
  +	static void
  +	getURLStringFromString(
  +			const XalanDOMChar*		urlString,
  +			const XalanDOMChar*		base,
  +			XalanDOMString&			theNormalizedURI)
  +	{
  +		assert(urlString != 0 && base != 0);
  +
  +		getURLStringFromString(
  +			urlString,
  +			XalanDOMString::length(urlString),
  +			base,
  +			XalanDOMString::length(base),
  +			theNormalizedURI);
  +	}
  +
  +	/**
  +	 * Determine the fully qualified URI for a string.
  +	 *
  +	 * @param urlString string to qualify
  +	 * @param base base location for URI
  +	 * @param theNormalizedURI fully qualified URI
  +	 */
  +	static void
  +	getURLStringFromString(
  +			const XalanDOMChar*			urlString,
  +			XalanDOMString::size_type	urlStringLen,
  +			const XalanDOMChar*			base,
  +			XalanDOMString::size_type	baseLen,
  +			XalanDOMString&				theNormalizedURI);
   
   	/**
   	 * Normalizes the string passed in, replacing
  
  
  

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