public static @NotNull String unescapeIllegalXmlChars(@NotNull String text) {
    StringBuilder b = null;
    int lastPos = 0;
    for (int i = 0; i < text.length(); i++) {
      int c = text.charAt(i);
      if (c == '#') {
        int numberEnd = text.indexOf('#', i + 1);
        if (numberEnd > 0) {
          int charCode;
          try {
            charCode = numberEnd == i + 1 ? '#' : Integer.parseInt(text.substring(i + 1, numberEnd), 16);
          }
          catch (NumberFormatException e) {
            continue;
          }
          if (b == null) b = new StringBuilder(text.length());
          b.append(text, lastPos, i);
          b.append((char)charCode);
          //noinspection AssignmentToForLoopParameter
          i = numberEnd;
          lastPos = i + 1;
        }
      }
    }
    return b == null ? text : b.append(text, lastPos, text.length()).toString();
  }
public static @NotNull String unescapeIllegalXmlChars(@NotNull String text)