Here you can find the source of quotedJavaChar(char c, StringBuilder b)
Parameter | Description |
---|---|
c | character |
b | stream to append to |
public static void quotedJavaChar(char c, StringBuilder b)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w . j ava2 s. c om * Convert character to Java-compatible source form for use in a string. * @param c character * @param b stream to append to */ public static void quotedJavaChar(char c, StringBuilder b) { switch (c) { case '\b': b.append("\\b"); break; case '\t': b.append("\\t"); break; case '\n': b.append("\\n"); break; case '\f': b.append("\\f"); break; case '\r': b.append("\\r"); break; case '\'': b.append("\\'"); break; case '\"': b.append("\\\""); break; case '\\': b.append("\\\\"); break; default: if (Character.isISOControl(c)) b.append("\\" + octal((int) c, "000")); else if (c <= '~') b.append(c); else b.append("\\u" + hex((int) c, "0000")); } } /** * Return octal string for character inserted right adjusted in template. */ public static String octal(int c, String template) { String s = Integer.toOctalString(c); return template.substring(s.length()) + s; } /** * Return hex string for character inserted right adjusted in template. */ public static String hex(int c, String template) { String s = Integer.toHexString(c); return template.substring(s.length()) + s; } }