Example usage for java.lang Character codePointAt

List of usage examples for java.lang Character codePointAt

Introduction

In this page you can find the example usage for java.lang Character codePointAt.

Prototype

public static int codePointAt(char[] a, int index) 

Source Link

Document

Returns the code point at the given index of the char array.

Usage

From source file:Main.java

public static void main(String[] args) {
    CharSequence seq = "Hello";
    int index = 4;
    int res = Character.codePointAt(seq, index);

    String str = "Unicode code point is " + res;

    System.out.println(str);/*from w  ww  .jav  a2s  . c om*/
}

From source file:Main.java

public static void main(String[] args) {
    char[] c = new char[] { 'j', 'b', 'c', 'd', 'e' };
    int index = 0;

    int res = Character.codePointAt(c, index);
    System.out.println("Unicode code point is " + res);
}

From source file:Main.java

/**
 * Gets the index of the longest NCName that is the suffix of a character
 * sequence.//w  w w .  j a  v a  2 s.  c  o m
 * 
 * @param cs
 *           The character sequence.
 * @return Returns the index of the longest suffix of the specified character
 *         sequence <code>cs</code> that is an NCName, or -1 if the character
 *         sequence <code>cs</code> does not have a suffix that is an NCName.
 */
public static int getNCNameSuffixIndex(CharSequence cs) {
    int index = -1;
    for (int i = cs.length() - 1; i > -1; i--) {
        if (!Character.isLowSurrogate(cs.charAt(i))) {
            int c = Character.codePointAt(cs, i);
            if (isNCNameStartChar(c)) {
                index = i;
            }
            if (!isNCNameChar(c)) {
                break;
            }
        }
    }
    return index;
}

From source file:Main.java

/**
 * Determines if the input character sequence <code>cs</code> is a NCName
 * (Non-Colon Name). An NCName is a string which starts with an NCName start
 * character and is followed by zero or more NCName characters.
 * //w ww . j  av  a2s .co m
 * Source: http://www.w3.org/TR/xml-names/#NT-NCName
 * 
 * @param cs
 *           The character sequence to test.
 * @return Returns <code>true</code> if the input character sequence is a
 *         NCName or <code>false</code> otherwise.
 */
public static boolean isNCName(CharSequence cs) {
    if (isEmpty(cs)) {
        return false;
    }
    int firstChar = Character.codePointAt(cs, 0);
    if (!isNCNameStartChar(firstChar)) {
        return false;
    }
    for (int i = Character.charCount(firstChar); i < cs.length();) {
        int c = Character.codePointAt(cs, i);
        if (!isNCNameChar(c)) {
            return false;
        }
        i += Character.charCount(c);
    }
    return true;
}

From source file:Main.java

/**
 * Determines if a character sequence is a QName.
 * <p>// ww  w.  j a va2 s  .c  o m
 * A QName is either:
 * <ul>
 * <li>an NCName (LocalName), or</li>
 * <li>an NCName followed by a colon and by another NCName
 * (PrefixName:LocalName)</li>
 * </ul>
 *
 * Source: http://www.w3.org/TR/xml-names/#NT-QName
 *
 * @param s
 *           The character sequence to test.
 * @return Returns <code>true</code> if the character sequence
 *         <code>cs</code> is a QName, or <code>false</code> otherwise.
 */
public static boolean isQName(CharSequence s) {
    if (isEmpty(s)) {
        return false;
    }
    boolean foundColon = false;
    boolean inNCName = false;
    for (int i = 0; i < s.length();) {
        int c = Character.codePointAt(s, i);
        if (c == ':') { //$NON-NLS-1$
            if (foundColon) {
                return false;
            }
            foundColon = true;
            if (!inNCName) {
                return false;
            }
            inNCName = false;
        } else {
            if (!inNCName) {
                if (!isXmlNameStartChar(c)) {
                    return false;
                }
                inNCName = true;
            } else {
                if (!isXmlNameChar(c)) {
                    return false;
                }
            }
        }
        i += Character.charCount(c);
    }
    return true;
}

From source file:org.openo.nfvo.vnfmdriver.common.restfulutil.HttpContextUitl.java

/**
 * <br>/*ww  w .  j a  va2  s  .  c  om*/
 *
 * @param vnfReq
 * @return
 * @since NFVO 0.5
 */
