Module bus.extra

Class PinyinKit

java.lang.Object
org.miaixz.bus.extra.pinyin.PinyinKit

public class PinyinKit extends Object
Pinyin utility class for quickly obtaining Pinyin.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createEngine(String engineName)
    Creates a Pinyin engine.
    Gets the global singleton Pinyin engine.
    static char
    Converts the input character to the first letter of its Pinyin; other characters are returned as is.
    static String
    getFirstLetter(String text, String separator)
    Converts the input string to the first letter of its Pinyin; other characters are returned as is.
    static String
    getPinyin(char c)
    If c is a Chinese character, returns its uppercase Pinyin; otherwise, returns String.valueOf(c).
    static String
    getPinyin(char c, boolean tone)
    If c is a Chinese character, returns its uppercase Pinyin; otherwise, returns String.valueOf(c).
    static String
    Converts the input string to Pinyin, with spaces separating the Pinyin of each character.
    static String
    getPinyin(String text, boolean tone)
    Converts the input string to Pinyin, with spaces separating the Pinyin of each character.
    static String
    getPinyin(String text, String separator)
    Converts the input string to Pinyin, inserting a separator between the Pinyin of each character.
    static String
    getPinyin(String text, String separator, boolean tone)
    Converts the input string to Pinyin, inserting a separator between the Pinyin of each character.
    static boolean
    isChinese(char c)
    Checks if a character is a Chinese character.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PinyinKit

      public PinyinKit()
  • Method Details

    • createEngine

      public static PinyinProvider createEngine(String engineName)
      Creates a Pinyin engine.
      Parameters:
      engineName - The engine name.
      Returns:
      PinyinProvider
    • getEngine

      public static PinyinProvider getEngine()
      Gets the global singleton Pinyin engine.
      Returns:
      The global singleton Pinyin engine.
    • getPinyin

      public static String getPinyin(char c)
      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

      public static String getPinyin(char c, boolean tone)
      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

      public static String getPinyin(String text)
      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

      public static String getPinyin(String text, boolean tone)
      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

      public static String getPinyin(String text, String separator)
      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

      public static String getPinyin(String text, String separator, boolean tone)
      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

      public static String getFirstLetter(String text, String separator)
      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.