Here you can find the source of appendHexEscape(StringBuilder out, int codePoint)
Parameter | Description |
---|---|
out | The StringBuilder to append to. |
codePoint | The Unicode code point whose hex escape sequence to append. |
public static void appendHexEscape(StringBuilder out, int codePoint)
//package com.java2s; /*/*from w w w. j a v a 2s.c o m*/ * Copyright 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** Hex digits for Soy strings (requires upper-case hex digits). */ private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * Appends the Unicode hex escape sequence for the given code point (backslash + 'u' + 4 hex * digits) to the given StringBuilder. * * Note: May append 2 escape sequences (surrogate pair) in the case of a supplementary character * (outside the Unicode BMP). * * Adapted from StringUtil.appendHexJavaScriptRepresentation(). * * @param out The StringBuilder to append to. * @param codePoint The Unicode code point whose hex escape sequence to append. */ public static void appendHexEscape(StringBuilder out, int codePoint) { if (Character.isSupplementaryCodePoint(codePoint)) { // Handle supplementary unicode values which are not representable in // javascript. We deal with these by escaping them as two 4B sequences // so that they will round-trip properly when sent from java to javascript // and back. char[] surrogates = Character.toChars(codePoint); appendHexEscape(out, surrogates[0]); appendHexEscape(out, surrogates[1]); } else { out.append("\\u").append(HEX_DIGITS[(codePoint >>> 12) & 0xF]) .append(HEX_DIGITS[(codePoint >>> 8) & 0xF]).append(HEX_DIGITS[(codePoint >>> 4) & 0xF]) .append(HEX_DIGITS[codePoint & 0xF]); } } }