Ejemplo n.º 1
0
 /**
  * Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) <strong>escape</strong>
  * operation on a <tt>char[]</tt> input.
  *
  * <p><em>Level 2</em> means this method will escape:
  *
  * <ul>
  *   <li>The CSS Identifier basic escape set:
  *       <ul>
  *         <li>The <em>Backslash Escapes</em>: <tt>&#92; </tt> (<tt>U+0020</tt>), <tt>&#92;!</tt>
  *             (<tt>U+0021</tt>), <tt>&#92;&quot;</tt> (<tt>U+0022</tt>), <tt>&#92;#</tt>
  *             (<tt>U+0023</tt>), <tt>&#92;$</tt> (<tt>U+0024</tt>), <tt>&#92;%</tt>
  *             (<tt>U+0025</tt>), <tt>&#92;&amp;</tt> (<tt>U+0026</tt>), <tt>&#92;&#39;</tt>
  *             (<tt>U+0027</tt>), <tt>&#92;(</tt> (<tt>U+0028</tt>), <tt>&#92;)</tt>
  *             (<tt>U+0029</tt>), <tt>&#92;*</tt> (<tt>U+002A</tt>), <tt>&#92;+</tt>
  *             (<tt>U+002B</tt>), <tt>&#92;,</tt> (<tt>U+002C</tt>), <tt>&#92;.</tt>
  *             (<tt>U+002E</tt>), <tt>&#92;&#47;</tt> (<tt>U+002F</tt>), <tt>&#92;;</tt>
  *             (<tt>U+003B</tt>), <tt>&#92;&lt;</tt> (<tt>U+003C</tt>), <tt>&#92;=</tt>
  *             (<tt>U+003D</tt>), <tt>&#92;&gt;</tt> (<tt>U+003E</tt>), <tt>&#92;?</tt>
  *             (<tt>U+003F</tt>), <tt>&#92;@</tt> (<tt>U+0040</tt>), <tt>&#92;[</tt>
  *             (<tt>U+005B</tt>), <tt>&#92;&#92;</tt> (<tt>U+005C</tt>), <tt>&#92;]</tt>
  *             (<tt>U+005D</tt>), <tt>&#92;^</tt> (<tt>U+005E</tt>), <tt>&#92;`</tt>
  *             (<tt>U+0060</tt>), <tt>&#92;{</tt> (<tt>U+007B</tt>), <tt>&#92;|</tt>
  *             (<tt>U+007C</tt>), <tt>&#92;}</tt> (<tt>U+007D</tt>) and <tt>&#92;~</tt>
  *             (<tt>U+007E</tt>). Note that the <tt>&#92;-</tt> (<tt>U+002D</tt>) escape sequence
  *             exists, but will only be used when an identifier starts with two hypens or hyphen +
  *             digit. Also, the <tt>&#92;_</tt> (<tt>U+005F</tt>) escape will only be used at the
  *             beginning of an identifier to avoid problems with Internet Explorer 6. In the same
  *             sense, note that the <tt>&#92;:</tt> (<tt>U+003A</tt>) escape sequence is also
  *             defined in the standard, but will not be used for escaping as Internet Explorer
  *             &lt; 8 does not recognize it.
  *         <li>Two ranges of non-displayable, control characters: <tt>U+0000</tt> to
  *             <tt>U+001F</tt> and <tt>U+007F</tt> to <tt>U+009F</tt>.
  *       </ul>
  *   <li>All non ASCII characters.
  * </ul>
  *
  * <p>This escape will be performed by using Backslash escapes whenever possible. For escaped
  * characters that do not have an associated Backslash, default to <tt>&#92;FF </tt> Hexadecimal
  * Escapes.
  *
  * <p>This method calls {@link #escapeCssIdentifier(char[], int, int, java.io.Writer,
  * CssIdentifierEscapeType, CssIdentifierEscapeLevel)} with the following preconfigured values:
  *
  * <ul>
  *   <li><tt>type</tt>: {@link CssIdentifierEscapeType#BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA}
  *   <li><tt>level</tt>: {@link
  *       CssIdentifierEscapeLevel#LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET}
  * </ul>
  *
  * <p>This method is <strong>thread-safe</strong>.
  *
  * @param text the <tt>char[]</tt> to be escaped.
  * @param offset the position in <tt>text</tt> at which the escape operation should start.
  * @param len the number of characters in <tt>text</tt> that should be escaped.
  * @param writer the <tt>java.io.Writer</tt> to which the escaped result will be written. Nothing
  *     will be written at all to this writer if <tt>text</tt> is <tt>null</tt>.
  * @throws IOException if an input/output exception occurs
  */
 public static void escapeCssIdentifier(
     final char[] text, final int offset, final int len, final Writer writer) throws IOException {
   escapeCssIdentifier(
       text,
       offset,
       len,
       writer,
       CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA,
       CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET);
 }
 private CssFinder toCSS() {
   return new CssFinder("." + CssEscape.escapeCssIdentifier(this.unescapedClassName));
 }