Java Code Examples for com.sun.org.apache.xml.internal.utils.XMLStringFactory#newstr()

The following examples show how to use com.sun.org.apache.xml.internal.utils.XMLStringFactory#newstr() . 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: XStringForFSB.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 2
Source File: XStringForFSB.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 3
Source File: XStringForFSB.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 4
Source File: XStringForFSB.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 5
Source File: XStringForFSB.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 6
Source File: XStringForFSB.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 7
Source File: XStringForFSB.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 8
Source File: XStringForFSB.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 9
Source File: XStringForFSB.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 10
Source File: XStringForFSB.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example 11
Source File: XStringForFSB.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}