List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java
public Cursor autoComplete(String cardname) throws FamiliarDbException { Cursor mCursor = null;// w ww . j av a2 s. com String convertName = null; if (cardname != null) { cardname = cardname.replace(Character.toChars(0xE6)[0], Character.toChars(0xC6)[0]).trim(); convertName = cardname.toLowerCase().replace("ae", String.valueOf(Character.toChars(0xC6)[0])); } String sql = "SELECT MIN(" + KEY_ID + ") AS " + KEY_ID + ", " + KEY_NAME + " FROM " + DATABASE_TABLE_CARDS + " WHERE " + KEY_NAME + " LIKE " + DatabaseUtils.sqlEscapeString(cardname + "%") + " OR " + KEY_NAME + " LIKE " + DatabaseUtils.sqlEscapeString(convertName + "%") + "GROUP BY " + KEY_NAME + " ORDER BY " + KEY_NAME + " COLLATE UNICODE"; try { mCursor = mDb.rawQuery(sql, null); } catch (SQLiteException e) { throw new FamiliarDbException(e); } catch (IllegalStateException e) { throw new FamiliarDbException(e); } if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; }
From source file:org.cosmo.common.util.Util.java
/** * This method ensures that the output String has only valid XML unicode characters as specified by the * XML 1.0 standard. For reference, please see the * standard. This method will return an empty String if the input is null or empty. * * @author Donoiu Cristian, GPL/* w w w . j a v a2 s .c o m*/ * @param The String whose non-valid characters we want to remove. * @return The in String, stripped of non-valid characters. */ public static String removeInvalidXMLCharacters(String s) { StringBuilder out = new StringBuilder(); // Used to hold the output. int codePoint; // Used to reference the current character. //String ss = "\ud801\udc00"; // This is actualy one unicode character, represented by two code units!!!. //System.out.println(ss.codePointCount(0, ss.length()));// See: 1 int i = 0; while (i < s.length()) { //System.out.println("i=" + i); codePoint = s.codePointAt(i); // This is the unicode code of the character. if ((codePoint == 0x9) || // Consider testing larger ranges first to improve speed. (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) { out.append(Character.toChars(codePoint)); } i += Character.charCount(codePoint); // Increment with the number of code units(java chars) needed to represent a Unicode char. } return out.toString(); }
From source file:com.jaus.albertogiunta.justintrain_oraritreni.journeyFavourites.FavouriteJourneysActivity.java
private void fetchRemoteConfigs() { ServerConfigsHelper.removeAPIEndpoint(FavouriteJourneysActivity.this); FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(BuildConfig.DEBUG).build(); firebaseRemoteConfig.setConfigSettings(configSettings); firebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults); long cacheExpiration = 720; // 1/5 hour in seconds. if (firebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) { Log.d("fetchRemoteConfigs: changing cache expiration"); cacheExpiration = 0;/*from ww w. ja v a2 s . co m*/ } firebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(this, task -> { if (task.isSuccessful()) { firebaseRemoteConfig.activateFetched(); } else { // FirebaseCrash.report(new Exception("Firebase Remote Config FAILED in ADDONCOMPLETELISTENER")); } if (firebaseRemoteConfig.getBoolean(FIREBASE_IS_STRIKE_SET)) { updateDashboard(firebaseRemoteConfig.getString(FIREBASE_STRIKE), ViewsUtils.COLORS.RED, false, false); } else if (firebaseRemoteConfig.getBoolean(FIREBASE_IS_MAINTENANCE_SET)) { updateDashboard(firebaseRemoteConfig.getString(FIREBASE_MAINTENANCE), ViewsUtils.COLORS.ORANGE, false, false); } else if (firebaseRemoteConfig.getLong(FIREBASE_LATEST_VERSION) > BuildConfig.VERSION_CODE) { updateDashboard(firebaseRemoteConfig.getString(FIREBASE_UPDATE_MESSAGE), ViewsUtils.COLORS.BLUE, true, false); } else if (FirebaseRemoteConfig.getInstance().getBoolean(FIREBASE_IS_DISCOUNT_SET)) { updateDashboard(FirebaseRemoteConfig.getInstance().getString(FIREBASE_DISCOUNT_MESSAGE), ViewsUtils.COLORS.ORANGE, false, true); } if (shouldDisplayDiscountMessage) { btnIAP.setText(FirebaseRemoteConfig.getInstance().getString(FIREBASE_UPGRADE_BTN_HOME_MESSAGE) .replace("\\n", System.getProperty("line.separator")) + " " + new String(Character.toChars(0x21AA))); apply(btnIAP, VISIBLE); } }).addOnFailureListener(this, e -> { if (shouldDisplayDiscountMessage) { apply(btnIAP, VISIBLE); } // FirebaseCrash.report(new Exception("Firebase Remote Config FAILED in ADDONFAILURELISTENER")); }); }
From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java
public Cursor Search(String cardname, String cardtext, String cardtype, String color, int colorlogic, String sets, float pow_choice, String pow_logic, float tou_choice, String tou_logic, int cmc, String cmcLogic, String format, String rarity, String flavor, String artist, int type_logic, int text_logic, int set_logic, boolean backface, String[] returnTypes, boolean consolidate) throws FamiliarDbException { Cursor mCursor = null;/*w w w .j a v a2 s . c o m*/ if (cardname != null) cardname = cardname.replace("'", "''").replace(Character.toChars(0xE6)[0], Character.toChars(0xC6)[0]) .trim(); if (cardtext != null) cardtext = cardtext.replace("'", "''").trim(); if (cardtype != null) cardtype = cardtype.replace("'", "''").trim(); if (flavor != null) flavor = flavor.replace("'", "''").trim(); if (artist != null) artist = artist.replace("'", "''").trim(); String statement = " WHERE 1=1"; if (cardname != null) { String[] nameParts = cardname.split(" "); for (String s : nameParts) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_NAME + " LIKE '%" + s + "%' OR " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " LIKE '%" + s.toLowerCase().replace("ae", String.valueOf(Character.toChars(0xC6)[0])) + "%')"; } } /*************************************************************************************/ /** * Reuben's version Differences: Original code is verbose only, but mine * allows for matching exact text, all words, or just any one word. */ if (cardtext != null) { String[] cardTextParts = cardtext.split(" "); // Separate each // individual /** * The following switch statement tests to see which text search * logic was chosen by the user. If they chose the first option (0), * then look for cards with text that includes all words, but not * necessarily the exact phrase. The second option (1) finds cards * that have 1 or more of the chosen words in their text. The third * option (2) searches for the exact phrase as entered by the user. * The 'default' option is impossible via the way the code is * written, but I believe it's also mandatory to include it in case * someone else is perhaps fussing with the code and breaks it. The * if statement at the end is theorhetically unnecessary, because * once we've entered the current if statement, there is no way to * NOT change the statement variable. However, you never really know * who's going to break open your code and fuss around with it, so * it's always good to leave some small safety measures. */ switch (text_logic) { case 0: for (String s : cardTextParts) { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " NOT LIKE '%" + s.substring(EXCLUDE_TOKEN_START) + "%')"; else statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + s + "%')"; } break; case 1: boolean firstRun = true; for (String s : cardTextParts) { if (firstRun) { firstRun = false; if (s.contains(EXCLUDE_TOKEN)) statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " NOT LIKE '%" + s.substring(EXCLUDE_TOKEN_START) + "%')"; else statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + s + "%')"; } else { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " NOT LIKE '%" + s.substring(EXCLUDE_TOKEN_START) + "%')"; else statement += " OR (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + s + "%')"; } } statement += ")"; break; case 2: statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + cardtext + "%')"; break; default: break; } } /** End Reuben's version */ /** * Reuben's version Differences: Original version only allowed for * including all types, not any of the types or excluding the given * types. */ String supertypes = null; String subtypes = null; if (cardtype != null && !cardtype.equals("-")) { boolean containsSupertype = true; if (cardtype.substring(0, 2).equals("- ")) { containsSupertype = false; } String[] split = cardtype.split(" - "); if (split.length >= 2) { supertypes = split[0].replace(" -", ""); subtypes = split[1].replace(" -", ""); } else if (containsSupertype) { supertypes = cardtype.replace(" -", ""); } else { subtypes = cardtype.replace("- ", ""); } } if (supertypes != null) { String[] supertypesParts = supertypes.split(" "); // Separate each // individual switch (type_logic) { case 0: for (String s : supertypesParts) { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } break; case 1: boolean firstRun = true; for (String s : supertypesParts) { if (firstRun) { firstRun = false; if (s.contains(EXCLUDE_TOKEN)) statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } else if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " OR (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } statement += ")"; break; case 2: for (String s : supertypesParts) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s + "%')"; } break; default: break; } } if (subtypes != null) { String[] subtypesParts = subtypes.split(" "); // Separate each // individual switch (type_logic) { case 0: for (String s : subtypesParts) { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } break; case 1: boolean firstRun = true; for (String s : subtypesParts) { if (firstRun) { firstRun = false; if (s.contains(EXCLUDE_TOKEN)) statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } else if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " OR (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } statement += ")"; break; case 2: for (String s : subtypesParts) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s + "%')"; } break; default: break; } } /** End Reuben's version */ /*************************************************************************************/ if (flavor != null) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_FLAVOR + " LIKE '%" + flavor + "%')"; } if (artist != null) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ARTIST + " LIKE '%" + artist + "%')"; } /*************************************************************************************/ /** * Code below added/modified by Reuben. Differences: Original version * only had 'Any' and 'All' options and lacked 'Exclusive' and 'Exact' * matching. In addition, original programming only provided exclusive * results. */ if (!(color.equals("wubrgl") || (color.equals("WUBRGL") && colorlogic == 0))) { boolean firstPrint = true; // Can't contain these colors /** * ...if the chosen color logic was exactly (2) or none (3) of the * selected colors */ if (colorlogic > 1) // if colorlogic is 2 or 3 it will be greater // than 1 { statement += " AND (("; for (byte b : color.getBytes()) { char c = (char) b; if (c > 'a') { if (firstPrint) firstPrint = false; else statement += " AND "; if (c == 'l' || c == 'L') statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " NOT GLOB '[CLA]'"; else statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " NOT LIKE '%" + Character.toUpperCase(c) + "%'"; } } statement += ") AND ("; } firstPrint = true; // Might contain these colors if (colorlogic < 2) statement += " AND ("; for (byte b : color.getBytes()) { char c = (char) b; if (c < 'a') { if (firstPrint) firstPrint = false; else { if (colorlogic == 1 || colorlogic == 3) statement += " AND "; else statement += " OR "; } if (c == 'l' || c == 'L') statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " GLOB '[CLA]'"; else statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " LIKE '%" + c + "%'"; } } if (colorlogic > 1) statement += "))"; else statement += ")"; } /** End of addition */ /*************************************************************************************/ if (sets != null) { statement += " AND ("; boolean first = true; for (String s : sets.split("-")) { if (first) { first = false; } else { statement += " OR "; } statement += DATABASE_TABLE_CARDS + "." + KEY_SET + " = '" + s + "'"; } statement += ")"; } if (pow_choice != NOONECARES) { statement += " AND ("; if (pow_choice > STAR) { statement += DATABASE_TABLE_CARDS + "." + KEY_POWER + " " + pow_logic + " " + pow_choice; if (pow_logic.equals("<")) { statement += " AND " + DATABASE_TABLE_CARDS + "." + KEY_POWER + " > " + STAR; } } else if (pow_logic.equals("=")) { statement += DATABASE_TABLE_CARDS + "." + KEY_POWER + " " + pow_logic + " " + pow_choice; } statement += ")"; } if (tou_choice != NOONECARES) { statement += " AND ("; if (tou_choice > STAR) { statement += DATABASE_TABLE_CARDS + "." + KEY_TOUGHNESS + " " + tou_logic + " " + tou_choice; if (tou_logic.equals("<")) { statement += " AND " + DATABASE_TABLE_CARDS + "." + KEY_TOUGHNESS + " > " + STAR; } } else if (tou_logic.equals("=")) { statement += DATABASE_TABLE_CARDS + "." + KEY_TOUGHNESS + " " + tou_logic + " " + tou_choice; } statement += ")"; } if (cmc != -1) { statement += " AND ("; statement += DATABASE_TABLE_CARDS + "." + KEY_CMC + " " + cmcLogic + " " + cmc + ")"; } if (rarity != null) { statement += " AND ("; boolean firstPrint = true; for (int i = 0; i < rarity.length(); i++) { if (firstPrint) { firstPrint = false; } else { statement += " OR "; } statement += DATABASE_TABLE_CARDS + "." + KEY_RARITY + " = " + (int) rarity.toUpperCase().charAt(i) + ""; } statement += ")"; } String tbl = DATABASE_TABLE_CARDS; if (format != null) { if (!(format.equals("Legacy") || format.equals("Vintage"))) { tbl = "(" + DATABASE_TABLE_CARDS + " JOIN " + DATABASE_TABLE_LEGAL_SETS + " ON " + DATABASE_TABLE_CARDS + "." + KEY_SET + "=" + DATABASE_TABLE_LEGAL_SETS + "." + KEY_SET + " AND " + DATABASE_TABLE_LEGAL_SETS + "." + KEY_FORMAT + "='" + format + "')"; } else { statement += " AND NOT " + KEY_SET + "= 'UNH' AND NOT " + KEY_SET + "= 'UG'"; } statement += " AND NOT EXISTS (SELECT * FROM " + DATABASE_TABLE_BANNED_CARDS + " WHERE " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " = " + DATABASE_TABLE_BANNED_CARDS + "." + KEY_NAME + " AND " + DATABASE_TABLE_BANNED_CARDS + "." + KEY_FORMAT + " = '" + format + "' AND " + DATABASE_TABLE_BANNED_CARDS + "." + KEY_LEGALITY + " = " + BANNED + ")"; } if (!backface) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_NUMBER + " NOT LIKE '%b%')"; } if (set_logic != MOSTRECENTPRINTING && set_logic != ALLPRINTINGS) { statement = " JOIN (SELECT iT" + DATABASE_TABLE_CARDS + "." + KEY_NAME + ", MIN(" + DATABASE_TABLE_SETS + "." + KEY_DATE + ") AS " + KEY_DATE + " FROM " + DATABASE_TABLE_CARDS + " AS iT" + DATABASE_TABLE_CARDS + " JOIN " + DATABASE_TABLE_SETS + " ON iT" + DATABASE_TABLE_CARDS + "." + KEY_SET + " = " + DATABASE_TABLE_SETS + "." + KEY_CODE + " GROUP BY iT" + DATABASE_TABLE_CARDS + "." + KEY_NAME + ") AS FirstPrints" + " ON " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " = FirstPrints." + KEY_NAME + statement; if (set_logic == FIRSTPRINTING) statement = " AND " + DATABASE_TABLE_SETS + "." + KEY_DATE + " = FirstPrints." + KEY_DATE + statement; else statement = " AND " + DATABASE_TABLE_SETS + "." + KEY_DATE + " <> FirstPrints." + KEY_DATE + statement; } if (statement.equals(" WHERE 1=1")) { // If the statement is just this, it means we added nothing return null; } try { String sel = null; for (String s : returnTypes) { if (sel == null) { sel = DATABASE_TABLE_CARDS + "." + s + " AS " + s; } else { sel += ", " + DATABASE_TABLE_CARDS + "." + s + " AS " + s; } } sel += ", " + DATABASE_TABLE_SETS + "." + KEY_DATE; String sql = "SELECT * FROM (SELECT " + sel + " FROM " + tbl + " JOIN " + DATABASE_TABLE_SETS + " ON " + DATABASE_TABLE_CARDS + "." + KEY_SET + " = " + DATABASE_TABLE_SETS + "." + KEY_CODE + statement; if (consolidate) { sql += " ORDER BY " + DATABASE_TABLE_SETS + "." + KEY_DATE + ") GROUP BY " + KEY_NAME + " ORDER BY " + KEY_NAME + " COLLATE UNICODE"; } else { sql += " ORDER BY " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " COLLATE UNICODE" + ", " + DATABASE_TABLE_SETS + "." + KEY_DATE + " DESC)"; } mCursor = mDb.rawQuery(sql, null); } catch (SQLiteException e) { throw new FamiliarDbException(e); } catch (IllegalStateException e) { throw new FamiliarDbException(e); } if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; }
From source file:org.openrdf.rio.turtle.TurtleParser.java
/** * Parses a "normal string". This method requires that the opening character * has already been parsed.//from w ww . j a v a 2 s .co m */ protected String parseString(int closingCharacter) throws IOException, RDFParseException { StringBuilder sb = new StringBuilder(32); while (true) { int c = readCodePoint(); if (c == closingCharacter) { break; } else if (c == -1) { throwEOFException(); } sb.append(Character.toChars(c)); if (c == '\\') { // This escapes the next character, which might be a '"' c = readCodePoint(); if (c == -1) { throwEOFException(); } sb.append(Character.toChars(c)); } } return sb.toString(); }
From source file:org.openrdf.rio.turtle.TurtleParser.java
/** * Parses a """long string""". This method requires that the first three * characters have already been parsed./*from ww w.jav a 2s.c om*/ */ protected String parseLongString(int closingCharacter) throws IOException, RDFParseException { StringBuilder sb = new StringBuilder(1024); int doubleQuoteCount = 0; int c; while (doubleQuoteCount < 3) { c = readCodePoint(); if (c == -1) { throwEOFException(); } else if (c == closingCharacter) { doubleQuoteCount++; } else { doubleQuoteCount = 0; } sb.append(Character.toChars(c)); if (c == '\\') { // This escapes the next character, which might be a '"' c = readCodePoint(); if (c == -1) { throwEOFException(); } sb.append(Character.toChars(c)); } } return sb.substring(0, sb.length() - 3); }
From source file:org.openrdf.rio.turtle.TurtleParser.java
protected Literal parseNumber() throws IOException, RDFParseException { StringBuilder value = new StringBuilder(8); IRI datatype = XMLSchema.INTEGER;/* ww w. j ava 2s.c o m*/ int c = readCodePoint(); // read optional sign character if (c == '+' || c == '-') { value.append(Character.toChars(c)); c = readCodePoint(); } while (ASCIIUtil.isNumber(c)) { value.append(Character.toChars(c)); c = readCodePoint(); } if (c == '.' || c == 'e' || c == 'E') { // read optional fractional digits if (c == '.') { if (TurtleUtil.isWhitespace(peekCodePoint())) { // We're parsing an integer that did not have a space before the // period to end the statement } else { value.append(Character.toChars(c)); c = readCodePoint(); while (ASCIIUtil.isNumber(c)) { value.append(Character.toChars(c)); c = readCodePoint(); } if (value.length() == 1) { // We've only parsed a '.' reportFatalError("Object for statement missing"); } // We're parsing a decimal or a double datatype = XMLSchema.DECIMAL; } } else { if (value.length() == 0) { // We've only parsed an 'e' or 'E' reportFatalError("Object for statement missing"); } } // read optional exponent if (c == 'e' || c == 'E') { datatype = XMLSchema.DOUBLE; value.append(Character.toChars(c)); c = readCodePoint(); if (c == '+' || c == '-') { value.append(Character.toChars(c)); c = readCodePoint(); } if (!ASCIIUtil.isNumber(c)) { reportError("Exponent value missing", BasicParserSettings.VERIFY_DATATYPE_VALUES); } value.append(Character.toChars(c)); c = readCodePoint(); while (ASCIIUtil.isNumber(c)) { value.append(Character.toChars(c)); c = readCodePoint(); } } } // Unread last character, it isn't part of the number unread(c); // String label = value.toString(); // if (datatype.equals(XMLSchema.INTEGER)) { // try { // label = XMLDatatypeUtil.normalizeInteger(label); // } // catch (IllegalArgumentException e) { // // Note: this should never happen because of the parse constraints // reportError("Illegal integer value: " + label); // } // } // return createLiteral(label, null, datatype); // Return result as a typed literal return createLiteral(value.toString(), null, datatype, getLineNumber(), -1); }
From source file:com.fluffypeople.managesieve.ManageSieveClient.java
private String parseString() throws IOException, ParseException { int token = in.nextToken(); if (token == DQUOTE) { return in.sval; } else if (token == '{') { // "Literal" String - {<length>}CRLF<length bytes of string> token = in.nextToken();/*from www .j a v a 2s . c om*/ if (token != StreamTokenizer.TT_NUMBER) { throw new ParseException( "Expecting NUMBER got " + tokenToString(token) + " at line " + in.lineno()); } // Irritatingly, the tokenizer will parse a double here, even // if we only want an int. Sigh. int length = (int) in.nval; token = in.nextToken(); if (token != '}') { throw new ParseException("Expecing } got " + tokenToString(token) + " at line " + in.lineno()); } token = in.nextToken(); if (token != StreamTokenizer.TT_EOL) { throw new ParseException("Expecting EOL got " + tokenToString(token) + " at line " + in.lineno()); } // Drop out of the tokenizer to read the raw bytes... StringBuilder rawString = new StringBuilder(); log.debug("Raw string: reading {} bytes", length); in.resetSyntax(); int count = 0; while (count < length) { token = in.nextToken(); if (token == StreamTokenizer.TT_WORD) { // Tokenizer calls unicode "WORD" even in raw(ish) mode rawString.append(in.sval); count += in.sval.getBytes(UTF8).length; } else { // Probably only ever one byte chars, however lets be // careful out there. char[] chars = Character.toChars(token); rawString.append(chars); count += chars.length; } } // Remember to reset the tokenizer now we're done setupTokenizer(); return rawString.toString(); } else { throw new ParseException( "Expecing DQUOTE or {, got " + tokenToString(token) + " at line " + in.lineno()); } }
From source file:im.delight.java.emoji.Emoji.java
private static String getUnicodeChar(int codepoint) { return new String(Character.toChars(codepoint)); }
From source file:com.fluffypeople.managesieve.ManageSieveClient.java
private String tokenToString(final int c) { if (c > 0) { return new String(Character.toChars(c)); } else {//from w w w .j a v a2 s . c o m switch (c) { case StreamTokenizer.TT_EOF: return "EOF"; case StreamTokenizer.TT_NUMBER: return "NUMBER"; case StreamTokenizer.TT_EOL: return "EOL"; case StreamTokenizer.TT_WORD: return ("WORD [" + in.sval + "]"); default: return "UNKNOWN"; } } }