@SuppressWarnings("unchecked")
public static <T> T extractJsonObject(HttpServletRequest vnfReq) {
    T ret = null;
    try {
        InputStream vnfInput = vnfReq.getInputStream();
        String vnfJsonStr = IOUtils.toString(vnfInput);
        JSONTokener vnfJsonTokener = new JSONTokener(vnfJsonStr);

        if (vnfJsonTokener.nextClean() == Character.codePointAt("{", 0)) {
            ret = (T) JSONObject.fromObject(vnfJsonStr);
        }

        vnfJsonTokener.back();

        if (vnfJsonTokener.nextClean() == Character.codePointAt("[", 0)) {
            ret = (T) JSONArray.fromObject(vnfJsonStr);
        }
    } catch (IOException e) {
        LOG.warn("IOException! " + e.getMessage());
    } catch (JSONException e) {
        LOG.warn("JSONException! " + e.getMessage());
    }

    return ret;
}

From source file:uk.ac.bbsrc.tgac.miso.core.factory.barcode.MisoJscriptFactory.java

private static String unicodeify(String barcode) {
    log.info("ORIGINAL :: " + barcode);
    StringBuilder b = new StringBuilder();
    int count = 0;
    for (Character c : barcode.toCharArray()) {
        if (Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN) {
            int codePoint = Character.codePointAt(barcode, count);
            b.append("[U:$").append(String.format("%04x", codePoint).toUpperCase()).append("]");
        } else {//from  www.j a va  2  s  . com
            b.append(c);
        }
        count++;
    }
    log.info("UNICODED :: " + b.toString());
    return b.toString();
}

From source file:org.openo.nfvo.vnfmadapter.common.VnfmJsonUtil.java

/**
 * Get the JSON string from input http context.
 * <br/>/*w  w  w .  j  ava  2  s .  c  om*/
 *
 * @param vnfReq HttpServletRequest
 * @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) {
        LOGGER.error("function=getJsonFromContext, msg=IOException occurs, e={}.", e);
    } catch (JSONException e) {
        LOGGER.error("function=getJsonFromContext, msg=JSONException occurs, e={}.", e);
    }

    return null;
}

From source file:Main.java

/**
 * Similar to String.contains() with two main differences:
 * <p>/*from   w  ww.  j a  va  2 s  . co  m*/
 * 1) Only searches token prefixes.  A token is defined as any combination of letters or
 * numbers.
 * <p>
 * 2) Returns the starting index where the substring is found.
 *
 * @param value The string to search.
 * @param substring The substring to look for.
 * @return The starting index where the substring is found. {@literal -1} if substring is not
 *         found in value.
 */
@VisibleForTesting
static int contains(String value, String substring) {
    if (value.length() < substring.length()) {
        return -1;
    }

    // i18n support
    // Generate the code points for the substring once.
    // There will be a maximum of substring.length code points.  But may be fewer.
    // Since the array length is not an accurate size, we need to keep a separate variable.
    final int[] substringCodePoints = new int[substring.length()];
    int substringLength = 0; // may not equal substring.length()!!
    for (int i = 0; i < substring.length();) {
        final int codePoint = Character.codePointAt(substring, i);
        substringCodePoints[substringLength] = codePoint;
        substringLength++;
        i += Character.charCount(codePoint);
    }

    for (int i = 0; i < value.length(); i = findNextTokenStart(value, i)) {
        int numMatch = 0;
        for (int j = i; j < value.length() && numMatch < substringLength; ++numMatch) {
            int valueCp = Character.toLowerCase(value.codePointAt(j));
            int substringCp = substringCodePoints[numMatch];
            if (valueCp != substringCp) {
                break;
            }
            j += Character.charCount(valueCp);
        }
        if (numMatch == substringLength) {
            return i;
        }
    }
    return -1;
}

From source file:Main.java

/**
 * Determines if a character sequence is an NCName (Non-Colonised Name). An
 * NCName is a string which starts with an NCName start character and is
 * followed by zero or more NCName characters.
 * /*from  w w w .  j av a 2  s .co  m*/
 * @param s
 *        The character sequence to be tested.
 * @return {@code true} if {@code s} is an NCName, otherwise {@code false}.
 */
public static boolean isNCName(@Nullable CharSequence s) {
    if (isNullOrEmpty(s)) {
        return false;
    }
    assert s != null;
    int firstCodePoint = Character.codePointAt(s, 0);
    if (!isNCNameStartChar(firstCodePoint)) {
        return false;
    }
    for (int i = Character.charCount(firstCodePoint); i < s.length();) {
        int codePoint = Character.codePointAt(s, i);
        if (!isNCNameChar(codePoint)) {
            return false;
        }
        i += Character.charCount(codePoint);
    }
    return true;
}