Documentation
¶
Overview ¶
Package pinyin provides Chinese character to Pinyin conversion.
Index ¶
Constants ¶
const ( Version = "0.2.1" Author = "mozillazg, 闲耘" License = "MIT" Copyright = "Copyright (c) 2014 mozillazg, 闲耘" )
Package metadata.
const ( Normal = 0 // Plain style, no tone marks. e.g. pin yin Tone = 1 // Tone on first vowel of final. e.g. pīn yīn Tone2 = 2 // Tone as digit [0-4] after syllable. e.g. pi1n yi1n Initials = 3 // Initial consonants only. e.g. "zh g" FirstLetter = 4 // First letter of each syllable only. e.g. p y Finals = 5 // Finals only, no tone. e.g. ong uo FinalsTone = 6 // Finals with tone on first vowel. e.g. ōng uó FinalsTone2 = 7 // Finals with tone as digit [0-4]. e.g. o1ng uo2 )
Pinyin style constants (recommended).
const ( NORMAL = 0 TONE = 1 TONE2 = 2 INITIALS = 3 FIRST_LETTER = 4 FINALS = 5 FINALS_TONE = 6 FINALS_TONE2 = 7 )
Pinyin style constants (backward compatible aliases).
Variables ¶
var Heteronym = false
Heteronym enables multi-reading character mode when true.
var PinyinDict = map[int]string{}/* 42013 elements not displayed */
Pinyin dictionary scraped from zdic.net. Contains the following Unicode ranges:
CJK基本:[4E00-9FFF] CJK扩展A:[3400-4DBF] CJK扩展B:[20000-2A6DF] CJK扩展C:[2A700-2B73F] CJK扩展D:[2B740-2B81D] CJK兼容扩展:[2F800-2FA1F] CJK部首扩展:[2E80-2EFF] CJK笔画:[31C0-31EF] CJK康熙部首:[2F00-2FDF] CJK兼容:[F900-FAFF]
Characters without pinyin are commented out.
var Separator = "-"
Separator is the default join separator for Slug.
var Style = Normal
Style is the default pinyin style.
Functions ¶
func LazyPinyin ¶
LazyPinyin converts Chinese to pinyin, returning a flat slice. Unlike Pinyin, it does not support heteronyms and uses only the first reading per character.
func SinglePinyin ¶
SinglePinyin converts a single Chinese character (rune) to pinyin.
func SortInitials ¶
func SortInitials(strs []string)
SortInitials sorts the string slice by pinyin initial letters (in-place).