當前位置: 首頁>>代碼示例>>Java>>正文


Java Character類代碼示例

本文整理匯總了Java中java.lang.Character的典型用法代碼示例。如果您正苦於以下問題:Java Character類的具體用法?Java Character怎麽用?Java Character使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Character類屬於java.lang包,在下文中一共展示了Character類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: scanEscape

import java.lang.Character; //導入依賴的package包/類
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
開發者ID:alexkasko,項目名稱:openjdk-icedtea7,代碼行數:22,代碼來源:URI.java

示例2: isPrintable

import java.lang.Character; //導入依賴的package包/類
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // [email protected]#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:ORBUtility.java

示例3: scanEscape

import java.lang.Character; //導入依賴的package包/類
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(input.charAt(p + 1), L_HEX, H_HEX)
            && match(input.charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:URI.java

示例4: readUnicodeChar

import java.lang.Character; //導入依賴的package包/類
static private int readUnicodeChar(PushbackReader r, int initch, int base, int length, boolean exact) {
	int uc = Character.digit(initch, base);
	if(uc == -1)
		throw new IllegalArgumentException("Invalid digit: " + (char) initch);
	int i = 1;
	for(; i < length; ++i)
		{
		int ch = read1(r);
		if(ch == -1 || isWhitespace(ch) || isMacro(ch))
			{
			unread(r, ch);
			break;
			}
		int d = Character.digit(ch, base);
		if(d == -1)
			throw new IllegalArgumentException("Invalid digit: " + (char) ch);
		uc = uc * base + d;
		}
	if(i != length && exact)
		throw new IllegalArgumentException("Invalid character length: " + i + ", should be: " + length);
	return uc;
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:23,代碼來源:LispReader.java

示例5: scanEscape

import java.lang.Character; //導入依賴的package包/類
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
	// Process escape pair
	if ((p + 3 <= n)
	    && match(charAt(p + 1), L_HEX, H_HEX)
	    && match(charAt(p + 2), L_HEX, H_HEX)) {
	    return p + 3;
	}
	fail("Malformed escape pair", p);
    } else if ((c > 128)
	       && !Character.isSpaceChar(c)
	       && !Character.isISOControl(c)) {
	// Allow unescaped but visible non-US-ASCII chars
	return p + 1;
    }
    return p;
}
 
開發者ID:jgaltidor,項目名稱:VarJ,代碼行數:22,代碼來源:URI.java

示例6: encryptGameTitle

import java.lang.Character; //導入依賴的package包/類
private void encryptGameTitle() {
    char oldCharTmp;
    int indexTmp;

    do {
        indexTmp = (int)(Math.random() * gameTitle.getText().length());
        oldCharTmp = gameTitle.getText().charAt(indexTmp);
    } while (!Character.isLetter(oldCharTmp) || oldCharTmp == 'M');

    final char oldChar = oldCharTmp;
    final int index = indexTmp;
    int number = (int)(Math.random() * 10);

    gameTitle.setText(gameTitle.getText().substring(0, index) + number + gameTitle.getText().substring(index + 1));
    Timer.schedule(new Timer.Task() {
        @Override
        public void run() {
            gameTitle.setText(gameTitle.getText().substring(0, index) + oldChar + gameTitle.getText().substring(index + 1));
        }
    }, ENCRYPTION_DURATION);
}
 
開發者ID:naomiHauret,項目名稱:OdysseeDesMaths,代碼行數:22,代碼來源:MenuPrincipal.java

示例7: getChildren

import java.lang.Character; //導入依賴的package包/類
@Override
public final List<Subject> getChildren() {
  List<Subject> children = new ArrayList<>();

  int begin = 0;
  for (int i = 0; i < getContent().length(); ++i) {
    Character character = new Character(getContent().charAt(i));
    if (shouldSplitAt(i, character)) {
      addSubject(children, begin, i);
      int dividerSize = addDivider(children, i, character);
      begin = i + dividerSize;
      i += dividerSize - 1;
    } else if (i + 1 == getContent().length()) {
      endReached(children, begin, character);
    }
  }

  return children;
}
 
開發者ID:croesch,項目名稱:diff,代碼行數:20,代碼來源:TextualSplittableSubject.java

示例8: nibble2Int

import java.lang.Character; //導入依賴的package包/類
public static int nibble2Int(byte nibble) {
    final char[] hexBytes = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    int out = -1;

    for (final char ch : hexBytes) {
        char nibble_ch = (char) nibble;
        nibble_ch = Character.toUpperCase(nibble_ch);
        if (nibble_ch == ch) {
            out = Character.digit(nibble,16);
            break;
        }
    }

    if (out < 0) {
        System.out.println(String.format("nibble is: %c", nibble));
        out = -1;

    }
    return out;
}
 
開發者ID:citrixsystems,項目名稱:pathweaver,代碼行數:22,代碼來源:IPUtils.java

示例9: getIOSVersion

import java.lang.Character; //導入依賴的package包/類
@Nullable
public static String getIOSVersion(@Nullable final String ua) {
    if (ua == null) return null;
    StringBuilder versionBuilder = new StringBuilder(6);
    int index = ua.indexOf("OS ");
    if (index == -1) return null;
    index += 3; // skip over "OS ".
    if (!Character.isDigit(ua.charAt(index))) {
        return null;
    }
    while (index < ua.length() && ua.charAt(index) != ' ') {
        versionBuilder.append(ua.charAt(index));
        index++;
    }
    return versionBuilder.toString().replace('_', '.');
}
 
開發者ID:indeedeng,項目名稱:proctor-demo,代碼行數:17,代碼來源:Browser.java

示例10: changeFirstCharCase

