Here you can find the source of convertToJavaUnicode(String input, Character start1, Character end1, Character start2, Character end2)
Parameter | Description |
---|---|
input | the input String |
start1 | start of range 1 |
end1 | end of range 2 |
start2 | start of range 2 |
end2 | end of range 2 |
public static String convertToJavaUnicode(String input, Character start1, Character end1, Character start2, Character end2)
//package com.java2s; /*************************************************************** * This file is part of the [fleXive](R) framework. *//from w w w.ja v a 2 s .c o m * Copyright (c) 1999-2014 * UCS - unique computing solutions gmbh (http://www.ucs.at) * All rights reserved * * The [fleXive](R) project is free software; you can redistribute * it and/or modify it under the terms of the GNU Lesser General Public * License version 2.1 or higher as published by the Free Software Foundation. * * The GNU Lesser General Public License can be found at * http://www.gnu.org/licenses/lgpl.html. * A copy is found in the textfile LGPL.txt and important notices to the * license from the author are found in LICENSE.txt distributed with * these libraries. * * 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 General Public License for more details. * * For further information about UCS - unique computing solutions gmbh, * please see the company website: http://www.ucs.at * * For further information about [fleXive](R), please see the * project website: http://www.flexive.org * * * This copyright notice MUST APPEAR in all copies of the file! ***************************************************************/ import java.text.SimpleDateFormat; import java.util.*; public class Main { /** * Convert international characters to hex-encoded unicode format (\\u....) * internat. chars: e.g. ~ 0x007E - 0x00FF * Takes one or two character ranges as parameters (second range == null --> converted to "first" range) * Ranges are inclusive! * * @param input the input String * @param start1 start of range 1 * @param end1 end of range 2 * @param start2 start of range 2 * @param end2 end of range 2 * @return the String containing unicode characters */ public static String convertToJavaUnicode(String input, Character start1, Character end1, Character start2, Character end2) { if (start1 == null || end1 == null) return input; StringBuilder out = new StringBuilder(input.length()); String hex; char ch; if (start2 == null || end2 == null) { start2 = start1; end2 = end1; } // walk through indiv. chars and convert as needed while appending to "out" for (int i = 0; i < input.length(); i++) { ch = input.charAt(i); if ((ch >= start1) && (ch <= end1) || (ch >= start2) && (ch <= end2)) { out.append("\\u"); hex = Integer.toHexString(input.charAt(i) & 0xFFFF); // prepend 0s for (int j = 0; j < 4 - hex.length(); j++) out.append("0"); out.append(hex.toUpperCase()); } else { out.append(ch); } } return out.toString(); } public static String toString(Date date) { return getDateFormat().format(date); } /** * Returns a basic date format that is readable but not localized. * * @return a basic date format that is readable but not localized. */ public static SimpleDateFormat getDateFormat() { return new SimpleDateFormat("yyyy-MM-dd"); } }