Java Code Examples for com.sun.org.apache.xml.internal.utils.XMLString#length()

The following examples show how to use com.sun.org.apache.xml.internal.utils.XMLString#length() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XString.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two strings lexicographically.
 *
 * @param   xstr   the <code>String</code> to be compared.
 *
 * @return  the value <code>0</code> if the argument string is equal to
 *          this string; a value less than <code>0</code> if this string
 *          is lexicographically less than the string argument; and a
 *          value greater than <code>0</code> if this string is
 *          lexicographically greater than the string argument.
 * @exception java.lang.NullPointerException if <code>anotherString</code>
 *          is <code>null</code>.
 */
public int compareTo(XMLString xstr)
{

  int len1 = this.length();
  int len2 = xstr.length();
  int n = Math.min(len1, len2);
  int i = 0;
  int j = 0;

  while (n-- != 0)
  {
    char c1 = this.charAt(i);
    char c2 = xstr.charAt(j);

    if (c1 != c2)
    {
      return c1 - c2;
    }

    i++;
    j++;
  }

  return len1 - len2;
}
 
Example 2
Source File: XStringForFSB.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  FastStringBuffer fsb = fsb();
  int to = m_start + toffset;
  int tlim = m_start + m_length;
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > m_length - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (fsb.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 3
Source File: XStringForFSB.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Compares two strings lexicographically.
 *
 * @param   xstr   the <code>String</code> to be compared.
 *
 * @return  the value <code>0</code> if the argument string is equal to
 *          this string; a value less than <code>0</code> if this string
 *          is lexicographically less than the string argument; and a
 *          value greater than <code>0</code> if this string is
 *          lexicographically greater than the string argument.
 * @exception java.lang.NullPointerException if <code>anotherString</code>
 *          is <code>null</code>.
 */
public int compareTo(XMLString xstr)
{

  int len1 = m_length;
  int len2 = xstr.length();
  int n = Math.min(len1, len2);
  FastStringBuffer fsb = fsb();
  int i = m_start;
  int j = 0;

  while (n-- != 0)
  {
    char c1 = fsb.charAt(i);
    char c2 = xstr.charAt(j);

    if (c1 != c2)
    {
      return c1 - c2;
    }

    i++;
    j++;
  }

  return len1 - len2;
}
 
Example 4
Source File: XStringForFSB.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  FastStringBuffer fsb = fsb();
  int to = m_start + toffset;
  int tlim = m_start + m_length;
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > m_length - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (fsb.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 5
Source File: XStringForFSB.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  FastStringBuffer fsb = fsb();
  int to = m_start + toffset;
  int tlim = m_start + m_length;
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > m_length - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (fsb.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 6
Source File: XStringForFSB.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares two strings lexicographically.
 *
 * @param   xstr   the <code>String</code> to be compared.
 *
 * @return  the value <code>0</code> if the argument string is equal to
 *          this string; a value less than <code>0</code> if this string
 *          is lexicographically less than the string argument; and a
 *          value greater than <code>0</code> if this string is
 *          lexicographically greater than the string argument.
 * @exception java.lang.NullPointerException if <code>anotherString</code>
 *          is <code>null</code>.
 */
public int compareTo(XMLString xstr)
{

  int len1 = m_length;
  int len2 = xstr.length();
  int n = Math.min(len1, len2);
  FastStringBuffer fsb = fsb();
  int i = m_start;
  int j = 0;

  while (n-- != 0)
  {
    char c1 = fsb.charAt(i);
    char c2 = xstr.charAt(j);

    if (c1 != c2)
    {
      return c1 - c2;
    }

    i++;
    j++;
  }

  return len1 - len2;
}
 
Example 7
Source File: XStringForFSB.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares two strings lexicographically.
 *
 * @param   xstr   the <code>String</code> to be compared.
 *
 * @return  the value <code>0</code> if the argument string is equal to
 *          this string; a value less than <code>0</code> if this string
 *          is lexicographically less than the string argument; and a
 *          value greater than <code>0</code> if this string is
 *          lexicographically greater than the string argument.
 * @exception java.lang.NullPointerException if <code>anotherString</code>
 *          is <code>null</code>.
 */
public int compareTo(XMLString xstr)
{

  int len1 = m_length;
  int len2 = xstr.length();
  int n = Math.min(len1, len2);
  FastStringBuffer fsb = fsb();
  int i = m_start;
  int j = 0;

  while (n-- != 0)
  {
    char c1 = fsb.charAt(i);
    char c2 = xstr.charAt(j);

    if (c1 != c2)
    {
      return c1 - c2;
    }

    i++;
    j++;
  }

  return len1 - len2;
}
 
Example 8
Source File: XStringForFSB.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares two strings lexicographically, ignoring case considerations.
 * This method returns an integer whose sign is that of
 * <code>this.toUpperCase().toLowerCase().compareTo(
 * str.toUpperCase().toLowerCase())</code>.
 * <p>
 * Note that this method does <em>not</em> take locale into account,
 * and will result in an unsatisfactory ordering for certain locales.
 * The java.text package provides <em>collators</em> to allow
 * locale-sensitive ordering.
 *
 * @param   xstr   the <code>String</code> to be compared.
 *
 * @return  a negative integer, zero, or a positive integer as the
 *          the specified String is greater than, equal to, or less
 *          than this String, ignoring case considerations.
 * @see     java.text.Collator#compare(String, String)
 * @since   1.2
 */
public int compareToIgnoreCase(XMLString xstr)
{

  int len1 = m_length;
  int len2 = xstr.length();
  int n = Math.min(len1, len2);
  FastStringBuffer fsb = fsb();
  int i = m_start;
  int j = 0;

  while (n-- != 0)
  {
    char c1 = Character.toLowerCase(fsb.charAt(i));
    char c2 = Character.toLowerCase(xstr.charAt(j));

    if (c1 != c2)
    {
      return c1 - c2;
    }

    i++;
    j++;
  }

  return len1 - len2;
}
 
Example 9
Source File: XString.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Convert a string to a double -- Allowed input is in fixed
   * notation ddd.fff.
   *
   * @return A double value representation of the string, or return Double.NaN
   * if the string can not be converted.
   */
  public double toDouble()
  {
    /* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
     * characters as white space characters.
     * ht - horizontal tab, nl - newline , cr - carriage return and sp - space
     * trim() methods by default also takes care of these white space characters
     * So trim() method is used to remove leading and trailing white spaces.
     */
        XMLString s = trim();
        double result = Double.NaN;
        for (int i = 0; i < s.length(); i++)
        {
                char c = s.charAt(i);
    if (c != '-' && c != '.' && ( c < 0X30 || c > 0x39)) {
            // The character is not a '-' or a '.' or a digit
            // then return NaN because something is wrong.
                        return result;
        }
        }
        try
        {
                result = Double.parseDouble(s.toString());
        } catch (NumberFormatException e){}

        return result;
}
 
Example 10
Source File: XStringForFSB.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares two strings lexicographically, ignoring case considerations.
 * This method returns an integer whose sign is that of
 * <code>this.toUpperCase().toLowerCase().compareTo(
 * str.toUpperCase().toLowerCase())</code>.
 * <p>
 * Note that this method does <em>not</em> take locale into account,
 * and will result in an unsatisfactory ordering for certain locales.
 * The java.text package provides <em>collators</em> to allow
 * locale-sensitive ordering.
 *
 * @param   xstr   the <code>String</code> to be compared.
 *
 * @return  a negative integer, zero, or a positive integer as the
 *          the specified String is greater than, equal to, or less
 *          than this String, ignoring case considerations.
 * @see     java.text.Collator#compare(String, String)
 * @since   1.2
 */
public int compareToIgnoreCase(XMLString xstr)
{

  int len1 = m_length;
  int len2 = xstr.length();
  int n = Math.min(len1, len2);
  FastStringBuffer fsb = fsb();
  int i = m_start;
  int j = 0;

  while (n-- != 0)
  {
    char c1 = Character.toLowerCase(fsb.charAt(i));
    char c2 = Character.toLowerCase(xstr.charAt(j));

    if (c1 != c2)
    {
      return c1 - c2;
    }

    i++;
    j++;
  }

  return len1 - len2;
}
 
Example 11
Source File: XString.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  int to = toffset;
  int tlim = this.length();
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > tlim - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (this.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 12
Source File: XString.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Convert a string to a double -- Allowed input is in fixed
   * notation ddd.fff.
   *
   * @return A double value representation of the string, or return Double.NaN
   * if the string can not be converted.
   */
  public double toDouble()
  {
    /* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
     * characters as white space characters.
     * ht - horizontal tab, nl - newline , cr - carriage return and sp - space
     * trim() methods by default also takes care of these white space characters
     * So trim() method is used to remove leading and trailing white spaces.
     */
        XMLString s = trim();
        double result = Double.NaN;
        for (int i = 0; i < s.length(); i++)
        {
                char c = s.charAt(i);
    if (c != '-' && c != '.' && ( c < 0X30 || c > 0x39)) {
            // The character is not a '-' or a '.' or a digit
            // then return NaN because something is wrong.
                        return result;
        }
        }
        try
        {
                result = Double.parseDouble(s.toString());
        } catch (NumberFormatException e){}

        return result;
}
 
Example 13
Source File: XString.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  int to = toffset;
  int tlim = this.length();
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > tlim - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (this.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 14
Source File: XString.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
   * Convert a string to a double -- Allowed input is in fixed
   * notation ddd.fff.
   *
   * @return A double value representation of the string, or return Double.NaN
   * if the string can not be converted.
   */
  public double toDouble()
  {
    /* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
     * characters as white space characters.
     * ht - horizontal tab, nl - newline , cr - carriage return and sp - space
     * trim() methods by default also takes care of these white space characters
     * So trim() method is used to remove leading and trailing white spaces.
     */
        XMLString s = trim();
        double result = Double.NaN;
        for (int i = 0; i < s.length(); i++)
        {
                char c = s.charAt(i);
    if (c != '-' && c != '.' && ( c < 0X30 || c > 0x39)) {
            // The character is not a '-' or a '.' or a digit
            // then return NaN because something is wrong.
                        return result;
        }
        }
        try
        {
                result = Double.parseDouble(s.toString());
        } catch (NumberFormatException e){}

        return result;
}
 
Example 15
Source File: XStringForFSB.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  FastStringBuffer fsb = fsb();
  int to = m_start + toffset;
  int tlim = m_start + m_length;
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > m_length - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (fsb.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 16
Source File: XStringForFSB.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Compares this string to the specified object.
 * The result is <code>true</code> if and only if the argument is not
 * <code>null</code> and is a <code>String</code> object that represents
 * the same sequence of characters as this object.
 *
 * @param   obj2       the object to compare this <code>String</code>
 *                     against.
 *
 * @return  <code>true</code> if the <code>String </code>are equal;
 *          <code>false</code> otherwise.
 * @see     java.lang.String#compareTo(java.lang.String)
 * @see     java.lang.String#equalsIgnoreCase(java.lang.String)
 */
public boolean equals(XMLString obj2)
{

  if (this == obj2)
  {
    return true;
  }

  int n = m_length;

  if (n == obj2.length())
  {
    FastStringBuffer fsb = fsb();
    int i = m_start;
    int j = 0;

    while (n-- != 0)
    {
      if (fsb.charAt(i) != obj2.charAt(j))
      {
        return false;
      }

      i++;
      j++;
    }

    return true;
  }

  return false;
}
 
Example 17
Source File: XString.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if this string starts with the specified prefix beginning
 * a specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(XMLString prefix, int toffset)
{

  int to = toffset;
  int tlim = this.length();
  int po = 0;
  int pc = prefix.length();

  // Note: toffset might be near -1>>>1.
  if ((toffset < 0) || (toffset > tlim - pc))
  {
    return false;
  }

  while (--pc >= 0)
  {
    if (this.charAt(to) != prefix.charAt(po))
    {
      return false;
    }

    to++;
    po++;
  }

  return true;
}
 
Example 18
Source File: XString.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
   * Convert a string to a double -- Allowed input is in fixed
   * notation ddd.fff.
   *
   * @return A double value representation of the string, or return Double.NaN
   * if the string can not be converted.
   */
  public double toDouble()
  {
    /* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
     * characters as white space characters.
     * ht - horizontal tab, nl - newline , cr - carriage return and sp - space
     * trim() methods by default also takes care of these white space characters
     * So trim() method is used to remove leading and trailing white spaces.
     */
        XMLString s = trim();
        double result = Double.NaN;
        for (int i = 0; i < s.length(); i++)
        {
                char c = s.charAt(i);
    if (c != '-' && c != '.' && ( c < 0X30 || c > 0x39)) {
            // The character is not a '-' or a '.' or a digit
            // then return NaN because something is wrong.
                        return result;
        }
        }
        try
        {
                result = Double.parseDouble(s.toString());
        } catch (NumberFormatException e){}

        return result;
}
 
Example 19
Source File: FuncSubstring.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XMLString s1 = m_arg0.execute(xctxt).xstr();
  double start = m_arg1.execute(xctxt).num();
  int lenOfS1 = s1.length();
  XMLString substr;

  if (lenOfS1 <= 0)
    return XString.EMPTYSTRING;
  else
  {
    int startIndex;

    if (Double.isNaN(start))
    {

      // Double.MIN_VALUE doesn't work with math below
      // so just use a big number and hope I never get caught.
      start = -1000000;
      startIndex = 0;
    }
    else
    {
      start = Math.round(start);
      startIndex = (start > 0) ? (int) start - 1 : 0;
    }

    if (null != m_arg2)
    {
      double len = m_arg2.num(xctxt);
      int end = (int) (Math.round(len) + start) - 1;

      // Normalize end index.
      if (end < 0)
        end = 0;
      else if (end > lenOfS1)
        end = lenOfS1;

      if (startIndex > lenOfS1)
        startIndex = lenOfS1;

      substr = s1.substring(startIndex, end);
    }
    else
    {
      if (startIndex > lenOfS1)
        startIndex = lenOfS1;
      substr = s1.substring(startIndex);
    }
  }

  return (XString)substr; // cast semi-safe
}
 
Example 20
Source File: FuncSubstring.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XMLString s1 = m_arg0.execute(xctxt).xstr();
  double start = m_arg1.execute(xctxt).num();
  int lenOfS1 = s1.length();
  XMLString substr;

  if (lenOfS1 <= 0)
    return XString.EMPTYSTRING;
  else
  {
    int startIndex;

    if (Double.isNaN(start))
    {

      // Double.MIN_VALUE doesn't work with math below
      // so just use a big number and hope I never get caught.
      start = -1000000;
      startIndex = 0;
    }
    else
    {
      start = Math.round(start);
      startIndex = (start > 0) ? (int) start - 1 : 0;
    }

    if (null != m_arg2)
    {
      double len = m_arg2.num(xctxt);
      int end = (int) (Math.round(len) + start) - 1;

      // Normalize end index.
      if (end < 0)
        end = 0;
      else if (end > lenOfS1)
        end = lenOfS1;

      if (startIndex > lenOfS1)
        startIndex = lenOfS1;

      substr = s1.substring(startIndex, end);
    }
    else
    {
      if (startIndex > lenOfS1)
        startIndex = lenOfS1;
      substr = s1.substring(startIndex);
    }
  }

  return (XString)substr; // cast semi-safe
}