当前位置:网站首页>String.toLowerCase(Locale.ROOT)
String.toLowerCase(Locale.ROOT)
2022-08-09 06:27:00 【Koala Rice Bowl】
String.toLowerCase(Locale.ROOT)
环境:jdk1.8
Localeis the transformation rule for the region
首先看到Locale类中的ROOTis an object initialized with two empty strings,表示所有语言环境的基本语言环境,并且用于语言/国家无关的区域设置,用于区域设置敏感的操作.
/** * Useful constant for the root locale. The root locale is the locale whose * language, country, and variant are empty ("") strings. This is regarded * as the base locale of all locales, and is used as the language/country * neutral locale for the locale sensitive operations. * * @since 1.6 */
static public final Locale ROOT = createConstant("", "");
Some language and regional properties
/** Useful constant for language. */
static public final Locale JAPANESE = createConstant("ja", "");
/** Useful constant for language. */
static public final Locale KOREAN = createConstant("ko", "");
/** Useful constant for language. */
static public final Locale CHINESE = createConstant("zh", "");
/** Useful constant for language. */
static public final Locale SIMPLIFIED_CHINESE = createConstant("zh", "CN"); // 中国简体
/** Useful constant for language. */
static public final Locale TRADITIONAL_CHINESE = createConstant("zh", "TW"); // 中国繁体
/** Useful constant for country. */
static public final Locale FRANCE = createConstant("fr", "FR");
/** Useful constant for country. */
static public final Locale GERMANY = createConstant("de", "DE");
/** Useful constant for country. */
static public final Locale ITALY = createConstant("it", "IT");
/** Useful constant for country. */
static public final Locale JAPAN = createConstant("ja", "JP");
/** Useful constant for country. */
static public final Locale KOREA = createConstant("ko", "KR");
来看看StringA parameterless method to lowercase
public String toLowerCase() {
return toLowerCase(Locale.getDefault()); // The final call is all parameterized to lowercase
}
// 这里调用Locale的initDefault获取Locale
private static Locale initDefault() {
String language, region, script, country, variant;
language = AccessController.doPrivileged(
new GetPropertyAction("user.language", "en")); // Get the language of the host
// for compatibility, check for old user.region property
region = AccessController.doPrivileged(
new GetPropertyAction("user.region")); // Get the host's region
if (region != null) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
if (i >= 0) {
country = region.substring(0, i);
variant = region.substring(i + 1);
} else {
country = region;
variant = "";
}
script = "";
} else {
script = AccessController.doPrivileged(
new GetPropertyAction("user.script", ""));
country = AccessController.doPrivileged(
new GetPropertyAction("user.country", ""));
variant = AccessController.doPrivileged(
new GetPropertyAction("user.variant", ""));
}
return getInstance(language, script, country, variant, null);
}
Get the language and region above,Most are in mainland China -Duser.language=“zh” \ -Duser.region=“CN” \
也就是对应的
static public final Locale SIMPLIFIED_CHINESE = createConstant("zh", "CN");
来看看StringThe final method to lowercase:
public String toLowerCase(Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int firstUpper;
final int len = value.length;
/* Now check if there are any characters that need to be changed. */
scan: {
for (firstUpper = 0 ; firstUpper < len; ) {
char c = value[firstUpper];
if ((c >= Character.MIN_HIGH_SURROGATE)
&& (c <= Character.MAX_HIGH_SURROGATE)) {
int supplChar = codePointAt(firstUpper);
if (supplChar != Character.toLowerCase(supplChar)) {
break scan;
}
firstUpper += Character.charCount(supplChar);
} else {
if (c != Character.toLowerCase(c)) {
break scan;
}
firstUpper++;
}
}
return this;
}
char[] result = new char[len];
int resultOffset = 0; /* result may grow, so i+resultOffset * is the write location in result */
/* Just copy the first few lowerCase characters. */
System.arraycopy(value, 0, result, 0, firstUpper);
String lang = locale.getLanguage();
boolean localeDependent =
(lang == "tr" || lang == "az" || lang == "lt");
char[] lowerCharArray;
int lowerChar;
int srcChar;
int srcCount;
for (int i = firstUpper; i < len; i += srcCount) {
srcChar = (int)value[i];
if ((char)srcChar >= Character.MIN_HIGH_SURROGATE
&& (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
srcChar = codePointAt(i);
srcCount = Character.charCount(srcChar);
} else {
srcCount = 1;
}
if (localeDependent ||
srcChar == '\u03A3' || // Greek capital letters
srcChar == '\u0130') {
// 拉丁文大写字母Idot on top
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if ((lowerChar == Character.ERROR)
|| (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
if (lowerChar == Character.ERROR) {
lowerCharArray =
ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
} else if (srcCount == 2) {
resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
continue;
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed */
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
char[] result2 = new char[result.length + mapLen - srcCount];
System.arraycopy(result, 0, result2, 0, i + resultOffset);
result = result2;
}
for (int x = 0; x < mapLen; ++x) {
result[i + resultOffset + x] = lowerCharArray[x];
}
resultOffset += (mapLen - srcCount);
} else {
result[i + resultOffset] = (char)lowerChar;
}
}
return new String(result, 0, len + resultOffset);
}
从上面toLowerCase方法中
boolean localeDependent =
(lang == "tr" || lang == "az" || lang == "lt");
See this line,The method of converting to lowercase only deals with a small number of special languages
总结
If there is no special language, use no parameter directlytoLowerCase即可,I haven't done research on performance,If you are interested, you can compare
边栏推荐
- 超顺磁四氧化三铁@二氧化硅@硫化镉纳米核壳结构材料|表面接枝mPEG的Fe3O4磁性纳米颗粒(f-Fe3O4)|相关产品
- Text String Length Sorting - Online Tool
- Getting started with kubernetes apparmor
- Unity Gobang Game Design and Simple AI (2)
- DevNet: Deviation Aware Networkfor Lane Detection
- Fragments
- Silently start over, the first page is also a new page
- Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
- flask创建数据库失败未报错
- 什么是excel文件保护
猜你喜欢
Used to import the data type
缓存技术使用
Excel受保护的工作表怎么操作?
phpstudy 安装 flarum论坛
Molybdenum disulfide/hafnium dioxide composite nanomaterials (MoS2/HfO2) | tantalum-doped hafnium dioxide nanoparticles (Qi Yue bio)
pdf加密、找回密码
Deep Learning - Principles of Neural Networks 2
How to automatically fill down an excel table without dragging the mouse down
JMeter test - JMeter 】 【 upload multiple images/batch CSV file upload pictures interface parametric method
使用百度EasyDL实现智能垃圾箱
随机推荐
语句加锁分析
Redis 2 - 高级
Unity 五子棋游戏设计和简单AI(2)
Web APIs BOM- 操作浏览器:本地存储
flask创建数据库失败未报错
锁执行的过程
Harbor Enterprise Mirror Warehouse Construction
推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”
phpstudy 安装 flarum论坛
A test engineer with an annual salary of 35W was laid off. Personal experience: advice that you have to listen to
深度学习-神经网络原理2
[R language] interaction test data
SiO2/KH550修饰四氧化三铁纳米磁性颗粒|PDA包裹四氧化三铁磁性纳米颗粒(科研级)
Getting started with kubernetes apparmor
workbench 数据导出
阿里巴巴官方技术号
C# 利用iTextSharp画PDF
Output method of list string print(*a) print(““.join(str(c) for c in a) )
mongo+ycsb性能测试及线程数分析
常用Oracle命令