本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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('_', '.');
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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('\'');
}
示例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();
}