code: public String serialize(String identifier)
      {
          if (StringUtils.isEmpty(identifier)) {
              return identifier;
          }
  
          int length = identifier.length();
          int index = -1;
          StringBuilder result = new StringBuilder();
          int firstCodeUnit = identifier.charAt(0);
  
          while (++index < length) {
              int codeUnit = identifier.charAt(index);
              // Note: there's no need to special-case astral symbols, surrogate pairs, or lone surrogates.
  
              // If the character is NULL (U+0000), throw an IllegalArgumentException exception and terminate these steps.
              if (codeUnit == 0x0000) {
                  throw new IllegalArgumentException("Invalid character: the input contains U+0000.");
  
              } else if (shouldEscapeAsCodePoint(codeUnit, index, firstCodeUnit)) {
                  // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
                  result.append('\\').append(Integer.toHexString(codeUnit)).append(' ');
  
              } else if (index == 0 && length == 1 && codeUnit == 0x002D) {
                  // If the character is the first character and is a '-' (U+002D), and there is no second character
                  // https://drafts.csswg.org/cssom/#escape-a-character
                  result.append('\\').append(identifier.charAt(index));
  
              } else if (shouldNotEscape(codeUnit)) {
                  // the character itself
                  result.append(identifier.charAt(index));
  
              } else {
                  // Otherwise, the escaped character.
                  // https://drafts.csswg.org/cssom/#escape-a-character
                  result.append('\\').append(identifier.charAt(index));
              }
          }
  
          return result.toString();
      }
docs: Serialize a CSS identifier.
  <p>
  NOTE: This code was adapted from Mathias Bynens' CSS.escape polyfill, available under the MIT license.
  </p>
  <p>
  See https://drafts.csswg.org/cssom/#serialize-an-identifier and https://github.com/mathiasbynens/CSS.escape.
  </p>
  
  @param identifier the identifier to serialize
  @return the serialized identifier
  @throws IllegalArgumentException if the input contains U+0000