dbertoni 01/06/14 11:54:07
Modified: c/src/PlatformSupport DOMStringHelper.cpp
DOMStringHelper.hpp
Log:
New substring() helper function.
Revision Changes Path
1.58 +95 -23 xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp
Index: DOMStringHelper.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- DOMStringHelper.cpp 2001/05/09 18:36:26 1.57
+++ DOMStringHelper.cpp 2001/06/14 18:53:57 1.58
@@ -503,42 +503,75 @@
-#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
-
-template<class InputIteratorType, class OutputIteratorType>
-inline OutputIteratorType
-XalanCopy(
- InputIteratorType begin,
- InputIteratorType end,
- OutputIteratorType iterator)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
+substring(
+ const XalanDOMChar* theString,
+ XalanDOMString& theSubstring,
+ unsigned int theStartIndex,
+ unsigned int theEndIndex)
{
- for(; begin != end; ++iterator, ++begin)
+ assert(theString != 0);
+
+ const unsigned int theStringLength = length(theString);
+
+ // $$$ ToDo: In Java-land, any failing of this
+ // assertion would result in an exception being thrown.
+ assert(theStartIndex <= theStringLength);
+
+ if (theStartIndex == theStringLength)
{
- *iterator = *begin;
+ // This is allowed, and should return an empty string.
+ clear(theSubstring);
}
+ else
+ {
+ const unsigned int theLength = theEndIndex == UINT_MAX ?
theStringLength - theStartIndex :
+
theEndIndex - theStartIndex;
+ assert(theStartIndex + theLength <= theStringLength);
- return iterator;
+ theSubstring.assign(theString + theStartIndex, theLength);
+ }
+
+ return theSubstring;
}
-template<class InputIteratorType, class OutputIteratorType, class
UnaryFunction>
-inline OutputIteratorType
-XalanTransform(
- InputIteratorType begin,
- InputIteratorType end,
- OutputIteratorType iterator,
- UnaryFunction function)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+substring(
+ const XalanDOMString& theString,
+ XalanDOMString& theSubstring,
+ unsigned int theStartIndex,
+ unsigned int theEndIndex)
{
- for(; begin != end; ++iterator, ++begin)
+ const unsigned int theStringLength = length(theString);
+
+ // $$$ ToDo: In Java-land, any failing of this
+ // assertion would result in an exception being thrown.
+ assert(theStartIndex <= theStringLength);
+
+ if (theStartIndex == theStringLength)
{
- *iterator = function(*begin);
+ // This is allowed, and should return an empty string.
+ clear(theSubstring);
}
+ else
+ {
+ const unsigned int theLength = theEndIndex == UINT_MAX ?
theStringLength - theStartIndex :
+
theEndIndex - theStartIndex;
- return iterator;
-}
+ if (theLength == 0)
+ {
+ clear(theSubstring);
+ }
+ else
+ {
+ assert(theStartIndex + theLength <= theStringLength);
-#endif
+ theString.substr(theSubstring, theStartIndex,
theLength);
+ }
+ }
+}
@@ -576,6 +609,45 @@
}
}
}
+
+
+
+#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
+
+template<class InputIteratorType, class OutputIteratorType>
+inline OutputIteratorType
+XalanCopy(
+ InputIteratorType begin,
+ InputIteratorType end,
+ OutputIteratorType iterator)
+{
+ for(; begin != end; ++iterator, ++begin)
+ {
+ *iterator = *begin;
+ }
+
+ return iterator;
+}
+
+
+
+template<class InputIteratorType, class OutputIteratorType, class
UnaryFunction>
+inline OutputIteratorType
+XalanTransform(
+ InputIteratorType begin,
+ InputIteratorType end,
+ OutputIteratorType iterator,
+ UnaryFunction function)
+{
+ for(; begin != end; ++iterator, ++begin)
+ {
+ *iterator = function(*begin);
+ }
+
+ return iterator;
+}
+
+#endif
1.44 +44 -3 xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp
Index: DOMStringHelper.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- DOMStringHelper.hpp 2001/04/11 02:14:07 1.43
+++ DOMStringHelper.hpp 2001/06/14 18:54:00 1.44
@@ -1152,9 +1152,9 @@
* Simulates the java String method substring(). Returns a new string that is
* a substring of this string. The substring begins at the specified
* theStartIndex and extends to the character at index theEndIndex - 1. Thus
- * the length of the substring is theEndIndex-theStartIndex.
+ * the length of the substring is theEndIndex - theStartIndex.
*
- * @param theString target string
+ * @param theString source string
* @param theStartIndex starting index, inclusive
* @param theEndIndex ending index, exclusive
* @return string containing the specified range of characters from target
@@ -1171,9 +1171,50 @@
* Simulates the java String method substring(). Returns a new string that is
* a substring of this string. The substring begins at the specified
* theStartIndex and extends to the character at index theEndIndex - 1. Thus
+ * the length of the substring is theEndIndex - theStartIndex.
+ *
+ * @param theString source string
+ * @param theSubstring target string
+ * @param theStartIndex starting index, inclusive
+ * @param theEndIndex ending index, exclusive
+ * @return Returns a reference to theSubstring
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
+substring(
+ const XalanDOMChar* theString,
+ XalanDOMString& theSubstring,
+ unsigned int theStartIndex,
+ unsigned int theEndIndex =
unsigned(-1));
+
+
+
+/**
+ * Simulates the java String method substring(). Returns a new string that is
+ * a substring of this string. The substring begins at the specified
+ * theStartIndex and extends to the character at index theEndIndex - 1. Thus
+ * the length of the substring is theEndIndex - theStartIndex.
+ *
+ * @param theString source string
+ * @param theSubstring target string
+ * @param theStartIndex starting index, inclusive
+ * @param theEndIndex ending index, exclusive
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+substring(
+ const XalanDOMString& theString,
+ XalanDOMString& theSubstring,
+ unsigned int theStartIndex,
+ unsigned int theEndIndex =
unsigned(-1));
+
+
+
+/**
+ * Simulates the java String method substring(). Returns a new string that is
+ * a substring of this string. The substring begins at the specified
+ * theStartIndex and extends to the character at index theEndIndex - 1. Thus
* the length of the substring is theEndIndex-theStartIndex.
*
- * @param theString target string
+ * @param theString source string
* @param theStartIndex starting index, inclusive
* @param theEndIndex ending index, exclusive
* @return string containing the specified range of characters from target
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]