Java Unicode Escape unicodeHexEscapeJava(char ch)

Here you can find the source of unicodeHexEscapeJava(char ch)

Description

converts a char to a java-style unicode escaped string

License

Open Source License

Declaration

public static final String unicodeHexEscapeJava(char ch) 

Method Source Code

//package com.java2s;
/*/*from   w  w w  .  j  av  a 2  s  .c  o m*/
 * org.daisy.util (C) 2005-2008 Daisy Consortium
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

public class Main {
    /**
     * converts a char to a java-style unicode escaped string
     */
    public static final String unicodeHexEscapeJava(char ch) {
        if (ch < 0x10) {
            return "\\u000" + Integer.toHexString(ch);
        } else if (ch < 0x100) {
            return "\\u00" + Integer.toHexString(ch);
        } else if (ch < 0x1000) {
            return "\\u0" + Integer.toHexString(ch);
        }
        return "\\u" + Integer.toHexString(ch);
    }
}

Related

  1. unicodeEscaped(Character ch)
  2. unicodeEscaped(Character ch)
  3. unicodeEscaped(final Character ch)
  4. unicodeEscaped(final String str)
  5. unicodeEscapeEncode(String unicode)
  6. unicodeUnescape(String st)