Example usage for org.apache.commons.lang CharUtils unicodeEscaped

List of usage examples for org.apache.commons.lang CharUtils unicodeEscaped

Introduction

In this page you can find the example usage for org.apache.commons.lang CharUtils unicodeEscaped.

Prototype

public static String unicodeEscaped(Character ch) 

Source Link

Document

Converts the string to the unicode format '\u0020'.

Usage

From source file:de.interactive_instruments.ShapeChange.Target.JSON.JsonSchema.java

/**
 * <p>See https://tools.ietf.org/html/rfc7159: characters that must be escaped quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)</p>
 * <p>Control characters that are likely to occur in EA models, especially when using memo tagged values: \n, \r and \t.</p>
 *///from   ww  w  .j  a v a  2  s  . c o  m
private String escape(String s2) {
    return StringUtils.replaceEach(s2, new String[] { "\"", "\\", "\n", "\r", "\t" },
            new String[] { "\\\"", "\\\\", CharUtils.unicodeEscaped('\n'), CharUtils.unicodeEscaped('\r'),
                    CharUtils.unicodeEscaped('\t') });
}

From source file:org.apache.tajo.util.StringUtils.java

public static String unicodeEscapedDelimiter(char c) {
    return CharUtils.unicodeEscaped(c);
}

From source file:org.apache.tajo.util.TestStringUtil.java

@Test
public void testUnicodeEscapedDelimiter() {
    for (int i = 0; i < 128; i++) {
        char c = (char) i;
        String delimiter = CharUtils.unicodeEscaped(c);
        String escapedDelimiter = StringUtils.unicodeEscapedDelimiter(delimiter);
        assertEquals(delimiter, escapedDelimiter);
        assertEquals(1, StringEscapeUtils.unescapeJava(escapedDelimiter).length());
        assertEquals(c, StringEscapeUtils.unescapeJava(escapedDelimiter).charAt(0));
    }/*w  w w. j  a  va  2  s .c om*/
}

From source file:org.apache.tajo.util.TestStringUtil.java

@Test
public void testUnescapedDelimiter() {
    for (int i = 0; i < 128; i++) {
        char c = (char) i;
        String delimiter = String.valueOf(c);
        String escapedDelimiter = StringUtils.unicodeEscapedDelimiter(delimiter);
        assertEquals(CharUtils.unicodeEscaped(c), escapedDelimiter);
        assertEquals(1, StringEscapeUtils.unescapeJava(escapedDelimiter).length());
        assertEquals(c, StringEscapeUtils.unescapeJava(escapedDelimiter).charAt(0));
    }/*  w  ww  .j  a v a 2  s .  c  o  m*/
}

From source file:org.gtdfree.ApplicationHelper.java

/**
 * Escape in Java style in readable friendly way common control characters and other control characters.
 * @param in input string//from   w  w w  .jav a2 s .c  o  m
 * @return escaped string in Java style
 */
public static String escapeControls(String in) {
    if (in == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder(in.length() + 10);

    for (int i = 0; i < in.length(); i++) {
        char ch = in.charAt(i);

        switch (ch) {
        case '\b':
            sb.append('\\');
            sb.append('b');
            break;
        case '\n':
            sb.append('\\');
            sb.append('n');
            break;
        case '\t':
            sb.append('\\');
            sb.append('t');
            break;
        case '\f':
            sb.append('\\');
            sb.append('f');
            break;
        case '\r':
            sb.append('\\');
            sb.append('r');
            break;
        /*case '\'':
            if (escapeSingleQuote) {
              out.write('\\');
            }
            out.write('\'');
            break;*/
        case '\\':
            sb.append('\\');
            sb.append('\\');
            break;
        default:
            // TODO: this does not escape properly split characters. Should I care?  
            if (Character.isISOControl(ch)) {
                sb.append(CharUtils.unicodeEscaped(ch));
            } else {
                sb.append(ch);
            }
            break;
        }

    }

    return sb.toString();
}

From source file:org.novelang.parser.unicode.UnicodeNamesTest.java

@Test
public void logSomeBasicCharacterRepresentations() {
    final int aCharacterAsInt = 'a';
    final String aCharacterAsHex = TextTools.to16ByteHex(aCharacterAsInt);
    LOGGER.info("\nThe 'a' letter", "\nAs int: ", aCharacterAsInt, "\nAs hex: ", aCharacterAsHex,
            "\nUnicode escaped: ", CharUtils.unicodeEscaped('a'));
}