Java Hex String Create appendHexJavaScriptRepresentation(StringBuilder sb, char c)

Here you can find the source of appendHexJavaScriptRepresentation(StringBuilder sb, char c)

Description

Returns a javascript representation of the character in a hex escaped format.

License

Apache License

Parameter

Parameter Description
sb The buffer to which the hex representation should be appended.
c The character to be appended.

Declaration

public static void appendHexJavaScriptRepresentation(StringBuilder sb, char c) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  w  w  w.ja va  2 s . c  o  m
     * Returns a javascript representation of the character in a hex escaped
     * format. Although this is a rather specific method, it is made public
     * because it is also used by the JSCompiler.
     *
     * @param sb The buffer to which the hex representation should be appended.
     * @param c  The character to be appended.
     */
    public static void appendHexJavaScriptRepresentation(StringBuilder sb, char c) {
        sb.append("\\u");
        String val = Integer.toHexString(c);
        for (int j = val.length(); j < 4; j++) {
            sb.append('0');
        }
        sb.append(val);
    }
}

Related

  1. appendHexByte(final StringBuilder sb, final byte b)
  2. appendHexBytes(StringBuilder builder, byte[] bytes)
  3. appendHexDumpRowPrefix(StringBuilder dump, int row, int rowStartIndex)
  4. appendHexEntity(final StringBuilder out, final char value)
  5. appendHexEscape(StringBuilder out, int codePoint)
  6. appendHexNumber(StringBuffer target, byte b)
  7. appendHexPair(byte b, StringBuffer sb)
  8. appendHexStream(StringBuilder sb, byte[] bytes, String delimiter, boolean prefixEachValue, boolean upperCase)
  9. appendHexString(StringBuffer buffer, byte data)