List of usage examples for java.lang String codePointAt
public int codePointAt(int index)
From source file:brooklyn.util.os.Os.java
/** * Checks whether a file system path is absolute in a platform neutral way. * <p>/*www .j a v a 2 s . co m*/ * As a consequence of the platform neutrality some edge cases are * not handled correctly: * <ul> * <li>On Windows relative paths starting with slash (either forward or backward) or ~ are treated as absolute. * <li>On UNIX relative paths starting with X:/ are treated as absolute. * </ul> * * @param path A string representing a file system path. * @return whether the path is absolute under the above constraints. */ public static boolean isAbsolutish(String path) { return path.codePointAt(0) == SEPARATOR_UNIX || path.equals("~") || path.startsWith("~" + SEPARATOR_UNIX) || path.length() >= 3 && path.codePointAt(1) == ':' && isSeparator(path.codePointAt(2)); }
From source file:jp.furplag.util.commons.StringUtils.java
/** * normalize a String with Japanese Kana Convert. * * <pre>/*from w ww .j a v a 2 s .c o m*/ * StringUtils.normalizeKana(null, {@code true}/{@code false}) = null * StringUtils.normalizeKana(null, true) = "" * StringUtils.normalizeKana("abc123???", true) = "abcdef123456" * StringUtils.normalize("abc123???", false) = "abcdef123456????????" * </pre> * * @param str the string, may be null. * @param hiraToKata {@code true} then Hiragana to Katakana. * @return Normalize a String with Japanese Kana Convert. */ public static String normalizeKana(final String str, final boolean hiraToKata) { if (isSimilarToBlank(str)) return null; String temporary = normalize(str); Pattern pattern = Pattern.compile(hiraToKata ? "[\u3040-\u309F]" : "[\u30A0-\u30FF]"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < temporary.length(); i++) { String s = temporary.substring(i, i + 1); sb.append(pattern.matcher(s).matches() ? new String(new int[] { s.codePointAt(0) + (hiraToKata ? 96 : -96) }, 0, 1) : s); } return sb.toString(); }
From source file:org.apache.any23.extractor.calendar.BaseCalendarExtractor.java
private static String camelCase(String name, boolean forProperty) { String[] nameComponents = name.toLowerCase(Locale.ENGLISH).split("-"); StringBuilder sb = new StringBuilder(name.length()); int i = 0;/*from ww w . j av a2s . co m*/ if (forProperty) { sb.append(nameComponents[i++]); } for (int len = nameComponents.length; i < len; i++) { String n = nameComponents[i]; if (!n.isEmpty()) { int ind = Character.charCount(n.codePointAt(0)); sb.append(n.substring(0, ind).toUpperCase(Locale.ENGLISH)).append(n.substring(ind)); } } return sb.toString(); }
From source file:password.pwm.util.java.StringUtil.java
public static int[] toCodePointArray(final String str) { if (str != null) { final int len = str.length(); final int[] acp = new int[str.codePointCount(0, len)]; for (int i = 0, j = 0; i < len; i = str.offsetByCodePoints(i, 1)) { acp[j++] = str.codePointAt(i); }//w w w .j a v a 2 s . c o m return acp; } return new int[0]; }
From source file:org.web4thejob.studio.controller.impl.PropertyEditorController.java
private static boolean isEvent(String name) { return name.startsWith("on") && name.length() > 2 && name.codePointAt(2) >= "A".codePointAt(0); }
From source file:org.opendatakit.common.utils.WebUtils.java
/** * Return a string with utf-8 characters replaced with backslash-uxxxx codes. * Useful for debugging.//from w ww .j a va2 s . c o m * * @param str * @return printable rendition of non-ASCII utf-8 characters. */ public static final String escapeUTF8String(String str) { StringBuilder b = new StringBuilder(); for (int i = 0; i < str.length(); ++i) { int code = str.codePointAt(i); if (code < 127) { b.append(str.charAt(i)); } else { String val = Integer.toHexString(code); while (val.length() < 4) { val = '0' + val; } b.append("\\u" + val); } } return b.toString(); }
From source file:Main.java
/** * This is useful since vCard 3.0 often requires the ("X-") properties and groups * should contain only alphabets, digits, and hyphen. * //from w w w . j av a2s .c o m * Note: It is already known some devices (wrongly) outputs properties with characters * which should not be in the field. One example is "X-GOOGLE TALK". We accept * such kind of input but must never output it unless the target is very specific * to the device which is able to parse the malformed input. */ public static boolean containsOnlyAlphaDigitHyphen(String str) { if (TextUtils.isEmpty(str)) { return true; } final int lowerAlphabetFirst = 0x41; // included ('A') final int lowerAlphabetLast = 0x5b; // not included ('[') final int upperAlphabetFirst = 0x61; // included ('a') final int upperAlphabetLast = 0x7b; // included ('{') final int digitFirst = 0x30; // included ('0') final int digitLast = 0x39; // included ('9') final int hyphen = '-'; final int length = str.length(); for (int i = 0; i < length; i = str.offsetByCodePoints(i, 1)) { int codepoint = str.codePointAt(i); if (!((lowerAlphabetFirst <= codepoint && codepoint < lowerAlphabetLast) || (upperAlphabetFirst <= codepoint && codepoint < upperAlphabetLast) || (digitFirst <= codepoint && codepoint < digitLast) || (codepoint == hyphen))) { return false; } } return true; }
From source file:net.metanotion.json.JsonPath.java
private static int read(final String cs, final int[] position) { try {/* w ww .j a va2s. c om*/ final int c = cs.codePointAt(position[0]); position[0]++; return c; } catch (IndexOutOfBoundsException ioobe) { return -1; } }
From source file:Main.java
public static String $$insertWordBreaks(String value, int maxCharsBetweenWordBreaks) { StringBuilder result = new StringBuilder(); // These variables keep track of important state while looping through the string below. boolean isInTag = false; // whether we're inside an HTML tag boolean isMaybeInEntity = false; // whether we might be inside an HTML entity int numCharsWithoutBreak = 0; // number of characters since the last word break for (int codePoint, i = 0; i < value.length(); i += Character.charCount(codePoint)) { codePoint = value.codePointAt(i); // If hit maxCharsBetweenWordBreaks, and next char is not a space, then add <wbr>. if (numCharsWithoutBreak >= maxCharsBetweenWordBreaks && codePoint != ' ') { result.append("<wbr>"); numCharsWithoutBreak = 0;/*from www . j av a2 s .c o m*/ } if (isInTag) { // If inside an HTML tag and we see '>', it's the end of the tag. if (codePoint == '>') { isInTag = false; } } else if (isMaybeInEntity) { switch (codePoint) { // If maybe inside an entity and we see ';', it's the end of the entity. The entity // that just ended counts as one char, so increment numCharsWithoutBreak. case ';': isMaybeInEntity = false; ++numCharsWithoutBreak; break; // If maybe inside an entity and we see '<', we weren't actually in an entity. But // now we're inside an HTML tag. case '<': isMaybeInEntity = false; isInTag = true; break; // If maybe inside an entity and we see ' ', we weren't actually in an entity. Just // correct the state and reset the numCharsWithoutBreak since we just saw a space. case ' ': isMaybeInEntity = false; numCharsWithoutBreak = 0; break; } } else { // !isInTag && !isInEntity switch (codePoint) { // When not within a tag or an entity and we see '<', we're now inside an HTML tag. case '<': isInTag = true; break; // When not within a tag or an entity and we see '&', we might be inside an entity. case '&': isMaybeInEntity = true; break; // When we see a space, reset the numCharsWithoutBreak count. case ' ': numCharsWithoutBreak = 0; break; // When we see a non-space, increment the numCharsWithoutBreak. default: ++numCharsWithoutBreak; break; } } // In addition to adding <wbr>s, we still have to add the original characters. result.appendCodePoint(codePoint); } return result.toString(); }
From source file:com.careerly.utils.TextUtils.java
/** * ?/*w w w .j av a 2s . co m*/ * * @param text * @return */ public static String removeDoubleByte(String text) { if (StringUtils.isBlank(text)) { return StringUtils.EMPTY; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < text.codePointCount(0, text.length()); i++) { char[] chars = Character.toChars(text.codePointAt(i)); if (chars.length == 1) { stringBuilder.append(String.valueOf(chars)); } } return stringBuilder.toString(); }