List of usage examples for java.lang Character codePointAt
public static int codePointAt(char[] a, int index)
From source file:org.apache.syncope.core.spring.security.SecureRandomUtils.java
public static String generateRandomSpecialCharacter(final char[] characters) { return new RandomStringGenerator.Builder().usingRandom(new SecureTextRandomProvider()) .filteredBy(codePoint -> { boolean found = false; for (int i = 0; i < characters.length && !found; i++) { found = codePoint == Character.codePointAt(characters, i); }/*from www .j a va 2s .c om*/ return found; }).build().generate(1); }
From source file:Main.java
/** * Determines if a character sequence is a QName. A QName is either an * NCName (LocalName), or an NCName followed by a colon followed by another * NCName (where the first NCName is referred to as the 'Prefix Name' and * the second NCName is referred to as the 'Local Name' - i.e. * PrefixName:LocalName)./*from ww w . j ava 2 s . com*/ * * @param s * The character sequence to be tested. * @return {@code true} if {@code s} is a QName, otherwise {@code false}. */ public static boolean isQName(CharSequence s) { if (isNullOrEmpty(s)) { return false; } boolean foundColon = false; boolean inNCName = false; for (int i = 0; i < s.length();) { int codePoint = Character.codePointAt(s, i); if (codePoint == ':') { if (foundColon) { return false; } foundColon = true; if (!inNCName) { return false; } inNCName = false; } else { if (!inNCName) { if (!isXMLNameStartCharacter(codePoint)) { return false; } inNCName = true; } else { if (!isXMLNameChar(codePoint)) { return false; } } } i += Character.charCount(codePoint); } return true; }
From source file:org.mariotaku.twidere.util.CodePointArray.java
public CodePointArray(@NonNull final CharSequence cs) { final int inputLength = cs.length(); codePoints = new int[inputLength]; int codePointsLength = 0; for (int offset = 0; offset < inputLength;) { final int codePoint = Character.codePointAt(cs, offset); codePoints[codePointsLength++] = codePoint; offset += Character.charCount(codePoint); }/*www.ja va 2 s . c o m*/ this.length = codePointsLength; }
From source file:Main.java
/** * Escapes a character sequence so that it is valid XML. * /*from ww w . j av a 2s. c om*/ * @param s * The character sequence. * @return The escaped version of the character sequence. */ public static String escapeXML(CharSequence s) { // double quote -- quot // ampersand -- amp // less than -- lt // greater than -- gt // apostrophe -- apos StringBuilder sb = new StringBuilder(s.length() * 2); for (int i = 0; i < s.length();) { int codePoint = Character.codePointAt(s, i); if (codePoint == '<') { sb.append(LT); } else if (codePoint == '>') { sb.append(GT); } else if (codePoint == '\"') { sb.append(QUOT); } else if (codePoint == '&') { sb.append(AMP); } else if (codePoint == '\'') { sb.append(APOS); } else { sb.appendCodePoint(codePoint); } i += Character.charCount(codePoint); } return sb.toString(); }
From source file:org.openo.nfvo.jujuvnfmadapter.common.StringUtil.java
/** * /*from w w w . java2 s . c om*/ * Get the JSON string from input http context.<br> * * @param vnfReq * @return * @since NFVO 0.5 */ @SuppressWarnings("unchecked") public static <T> T getJsonFromContexts(HttpServletRequest vnfReq) { try { InputStream vnfInput = vnfReq.getInputStream(); String vnfJsonStr = IOUtils.toString(vnfInput); JSONTokener vnfJsonTokener = new JSONTokener(vnfJsonStr); if (vnfJsonTokener.nextClean() == Character.codePointAt("{", 0)) { return (T) JSONObject.fromObject(vnfJsonStr); } vnfJsonTokener.back(); if (vnfJsonTokener.nextClean() == Character.codePointAt("[", 0)) { return (T) JSONArray.fromObject(vnfJsonStr); } } catch (IOException e) { LOG.error("function=getJsonFromContext, msg=IOException occurs, e={}.", e); } catch (JSONException e) { LOG.error("function=getJsonFromContext, msg=JSONException occurs, e={}.", e); } return null; }
From source file:cherry.foundation.validator.CharTypeValidator.java
private int[] createAcceptable(String acceptable) { int[] result = new int[acceptable.codePointCount(0, acceptable.length())]; for (int i = 0, j = 0; i < acceptable.length(); i++) { if (Character.isLowSurrogate(acceptable.charAt(i))) { continue; }//from w w w .jav a 2 s.c o m result[j++] = Character.codePointAt(acceptable, i); } return result; }
From source file:com.igormaznitsa.jcp.expression.functions.FunctionSTR2WEB.java
@Override @Nonnull//w w w . j a v a 2 s. c o m public Value executeStr(@Nonnull final PreprocessorContext context, @Nonnull final Value value) { final String escaped = StringEscapeUtils.escapeHtml3(value.asString()); final StringBuilder result = new StringBuilder(escaped.length() * 2); for (int i = 0; i < escaped.length(); i++) { final char ch = escaped.charAt(i); if (CharUtils.isAscii(ch)) { result.append(ch); } else { result.append("&#").append(Integer.toString(Character.codePointAt(escaped, i))).append(';'); } } return Value.valueOf(result.toString()); }
From source file:Main.java
/** * Gets the index of the longest NCName that is the suffix of a character * sequence./*from w ww. j ava2 s . c om*/ * * @param s * The character sequence. * @return The index of the longest suffix of the specified character * sequence {@code s} that is an NCName, or -1 if the character * sequence {@code s} does not have a suffix that is an NCName. */ public static int getNCNameSuffixIndex(CharSequence s) { // identify bnode labels and do not try to split them if (s.length() > 1 && s.charAt(0) == '_' && s.charAt(1) == ':') { return -1; } int index = -1; for (int i = s.length() - 1; i > -1; i--) { if (!Character.isLowSurrogate(s.charAt(i))) { int codePoint = Character.codePointAt(s, i); if (isNCNameStartChar(codePoint)) { index = i; } if (!isNCNameChar(codePoint)) { break; } } } return index; }
From source file:jp.furplag.util.commons.StringUtils.java
/** * return the Array of Unicode code points in the string. * * @param str the string, may be null.//from w w w .ja v a2 s . co m * @return Array of codepoints. */ public static int[] getCodePoints(final String str) { char[] chars = defaultString(str).toCharArray(); int[] ret = new int[Character.codePointCount(chars, 0, chars.length)]; int index = 0; for (int i = 0, codePoint; i < chars.length; i += Character.charCount(codePoint)) { codePoint = Character.codePointAt(chars, i); ret[index++] = codePoint; } return ret; }
From source file:dhr.uploadtomicrobit.FirmwareGenerator.java
public String generateFirmware(String script) { System.out.println("Sketch being processed"); System.out.println(script);/*from ww w .java2 s .co m*/ StringBuilder output = new StringBuilder(); StringBuilder tempScript = new StringBuilder(); // Get the whole script into output. output.append(MicrobitFirmware.getFirmware()); //System.out.println("Firmware is: " + output.toString()); // add header, pad to multiple of 16 bytes int[] data = new int[4 + script.length() + (16 - (4 + script.length()) % 16)]; data[0] = 77; // 'M' data[1] = 80; // 'P' data[2] = script.length() & 0xff; data[3] = (script.length() >> 8) & 0xff; for (int i = 0; i < script.length(); ++i) { int codePointAt0 = Character.codePointAt(script, i); data[4 + i] = codePointAt0; } // convert to .hex format int addr = 0x3e000; // magic start address in flash int[] chunk = new int[5 + 16]; //output.append(":020000040003F7\n"); for (int i = 0; i < data.length; i += 16, addr += 16) { chunk[0] = 16; // length of data section chunk[1] = (addr >> 8) & 0xff; // high byte of 16-bit addr chunk[2] = addr & 0xff; // low byte of 16-bit addr chunk[3] = 0; // type (data) for (int j = 0; j < 16; ++j) { chunk[4 + j] = data[i + j]; } int checksum = 0; for (int j = 0; j < 4 + 16; ++j) { checksum += chunk[j]; } chunk[4 + 16] = (-checksum) & 0xff; tempScript.append(':' + hexlify(chunk)); tempScript.append(System.lineSeparator()); } // Simple replace strategy on the firmware should allow updates of the firmware //System.out.println(output.toString()); System.out.println(tempScript); replaceString(output, ":::::::::::::::::::::::::::::::::::::::::::", tempScript.toString()); //output.append(MicrobitFirmware.getFirmwareTrailer()); // Return a full string - ready to copy return output.toString(); }