android空白字符串,android Character.isWhitespace 判断是否是空白char及提供判断空白字符串...

这有个工具类可以判断字符串的:来自Blankj的项目

private static boolean isSpace(final String s) {

if (s == null) return true;

for (int i = 0, len = s.length(); i < len; ++i) {

if (!Character.isWhitespace(s.charAt(i))) {

return false;

}

}

return true;

}

然后看一下源码,理解深入一点:

/**

* Determines if the specified character is white space according to Java.

* A character is a Java whitespace character if and only if it satisfies

* one of the following criteria:

*

*

It is a Unicode space character ({@code SPACE_SEPARATOR},

* {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})

* but is not also a non-breaking space ({@code '\u005Cu00A0'},

* {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).

*

It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.

*

It is {@code '\u005Cn'}, U+000A LINE FEED.

*

It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.

*

It is {@code '\u005Cf'}, U+000C FORM FEED.

*

It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.

*

It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.

*

It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.

*

It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.

*

It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.

*

*

*

Note: This method cannot handle

* href="#supplementary"> supplementary characters

. To support

* all Unicode characters, including supplementary characters, use

* the {@link #isWhitespace(int)} method.

*

* @param ch the character to be tested.

* @return {@code true} if the character is a Java whitespace

* character; {@code false} otherwise.

* @see Character#isSpaceChar(char)

* @since 1.1

*/

public static boolean isWhitespace(char ch) {

return isWhitespace((int)ch);

}

/**

* Determines if the specified character (Unicode code point) is

* white space according to Java. A character is a Java

* whitespace character if and only if it satisfies one of the

* following criteria:

*

*

It is a Unicode space character ({@link #SPACE_SEPARATOR},

* {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})

* but is not also a non-breaking space ({@code '\u005Cu00A0'},

* {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).

*

It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.

*

It is {@code '\u005Cn'}, U+000A LINE FEED.

*

It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.

*

It is {@code '\u005Cf'}, U+000C FORM FEED.

*

It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.

*

It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.

*

It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.

*

It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.

*

It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.

*

*

*

* @param codePoint the character (Unicode code point) to be tested.

* @return {@code true} if the character is a Java whitespace

* character; {@code false} otherwise.

* @see Character#isSpaceChar(int)

* @since 1.5

*/

public static boolean isWhitespace(int codePoint) {

// We don't just call into icu4c because of the JNI overhead. Ideally we'd fix that.

// Any ASCII whitespace character?

if ((codePoint >= 0x1c && codePoint <= 0x20) || (codePoint >= 0x09 && codePoint <= 0x0d)) {

return true;

}

if (codePoint < 0x1000) {

return false;

}

// OGHAM SPACE MARK or MONGOLIAN VOWEL SEPARATOR?

if (codePoint == 0x1680 || codePoint == 0x180e) {

return true;

}

if (codePoint < 0x2000) {

return false;

}

// Exclude General Punctuation's non-breaking spaces (which includes FIGURE SPACE).

if (codePoint == 0x2007 || codePoint == 0x202f) {

return false;

}

if (codePoint <= 0xffff) {

// Other whitespace from General Punctuation...

return codePoint <= 0x200a || codePoint == 0x2028 || codePoint == 0x2029 || codePoint == 0x205f ||

codePoint == 0x3000; // ...or CJK Symbols and Punctuation?

}

// Let icu4c worry about non-BMP code points.

return isWhitespaceImpl(codePoint);

}

native static boolean isWhitespaceImpl(int codePoint);

这里面已经是判的

Unicode

了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值