java.lang.Object
org.miaixz.bus.extra.pinyin.PinyinKit
Pinyin utility class for quickly obtaining Pinyin.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PinyinProvidercreateEngine(String engineName) Creates a Pinyin engine.static PinyinProviderGets the global singleton Pinyin engine.static chargetFirstLetter(char c) Converts the input character to the first letter of its Pinyin; other characters are returned as is.static StringgetFirstLetter(String text, String separator) Converts the input string to the first letter of its Pinyin; other characters are returned as is.static StringgetPinyin(char c) If c is a Chinese character, returns its uppercase Pinyin; otherwise, returns String.valueOf(c).static StringgetPinyin(char c, boolean tone) If c is a Chinese character, returns its uppercase Pinyin; otherwise, returns String.valueOf(c).static StringConverts the input string to Pinyin, with spaces separating the Pinyin of each character.static StringConverts the input string to Pinyin, with spaces separating the Pinyin of each character.static StringConverts the input string to Pinyin, inserting a separator between the Pinyin of each character.static StringConverts the input string to Pinyin, inserting a separator between the Pinyin of each character.static booleanisChinese(char c) Checks if a character is a Chinese character.
-
Constructor Details
-
PinyinKit
public PinyinKit()
-
-
Method Details
-
createEngine
Creates a Pinyin engine.- Parameters:
engineName- The engine name.- Returns:
PinyinProvider
-
getEngine
Gets the global singleton Pinyin engine.- Returns:
- The global singleton Pinyin engine.
-
getPinyin
If c is a Chinese character, returns its uppercase Pinyin; otherwise, returns String.valueOf(c).- Parameters:
c- Any character. Chinese characters are converted to Pinyin, others are returned as is.- Returns:
- Chinese characters are converted to Pinyin, others are returned as is.
-
getPinyin
If c is a Chinese character, returns its uppercase Pinyin; otherwise, returns String.valueOf(c).- Parameters:
c- Any character. Chinese characters are converted to Pinyin, others are returned as is.tone- Whether to include tone marks.- Returns:
- Chinese characters are converted to Pinyin, others are returned as is.
-
getPinyin
Converts the input string to Pinyin, with spaces separating the Pinyin of each character.- Parameters:
text- Any character. Chinese characters are converted to Pinyin, others are returned as is.- Returns:
- Chinese characters are converted to Pinyin, others are returned as is.
-
getPinyin
Converts the input string to Pinyin, with spaces separating the Pinyin of each character.- Parameters:
text- Any character. Chinese characters are converted to Pinyin, others are returned as is.tone- Whether to include tone marks.- Returns:
- Chinese characters are converted to Pinyin, others are returned as is.
-
getPinyin
Converts the input string to Pinyin, inserting a separator between the Pinyin of each character.- Parameters:
text- Any character. Chinese characters are converted to Pinyin, others are returned as is.separator- The separator between the Pinyin of each character.- Returns:
- Chinese characters are converted to Pinyin, others are returned as is.
-
getPinyin
Converts the input string to Pinyin, inserting a separator between the Pinyin of each character.- Parameters:
text- Any character. Chinese characters are converted to Pinyin, others are returned as is.separator- The separator between the Pinyin of each character.tone- Whether to include tone marks.- Returns:
- Chinese characters are converted to Pinyin, others are returned as is.
-
getFirstLetter
public static char getFirstLetter(char c) Converts the input character to the first letter of its Pinyin; other characters are returned as is.- Parameters:
c- Any character. Chinese characters are converted to the first letter of their Pinyin, others are returned as is.- Returns:
- The first letter of the Pinyin for Chinese characters, or the original character for others.
-
getFirstLetter
Converts the input string to the first letter of its Pinyin; other characters are returned as is.- Parameters:
text- Any character string. Chinese characters are converted to the first letter of their Pinyin, others are returned as is.separator- The separator.- Returns:
- The first letters of the Pinyin for Chinese characters, or the original characters for others.
-
isChinese
public static boolean isChinese(char c) Checks if a character is a Chinese character.- Parameters:
c- The character.- Returns:
- Whether the character is a Chinese character.
-