import java.lang.Character; //導入依賴的package包/類
/**
 * Return <code>str</code> modified so that its first character is now an
 * lowercase or uppercase character, depending on <code>toUpperCase</code>.
 * If <code>str</code> starts with non-alphabetic
 * characters, such as quotes or parentheses, the first character is 
 * determined as the first alphabetic character.
 */
@Nullable
private static String changeFirstCharCase(String str, boolean toUpperCase) {
  if (isEmpty(str)) {
    return str;
  }
  if (str.length() == 1) {
    return toUpperCase ? str.toUpperCase(Locale.ENGLISH) : str.toLowerCase();
  }
  int pos = 0;
  int len = str.length() - 1;
  while (!Character.isLetterOrDigit(str.charAt(pos)) && len > pos) {
    pos++;
  }
  char firstChar = str.charAt(pos);    
  return str.substring(0, pos) 
      + (toUpperCase ? Character.toUpperCase(firstChar) : Character.toLowerCase(firstChar))
      + str.substring(pos + 1);
}
 
開發者ID:languagetool-org,項目名稱:languagetool,代碼行數:26,代碼來源:StringTools.java

示例11: isWhitespace

import java.lang.Character; //導入依賴的package包/類
/**
 * Checks if a string contains a whitespace, including:
 * <ul>
 * <li>all Unicode whitespace
 * <li>the non-breaking space (U+00A0)
 * <li>the narrow non-breaking space (U+202F)
 * <li>the zero width space (U+200B), used in Khmer
 * </ul>
 * @param str String to check
 * @return true if the string is a whitespace character
 */
public static boolean isWhitespace(String str) {
  if ("\u0002".equals(str) // unbreakable field, e.g. a footnote number in OOo
      || "\u0001".equals(str)) { // breakable field in OOo
    return false;
  }
  String trimStr = str.trim();
  if (isEmpty(trimStr)) {
    return true;
  }
  if (trimStr.length() == 1) {
    if ("\u200B".equals(str)) {
      // We need u200B​​ to be detected as whitespace for Khmer, as it was the case before Java 7.
      return true;
    } else if ("\u00A0".equals(str) || "\u202F".equals(str)) {  // non-breaking space and narrow non-breaking space
      return true;
    }
    return Character.isWhitespace(trimStr.charAt(0));
  }
  return false;
}
 
開發者ID:languagetool-org,項目名稱:languagetool,代碼行數:32,代碼來源:StringTools.java

示例12: nextContractChar

import java.lang.Character; //導入依賴的package包/類
/**
 * Get the ordering priority of the next contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int nextContractChar(int ch)
{
    // First get the ordering of this single character,
    // which is always the first element in the list
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    // find out the length of the longest contracting character sequence in the list.
    // There's logic in the builder code to make sure the longest sequence is always
    // the last.
    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    // (the Normalizer is cloned here so that the seeking we do in the next loop
    // won't affect our real position in the text)
    NormalizerBase tempText = (NormalizerBase)text.clone();

    // extract the next maxLength characters in the string (we have to do this using the
    // Normalizer to ensure that our offsets correspond to those the rest of the
    // iterator is using) and store it in "fragment".
    tempText.previous();
    key.setLength(0);
    int c = tempText.next();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.next();
    }
    String fragment = key.toString();
    // now that we have that fragment, iterate through this list looking for the
    // longest sequence that matches the characters in the actual text.  (maxLength
    // is used here to keep track of the length of the longest sequence)
    // Upon exit from this loop, maxLength will contain the length of the matching
    // sequence and order will contain the collation-element value corresponding
    // to this sequence
    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (!pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    // seek our current iteration position to the end of the matching sequence
    // and return the appropriate collation-element value (if there was no matching
    // sequence, we're already seeked to the right position and order already contains
    // the correct collation-element value for the single character)
    while (maxLength > 1) {
        c = text.next();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:72,代碼來源:CollationElementIterator.java

示例13: prevContractChar

import java.lang.Character; //導入依賴的package包/類
/**
 * Get the ordering priority of the previous contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int prevContractChar(int ch)
{
    // This function is identical to nextContractChar(), except that we've
    // switched things so that the next() and previous() calls on the Normalizer
    // are switched and so that we skip entry pairs with the fwd flag turned on
    // rather than off.  Notice that we still use append() and startsWith() when
    // working on the fragment.  This is because the entry pairs that are used
    // in reverse iteration have their names reversed already.
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    NormalizerBase tempText = (NormalizerBase)text.clone();

    tempText.next();
    key.setLength(0);
    int c = tempText.previous();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.previous();
    }
    String fragment = key.toString();

    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    while (maxLength > 1) {
        c = text.previous();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:59,代碼來源:CollationElementIterator.java

示例14: appendQuoted

import java.lang.Character; //導入依賴的package包/類
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:34,代碼來源:PatternEntry.java

示例15: quote

import java.lang.Character; //導入依賴的package包/類
private static String quote(String s, long lowMask, long highMask) {
    int n = s.length();
    StringBuffer sb = null;
    boolean allowNonASCII = ((lowMask & L_ESCAPED) != 0);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c < '\u0080') {
            if (!match(c, lowMask, highMask)) {
                if (sb == null) {
                    sb = new StringBuffer();
                    sb.append(s.substring(0, i));
                }
                appendEscape(sb, (byte)c);
            } else {
                if (sb != null)
                    sb.append(c);
            }
        } else if (allowNonASCII
                   && (Character.isSpaceChar(c)
                       || Character.isISOControl(c))) {
            if (sb == null) {
                sb = new StringBuffer();
                sb.append(s.substring(0, i));
            }
            appendEncoded(sb, c);
        } else {
            if (sb != null)
                sb.append(c);
        }
    }
    return (sb == null) ? s : sb.toString();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:URI.java


注:本文中的java.lang.Character類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。