1 Star 0 Fork 3

刘选华/pinyin

forked from iamyhw/pinyin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pinyin.c 29.51 KB
一键复制 编辑 原始数据 按行查看 历史
iamyhw 提交于 2021-01-13 14:46 . 消除一些GCC编译器下的警告!
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
/*
* Copyright (c) 2020-2021
*
* SPDX-License-Identifier: LGPL-2.0
*
* Change Logs:
* Date Author Notes
* 2021/01/09 iamyhw The first version.
*/
#include <stdio.h>
#include "pinyin.h"
#define DICTS(x, s) {x, sizeof(x)-1, s, sizeof(s)-1}
//将字典/词典按照首字母分类,可加快查找速度
static const ime_dicts_t dicts_a[] = {
DICTS("a", "阿啊"),
DICTS("ai", "哎哀唉埃挨皑癌矮蔼艾爱隘碍"),
DICTS("an", "安氨鞍俺岸按案胺暗"),
DICTS("ang", "肮昂盎"),
DICTS("ao", "凹敖熬翱袄傲奥澳懊"),
RT_NULL,
};
static const ime_dicts_t dicts_b[] = {
DICTS("b", "不部本表把变比并别百报保病北被步边八办布"),
DICTS("ba", "八巴叭扒吧芭疤捌笆拔跋把靶坝爸罢霸"),
DICTS("bai", "白百佰柏摆败拜稗"),
DICTS("ban", "扳班般颁斑搬板版办半伴扮拌绊瓣"),
DICTS("bang", "邦帮梆绑榜膀蚌傍棒谤磅镑"),
DICTS("bao", "包苞胞褒雹宝饱保堡报抱豹鲍暴爆剥薄瀑"),
DICTS("bei", "卑杯悲碑北贝狈备背钡倍被惫焙辈"),
DICTS("ben", "奔本苯笨夯"),
DICTS("beng", "崩绷甭泵迸蹦"),
DICTS("bi", "逼鼻比彼笔鄙币必毕闭庇毖陛毙敝痹蓖弊碧蔽壁避臂"),
DICTS("bian", "边编鞭贬扁卞便变遍辨辩辫"),
DICTS("biao", "彪标膘表"),
DICTS("bie", "憋鳖别瘪"),
DICTS("bin", "宾彬斌滨濒摈"),
DICTS("bing", "冰兵丙秉柄炳饼并病"),
DICTS("bo", "拨波玻钵脖菠播伯驳帛泊勃铂舶博渤搏箔膊卜"),
DICTS("bu", "补哺捕不布步怖部埠簿"),
RT_NULL,
};
static const ime_dicts_t dicts_c[] = {
DICTS("c", "产成出长从此常处车场传采层厂才次虫除查差"),
DICTS("ca", "擦"),
DICTS("cai", "猜才材财裁采彩睬踩菜蔡"),
DICTS("can", "参餐残蚕惭惨灿"),
DICTS("cang", "仓沧苍舱藏"),
DICTS("cao", "操糙曹槽草"),
DICTS("ce", "册侧厕测策"),
DICTS("ceng", "层蹭曾"),
DICTS("cha", "叉插查茬茶搽察碴岔诧差刹"),
DICTS("chai", "拆柴豺"),
DICTS("chan", "掺搀谗馋缠蝉产铲阐颤"),
DICTS("chang", "昌猖肠尝偿常厂场敞畅倡唱"),
DICTS("chao", "抄钞超巢朝嘲潮吵炒绰"),
DICTS("che", "车扯彻掣撤澈"),
DICTS("chen", "郴尘臣忱沉辰陈晨衬趁"),
DICTS("cheng", "称撑成呈承诚城乘惩程澄橙逞骋秤"),
DICTS("chi", "吃痴弛池驰迟持尺侈齿耻斥赤炽翅"),
DICTS("chong", "充冲虫崇宠"),
DICTS("chou", "抽仇绸畴愁稠筹酬踌丑瞅臭"),
DICTS("chu", "出初除厨滁锄雏橱躇础储楚处搐触矗畜"),
DICTS("chuai", "揣"),
DICTS("chuan", "川穿传船椽喘串"),
DICTS("chuang", "闯疮窗床创"),
DICTS("chui", "吹炊垂捶锤"),
DICTS("chun", "春椿纯唇淳醇蠢"),
DICTS("chuo", "戳"),
DICTS("ci", "疵词茨瓷慈辞磁雌此次刺赐"),
DICTS("cong", "囱从匆葱聪丛"),
DICTS("cou", "凑"),
DICTS("cu", "粗促醋簇"),
DICTS("cuan", "蹿窜篡"),
DICTS("cui", "崔催摧脆淬瘁粹翠"),
DICTS("cun", "村存寸"),
DICTS("cuo", "搓磋撮挫措错"),
RT_NULL,
};
static const ime_dicts_t dicts_d[] = {
DICTS("d", "的大地动到对度多电党得定等斗当队都点代道"),
DICTS("dai", "呆歹傣代带待怠殆贷袋逮戴"),
DICTS("dan", "丹单担耽郸胆掸旦但诞弹惮淡蛋氮"),
DICTS("dang", "当挡党荡档"),
DICTS("dao", "刀导岛倒捣祷蹈到悼盗道稻"),
DICTS("de", "得德的"),
DICTS("deng", "灯登蹬等邓凳瞪"),
DICTS("di", "低堤滴狄迪敌涤笛嫡底抵地弟帝递第缔蒂"),
DICTS("dian", "掂滇颠典点碘电佃甸店垫惦淀奠殿靛"),
DICTS("diao", "刁叼凋碉雕吊钓掉"),
DICTS("die", "爹跌迭谍叠碟蝶"),
DICTS("ding", "丁叮盯钉顶鼎订定锭"),
DICTS("diu", "丢"),
DICTS("dong", "东冬董懂动冻侗恫栋洞"),
DICTS("dou", "都兜斗抖陡豆逗痘"),
DICTS("du", "督毒读犊独堵赌睹妒杜肚度渡镀"),
DICTS("duan", "端短段断缎锻"),
DICTS("dui", "堆队对兑"),
DICTS("dun", "吨敦墩蹲盾钝顿遁"),
DICTS("duo", "多哆夺掇朵垛躲剁堕舵惰跺"),
RT_NULL,
};
static const ime_dicts_t dicts_e[] = {
DICTS("e", "讹俄娥峨鹅蛾额厄扼恶饿鄂遏"),
DICTS("en", "恩"),
DICTS("er", "儿而尔耳洱饵二贰"),
RT_NULL,
};
static const ime_dicts_t dicts_f[] = {
DICTS("f", "分发方法反放复风防非服肥副粉府夫负封富翻"),
DICTS("fa", "发乏伐罚阀筏法珐"),
DICTS("fan", "帆番翻藩凡矾钒烦樊繁反返犯泛饭范贩"),
DICTS("fang", "方坊芳防妨房肪仿访纺放"),
DICTS("fei", "飞非啡菲肥匪诽吠废沸肺费"),
DICTS("fen", "分吩纷芬氛酚坟汾焚粉份奋忿愤粪"),
DICTS("feng", "丰风枫封疯峰烽锋蜂冯逢缝讽凤奉"),
DICTS("fo", "佛"),
DICTS("fou", "否"),
DICTS("fu", "夫肤孵敷弗伏扶拂服俘氟浮涪符袱幅福辐抚甫府斧俯釜辅腑腐父讣付妇负附咐阜复赴副傅富赋缚腹覆"),
RT_NULL,
};
static const ime_dicts_t dicts_g[] = {
DICTS("g", "个国工过高干关各革公根更改管光广果格共搞"),
DICTS("ga", "嘎噶"),
DICTS("gai", "该改钙盖溉概"),
DICTS("gan", "干甘杆肝柑竿秆赶敢感赣"),
DICTS("gang", "冈刚岗纲肛缸钢港杠"),
DICTS("gao", "皋羔高膏篙糕搞稿镐告"),
DICTS("ge", "戈疙哥胳鸽割搁歌阁革格葛隔个各铬咯"),
DICTS("gei", "给"),
DICTS("gen", "根跟"),
DICTS("geng", "更庚耕羹埂耿梗"),
DICTS("gong", "工弓公功攻供宫恭躬龚巩汞拱共贡"),
DICTS("gou", "勾沟钩狗苟构购垢够"),
DICTS("gu", "估咕姑孤沽菇辜箍古谷股骨蛊鼓固故顾雇"),
DICTS("gua", "瓜刮剐寡挂褂"),
DICTS("guai", "乖拐怪"),
DICTS("guan", "关观官冠棺馆管贯惯灌罐"),
DICTS("guang", "光广逛"),
DICTS("gui", "归圭龟规闺硅瑰轨诡癸鬼刽柜贵桂跪"),
DICTS("gun", "辊滚棍"),
DICTS("guo", "郭锅国果裹过"),
RT_NULL,
};
static const ime_dicts_t dicts_h[] = {
DICTS("h", "和会后化好合还活很回号毫花或海话红火黄害"),
DICTS("ha", "蛤哈"),
DICTS("hai", "孩骸海亥骇害氦"),
DICTS("han", "酣憨含邯函涵寒韩罕喊汉汗旱悍捍焊憾撼翰"),
DICTS("hang", "杭航行"),
DICTS("hao", "毫豪嚎壕好郝号浩耗"),
DICTS("he", "呵喝禾合何和河阂核荷涸盒菏贺褐赫鹤"),
DICTS("hei", "黑嘿"),
DICTS("hen", "痕很狠恨"),
DICTS("heng", "亨哼恒横衡"),
DICTS("hong", "轰哄烘弘红宏洪虹鸿"),
DICTS("hou", "侯喉猴吼后厚候"),
DICTS("hu", "乎呼忽弧狐胡壶湖葫瑚糊蝴虎唬互户护沪"),
DICTS("hua", "花华哗滑猾化划画话"),
DICTS("huai", "怀徊淮槐坏"),
DICTS("huan", "欢还环桓缓幻宦唤换涣患焕痪豢"),
DICTS("huang", "荒慌皇凰黄惶煌蝗磺簧恍晃谎幌"),
DICTS("hui", "灰恢挥辉徽回蛔悔卉汇会讳绘诲烩贿晦秽惠毁慧"),
DICTS("hun", "昏荤婚浑魂混"),
DICTS("huo", "豁活火伙或货获祸惑霍"),
RT_NULL,
};
static const ime_dicts_t dicts_j[] = {
DICTS("j", "级就进加经家结阶间件及解较机军接教极九见"),
DICTS("ji", "讥击饥圾机肌鸡迹姬积基绩缉畸箕稽激及吉汲级即极急疾棘集嫉辑籍几己挤脊计记伎纪妓忌技际剂季既济继寂寄悸祭蓟冀藉"),
DICTS("jia", "加夹佳枷家嘉荚颊甲贾钾价驾架假嫁稼挟"),
DICTS("jian", "奸尖坚歼间肩艰兼监笺缄煎拣俭柬茧捡减剪检硷简碱见件建饯剑荐贱健涧舰渐溅践鉴键箭"),
DICTS("jiang", "江姜将浆僵疆讲奖桨蒋匠降酱"),
DICTS("jiao", "交郊娇浇骄胶椒焦蕉礁角狡绞饺矫脚铰搅剿缴叫轿较教窖酵觉嚼"),
DICTS("jie", "阶皆接秸揭街节劫杰洁结捷睫截竭姐解介戒芥届界疥诫借"),
DICTS("jin", "巾今斤金津筋襟仅紧谨锦尽劲近进晋浸烬禁靳"),
DICTS("jing", "京经茎荆惊晶睛粳兢精鲸井颈景警净径痉竞竟敬靖境静镜"),
DICTS("jiong", "炯窘"),
DICTS("jiu", "纠究揪九久灸玖韭酒旧臼咎疚厩救就舅"),
DICTS("ju", "居拘狙驹疽鞠局桔菊咀沮举矩句巨拒具炬俱剧惧据距锯聚踞"),
DICTS("juan", "娟捐鹃卷倦绢眷"),
DICTS("jue", "撅决诀抉绝倔掘爵攫"),
DICTS("jun", "军君均钧菌俊郡峻浚骏竣"),
RT_NULL,
};
static const ime_dicts_t dicts_k[] = {
DICTS("k", "可开看克孔科口空苦快考刻靠况块困宽矿抗卡"),
DICTS("ka", "咖喀卡"),
DICTS("kai", "开揩凯慨楷"),
DICTS("kan", "槛刊勘堪坎砍看"),
DICTS("kang", "康慷糠扛亢抗炕"),
DICTS("kao", "考拷烤靠"),
DICTS("ke", "坷苛柯科棵颗磕壳咳可渴克刻客课"),
DICTS("ken", "肯垦恳啃"),
DICTS("keng", "吭坑"),
DICTS("kong", "空孔恐控"),
DICTS("kou", "抠口扣寇"),
DICTS("ku", "枯哭窟苦库裤酷"),
DICTS("kua", "夸垮挎胯跨"),
DICTS("kuai", "块快侩筷"),
DICTS("kuan", "宽款"),
DICTS("kuang", "匡筐狂况旷矿框眶"),
DICTS("kui", "亏岿盔窥奎葵魁傀愧溃馈"),
DICTS("kun", "坤昆捆困"),
DICTS("kuo", "扩括阔廓"),
RT_NULL,
};
static const ime_dicts_t dicts_l[] = {
DICTS("l", "了来量理路里论两利领流力立料连老六轮类列"),
DICTS("la", "垃拉啦喇腊蜡辣"),
DICTS("lai", "来莱赖"),
DICTS("lan", "兰拦栏婪阑蓝谰澜篮览揽缆懒烂滥"),
DICTS("lang", "郎狼廊琅榔朗浪"),
DICTS("lao", "捞劳牢老佬姥涝烙酪"),
DICTS("le", "乐勒了"),
DICTS("lei", "雷镭垒磊蕾儡肋泪类累擂"),
DICTS("leng", "棱楞冷"),
DICTS("li", "厘梨狸离莉犁漓璃黎篱礼李里哩理鲤力历厉立吏丽利励沥例隶俐荔栗砾粒傈痢"),
DICTS("lian", "连帘怜涟莲联廉镰敛脸练炼恋链"),
DICTS("liang", "俩良凉梁粮粱两亮谅辆晾量"),
DICTS("liao", "潦辽疗聊僚寥廖撩燎镣料撂"),
DICTS("lie", "列劣烈猎裂"),
DICTS("lin", "邻林临淋琳霖磷鳞凛吝赁拎"),
DICTS("ling", "伶灵岭玲凌铃陵羚菱零龄领令另"),
DICTS("liu", "溜刘流留琉硫馏榴瘤柳六"),
DICTS("long", "龙咙笼聋隆窿陇垄拢"),
DICTS("lou", "娄楼搂篓陋漏"),
DICTS("lu", "露卢庐芦炉颅卤虏掳鲁陆录赂鹿禄碌路戮潞麓"),
DICTS("luan", "孪峦挛滦卵乱"),
DICTS("lue", "掠略"),
DICTS("lun", "抡仑伦沦纶轮论"),
DICTS("luo", "罗萝逻锣箩骡螺裸洛络骆落"),
DICTS("lv", "滤驴吕侣旅铝屡缕履律虑率绿氯"),
RT_NULL,
};
static const ime_dicts_t dicts_m[] = {
DICTS("m", "面命们民毛没米明马么每门名磨美密苗满亩目呒"),
DICTS("ma", "妈麻马玛码蚂骂吗嘛"),
DICTS("mai", "埋买迈麦卖脉"),
DICTS("man", "蛮馒瞒满曼谩慢漫蔓"),
DICTS("mang", "忙芒盲茫莽氓"),
DICTS("mao", "猫毛矛茅锚卯铆茂冒贸帽貌"),
DICTS("me", "么"),
DICTS("mei", "没枚玫眉梅媒煤酶霉每美镁妹昧媚寐"),
DICTS("men", "门闷们"),
DICTS("meng", "萌盟檬猛蒙锰孟梦"),
DICTS("mi", "弥迷谜醚糜靡米眯泌觅秘密幂蜜"),
DICTS("mian", "眠绵棉免勉娩冕缅面"),
DICTS("miao", "苗描瞄秒渺藐妙庙"),
DICTS("mie", "灭蔑"),
DICTS("min", "民皿抿闽悯敏"),
DICTS("ming", "名明鸣铭螟命"),
DICTS("miu", "谬"),
DICTS("mo", "貉摸摹模膜摩磨蘑魔抹末沫陌莫寞漠墨默"),
DICTS("mou", "牟谋某"),
DICTS("mu", "母亩牡姆拇木目牧募墓幕睦慕暮穆"),
RT_NULL,
};
static const ime_dicts_t dicts_n[] = {
DICTS("n", "年能内那农你南难呢女泥哪拿念牛宁脑粘尼纳嗯"),
DICTS("na", "拿哪那纳娜钠呐"),
DICTS("nai", "乃奶氖奈耐"),
DICTS("nan", "男南难"),
DICTS("nang", "囊"),
DICTS("nao", "挠恼脑闹淖"),
DICTS("ne", "呢"),
DICTS("nei", "内馁"),
DICTS("nen", "嫩"),
DICTS("neng", "能"),
DICTS("ni", "妮尼泥倪霓你拟逆匿溺腻"),
DICTS("nian", "拈年捻撵碾念蔫"),
DICTS("niang", "娘酿"),
DICTS("niao", "鸟尿"),
DICTS("nie", "捏涅聂啮镊镍孽"),
DICTS("nin", "您"),
DICTS("ning", "宁拧狞柠凝泞"),
DICTS("niu", "牛扭纽钮"),
DICTS("nong", "农浓脓弄"),
DICTS("nu", "奴努怒"),
DICTS("nuan", "暖"),
DICTS("nue", "疟虐"),
DICTS("nuo", "挪诺懦糯"),
DICTS("nv", "女"),
RT_NULL,
};
static const ime_dicts_t dicts_o[] = {
DICTS("o", "哦"),
DICTS("ou", "欧殴鸥呕偶藕沤"),
RT_NULL,
};
static const ime_dicts_t dicts_p[] = {
DICTS("p", "批平判配片派破排品皮喷盘偏评怕培普贫跑炮"),
DICTS("pa", "趴啪爬耙琶帕怕"),
DICTS("pai", "拍徘排牌派湃"),
DICTS("pan", "潘攀盘磐判叛盼畔"),
DICTS("pang", "乓庞旁耪胖"),
DICTS("pao", "抛刨咆炮袍跑泡"),
DICTS("pei", "呸胚陪培赔裴沛佩配"),
DICTS("pen", "喷盆"),
DICTS("peng", "抨砰烹朋彭棚硼蓬鹏澎篷膨捧碰"),
DICTS("pi", "辟批坯披砒劈霹皮毗疲啤琵脾匹痞屁僻譬"),
DICTS("pian", "片偏篇骗"),
DICTS("piao", "漂飘瓢票"),
DICTS("pie", "撇瞥"),
DICTS("pin", "拼贫频品聘"),
DICTS("ping", "乒平评凭坪苹屏瓶萍"),
DICTS("po", "坡泼颇婆迫破粕魄"),
DICTS("pou", "剖"),
DICTS("pu", "脯仆扑铺莆菩葡蒲朴圃埔浦普谱曝"),
RT_NULL,
};
static const ime_dicts_t dicts_q[] = {
DICTS("q", "起前其去气全期群情区强切取七求清确权且青"),
DICTS("qi", "七沏妻柒凄栖戚期欺漆祁齐其奇歧祈脐崎畦骑棋旗乞企岂启起气讫迄弃汽泣契砌器"),
DICTS("qia", "掐恰洽"),
DICTS("qian", "千仟扦迁钎牵铅谦签前钱钳乾潜黔浅遣谴欠堑嵌歉"),
DICTS("qiang", "呛羌枪腔强墙蔷抢"),
DICTS("qiao", "悄敲锹橇乔侨桥瞧巧俏峭窍翘撬鞘"),
DICTS("qie", "切茄且怯窃"),
DICTS("qin", "亲侵钦芹秦琴禽勤擒寝沁"),
DICTS("qing", "青氢轻倾卿清情晴氰擎顷请庆"),
DICTS("qiong", "穷琼"),
DICTS("qiu", "丘邱秋囚求泅酋球"),
DICTS("qu", "区曲驱屈蛆躯趋渠取娶龋去趣"),
DICTS("quan", "圈全权泉拳痊醛颧犬劝券"),
DICTS("que", "炔缺瘸却雀确鹊榷"),
DICTS("qun", "裙群"),
RT_NULL,
};
static const ime_dicts_t dicts_r[] = {
DICTS("r", "人如日认入任热然容让润弱燃染壤绕仁溶刃仍"),
DICTS("ran", "然燃冉染"),
DICTS("rang", "瓤嚷壤攘让"),
DICTS("rao", "饶扰绕"),
DICTS("re", "惹热"),
DICTS("ren", "人仁壬忍刃认任纫妊韧"),
DICTS("reng", "扔仍"),
DICTS("ri", "日"),
DICTS("rong", "戎绒茸荣容溶蓉熔融冗"),
DICTS("rou", "柔揉肉"),
DICTS("ru", "如茹儒孺蠕汝乳辱入褥"),
DICTS("ruan", "阮软"),
DICTS("rui", "蕊锐瑞"),
DICTS("run", "闰润"),
DICTS("ruo", "若弱"),
RT_NULL,
};
static const ime_dicts_t dicts_s[] = {
DICTS("s", "是上时生说社深水所三十使事数四实少式山手"),
DICTS("sa", "撒洒萨"),
DICTS("sai", "塞腮鳃赛"),
DICTS("san", "三叁伞散"),
DICTS("sang", "桑嗓丧"),
DICTS("sao", "搔骚扫嫂"),
DICTS("se", "色涩瑟"),
DICTS("sen", "森"),
DICTS("seng", "僧"),
DICTS("sha", "杀沙纱砂莎傻啥煞厦"),
DICTS("shai", "筛晒"),
DICTS("shan", "山删杉衫珊煽闪陕汕苫扇善缮擅膳赡栅"),
DICTS("shang", "伤商墒裳晌赏上尚"),
DICTS("shao", "捎梢烧稍勺芍韶少邵绍哨"),
DICTS("she", "奢赊舌蛇舍设社射涉赦慑摄"),
DICTS("shen", "申伸身呻绅娠砷深神沈审婶肾甚渗慎什"),
DICTS("sheng", "升生声牲胜甥绳省圣盛剩"),
DICTS("shi", "是十石士氏市示式史矢匙尸失师虱诗施狮湿时识实拾蚀食使始驶屎世仕事侍势视试饰室恃拭柿适逝释嗜誓噬似"),
DICTS("shou", "收手守首寿受兽售授瘦"),
DICTS("shu", "书抒叔枢殊梳淑疏舒输蔬孰赎熟暑黍署鼠蜀薯曙术戍束述树竖恕庶数墅漱属"),
DICTS("shua", "刷耍"),
DICTS("shuai", "衰摔甩帅"),
DICTS("shuan", "拴栓"),
DICTS("shuang", "双霜爽"),
DICTS("shui", "谁水税睡"),
DICTS("shun", "吮顺舜瞬"),
DICTS("shuo", "说烁朔硕"),
DICTS("si", "丝司私思斯嘶撕死巳四寺伺饲嗣肆"),
DICTS("song", "松怂耸讼宋诵送颂"),
DICTS("sou", "嗽搜艘擞"),
DICTS("su", "苏酥俗诉肃素速粟塑溯僳"),
DICTS("suan", "酸蒜算"),
DICTS("sui", "虽绥隋随髓岁祟遂碎隧穗"),
DICTS("sun", "孙损笋"),
DICTS("suo", "唆梭蓑缩所索琐锁"),
RT_NULL,
};
static const ime_dicts_t dicts_t[] = {
DICTS("t", "他同它提题体图天头通条特土团统台她太套铁"),
DICTS("ta", "她他它塌塔獭挞踏蹋"),
DICTS("tai", "胎台抬苔太汰态泰酞"),
DICTS("tan", "坍贪摊滩瘫坛谈痰谭潭檀坦袒毯叹炭探碳"),
DICTS("tang", "汤唐堂棠塘搪膛糖倘淌躺烫趟"),
DICTS("tao", "涛绦掏滔逃桃陶淘萄讨套"),
DICTS("te", "特"),
DICTS("teng", "疼腾誊藤"),
DICTS("ti", "剔梯锑踢啼提题蹄体屉剃涕惕替嚏"),
DICTS("tian", "天添田恬甜填腆舔"),
DICTS("tiao", "调挑条迢眺跳"),
DICTS("tie", "贴铁帖"),
DICTS("ting", "厅汀听烃廷亭庭停挺艇"),
DICTS("tong", "通同彤桐铜童酮瞳统捅桶筒痛"),
DICTS("tou", "偷头投透"),
DICTS("tu", "凸秃突图徒涂途屠土吐兔"),
DICTS("tuan", "湍团"),
DICTS("tui", "推颓腿退蜕褪"),
DICTS("tun", "囤吞屯臀"),
DICTS("tuo", "托拖脱驮陀驼鸵妥椭拓唾"),
RT_NULL,
};
static const ime_dicts_t dicts_w[] = {
DICTS("w", "为我无问外五位物委完温万文往武务王围误晚"),
DICTS("wa", "哇娃挖洼蛙瓦袜"),
DICTS("wai", "歪外"),
DICTS("wan", "弯湾豌丸完玩顽烷宛挽晚婉惋皖碗万腕"),
DICTS("wang", "汪亡王网往枉妄忘旺望"),
DICTS("wei", "危威微巍为韦围违桅唯惟维潍伟伪尾纬苇委萎卫未位味畏胃尉谓喂渭蔚慰魏"),
DICTS("wen", "温瘟文纹闻蚊吻紊稳问"),
DICTS("weng", "翁嗡瓮"),
DICTS("wo", "挝涡窝蜗我沃卧握斡"),
DICTS("wu", "乌污呜巫屋诬钨无毋吴吾芜梧五午伍坞武侮捂舞勿务戊物误悟晤雾"),
RT_NULL,
};
static const ime_dicts_t dicts_x[] = {
DICTS("x", "学下行小线性新些想心向相系席现西修象先形"),
DICTS("xi", "夕汐西吸希昔析矽息牺悉惜烯硒晰犀稀溪锡熄熙嘻膝习席袭媳檄洗喜戏系细隙"),
DICTS("xia", "虾瞎匣侠峡狭暇辖霞下吓夏"),
DICTS("xian", "铣仙先纤掀锨鲜闲弦贤咸涎舷衔嫌显险县现线限宪陷馅羡献腺"),
DICTS("xiang", "乡相香厢湘箱襄镶详祥翔享响想向巷项象像橡"),
DICTS("xiao", "宵消萧硝销霄嚣淆小晓孝肖哮效校笑啸"),
DICTS("xie", "些楔歇蝎协邪胁斜谐携鞋写泄泻卸屑械谢懈蟹"),
DICTS("xin", "心忻芯辛欣锌新薪信衅"),
DICTS("xing", "兴星惺猩腥刑邢形型醒杏姓幸性"),
DICTS("xiong", "凶兄匈汹胸雄熊"),
DICTS("xiu", "宿休修羞朽秀绣袖锈嗅"),
DICTS("xu", "戌须虚嘘需墟徐许旭序叙恤绪续酗婿絮蓄吁"),
DICTS("xuan", "轩宣喧玄悬旋选癣绚眩"),
DICTS("xue", "削靴薛穴学雪血"),
DICTS("xun", "勋熏寻巡旬驯询循训讯汛迅逊殉"),
RT_NULL,
};
static const ime_dicts_t dicts_y[] = {
DICTS("y", "一有用要以于也样义与由压员月意又运原油验"),
DICTS("ya", "丫压呀押鸦鸭牙芽蚜崖涯衙哑雅亚讶"),
DICTS("yan", "咽烟淹焉阉延严言岩沿炎研盐阎蜒颜奄衍掩眼演厌彦砚唁宴艳验谚堰焰雁燕"),
DICTS("yang", "央殃秧鸯扬羊阳杨佯疡洋仰养氧痒样漾"),
DICTS("yao", "侥妖腰邀尧姚窑谣摇遥瑶咬舀药要耀钥"),
DICTS("ye", "椰噎爷耶也冶野业叶曳页夜掖液腋"),
DICTS("yi", "一伊衣医依铱壹揖仪夷沂宜姨胰移遗颐疑彝乙已以矣蚁倚椅义亿忆艺议亦屹异役抑译邑易绎诣疫益谊翌逸意溢肄裔毅翼臆"),
DICTS("yin", "因阴姻茵荫音殷吟寅淫银尹引饮隐印"),
DICTS("ying", "应英婴缨樱鹰迎盈荧莹萤营蝇赢颖影映硬"),
DICTS("yo", "哟"),
DICTS("yong", "佣拥痈庸雍臃永咏泳勇涌恿蛹踊用"),
DICTS("you", "优忧幽悠尤由犹邮油铀游友有酉又右幼佑诱釉"),
DICTS("yu", "迂淤渝于予余盂鱼俞娱渔隅愉逾愚榆虞舆与宇屿羽雨禹语玉驭芋育郁狱峪浴预域欲喻寓御裕遇愈誉豫"),
DICTS("yuan", "冤鸳渊元员园垣原圆袁援缘源猿辕远苑怨院愿"),
DICTS("yue", "曰约月岳悦阅跃粤越"),
DICTS("yun", "云匀郧耘允陨孕运晕酝韵蕴"),
RT_NULL,
};
static const ime_dicts_t dicts_z[] = {
DICTS("z", "在这主中种着争战作正之制重组治只子自质指"),
DICTS("za", "匝杂砸咋"),
DICTS("zai", "灾哉栽宰载再在仔"),
DICTS("zan", "咱攒暂赞"),
DICTS("zang", "赃脏葬"),
DICTS("zao", "遭糟凿早枣蚤澡藻灶皂造噪燥躁"),
DICTS("ze", "则择泽责"),
DICTS("zei", "贼"),
DICTS("zen", "怎"),
DICTS("zeng", "增憎赠"),
DICTS("zha", "喳渣扎札轧闸铡眨乍诈炸榨柞"),
DICTS("zhai", "斋摘宅翟窄债寨"),
DICTS("zhan", "沾毡粘詹瞻斩展盏崭辗占战栈站绽湛蘸"),
DICTS("zhang", "长张章彰漳樟涨掌丈仗帐杖胀账障瘴"),
DICTS("zhao", "招昭找沼召兆赵照罩肇爪"),
DICTS("zhe", "遮折哲蛰辙者锗这浙蔗着"),
DICTS("zhen", "贞针侦珍真砧斟甄臻诊枕疹阵振镇震帧"),
DICTS("zheng", "争征怔挣狰睁蒸拯整正证郑政症"),
DICTS("zhi", "之支汁芝吱枝知织肢脂蜘执侄直值职植殖止只旨址纸指趾至志制帜治炙质峙挚秩致掷痔窒智滞稚置"),
DICTS("zhong", "中忠终盅钟衷肿种仲众重"),
DICTS("zhou", "州舟诌周洲粥轴肘帚咒宙昼皱骤"),
DICTS("zhu", "朱诛株珠诸猪蛛竹烛逐主拄煮嘱瞩住助注贮驻柱祝著蛀筑铸"),
DICTS("zhua", "抓"),
DICTS("zhuai", "拽"),
DICTS("zhuan", "专砖转撰篆"),
DICTS("zhuang", "妆庄桩装壮状幢撞"),
DICTS("zhui", "追椎锥坠缀赘"),
DICTS("zhun", "谆准"),
DICTS("zhuo", "卓拙捉桌灼茁浊酌啄琢"),
DICTS("zi", "孜兹咨姿资淄滋籽子紫滓字自渍"),
DICTS("zong", "宗综棕踪鬃总纵"),
DICTS("zou", "邹走奏揍"),
DICTS("zu", "租足卒族诅阻组祖"),
DICTS("zuan", "赚纂钻"),
DICTS("zui", "嘴最罪醉"),
DICTS("zun", "尊遵"),
DICTS("zuo", "昨左佐作坐座做"),
RT_NULL,
};
static const ime_dicts_t *dict_list[26] =
{
dicts_a, dicts_b, dicts_c, dicts_d, dicts_e, dicts_f, dicts_g,
dicts_h, RT_NULL, dicts_j, dicts_k, dicts_l, dicts_m, dicts_n,
dicts_o, dicts_p, dicts_q, dicts_r, dicts_s, dicts_t,
RT_NULL, RT_NULL, dicts_w, dicts_x, dicts_y, dicts_z
};
static const char *dicts_second[26] =
{
"ino","aeiou","aehiou","aeiou","inr","aeou","aeou","aeou",NULL,"iu","aeou","aeiouv","aeiou",
"aeiouv","u","aeiou","iu","aeiou","aehiou","aeiou",NULL,NULL,"aeou","iu","aeiou","aehiou"
};
#define TERMS(x, n, s) { x, sizeof(x)-1, n, s, (sizeof(s)+1)/(n*2+1) }
//请自己添加热词!
static const ime_terms_t terms_a[] =
{
TERMS("ay", 2, "哎呀,阿姨,熬夜,哎呦,安逸,按月,啊呀"),
RT_NULL,
};
static const ime_terms_t terms_b[] =
{
TERMS("bm", 2, "宝马"),
RT_NULL,
};
static const ime_terms_t terms_c[] =
{
TERMS("ces", 2, "测试,厕所,测算,测速,策士"),
TERMS("ceshi", 2, "测试,策士,侧室"),
TERMS("cf", 2, "处方"),
TERMS("chuf", 2, "处方,除法,处罚,出发,触发,除非,厨房,处分"),
TERMS("chufa", 2, "处方,触发,出发,处罚,除法"),
TERMS("chufan", 2, "处方,触犯,初犯,出饭"),
TERMS("cfy", 3, "处方药"),
TERMS("chufy", 3, "处方药"),
TERMS("chufangy", 3, "处方药"),
TERMS("chufang", 2, "处方,厨房,出访,初防"),
TERMS("ck", 2, "参考"),
RT_NULL,
};
static const ime_terms_t terms_d[] =
{
TERMS("dc", 2, "动车"),
RT_NULL,
};
static const ime_terms_t terms_e[] =
{
TERMS("ey", 2, "鳄鱼"),
RT_NULL,
};
static const ime_terms_t terms_f[] =
{
TERMS("fg", 2, "发光"),
RT_NULL,
};
static const ime_terms_t terms_g[] =
{
TERMS("gx", 2, "高兴,搞笑,高效,高新"),
RT_NULL,
};
static const ime_terms_t terms_h[] =
{
TERMS("hs", 2, "红色,洪水"),
RT_NULL,
};
static const ime_terms_t terms_j[] =
{
TERMS("jd", 2, "鸡蛋,简单"),
RT_NULL,
};
static const ime_terms_t terms_k[] =
{
TERMS("kl", 2, "快乐,考虑"),
RT_NULL,
};
static const ime_terms_t terms_l[] =
{
TERMS("ll", 2, "理论,力量,聊聊"),
RT_NULL,
};
static const ime_terms_t terms_m[] =
{
TERMS("mb", 2, "明白,目标,面包"),
RT_NULL,
};
static const ime_terms_t terms_n[] =
{
TERMS("nn", 2, "你呢,男女"),
RT_NULL,
};
static const ime_terms_t terms_o[] =
{
TERMS("oo", 2, "哦哦,噢噢"),
RT_NULL,
};
static const ime_terms_t terms_p[] =
{
TERMS("pp", 2, "匹配,婆婆"),
RT_NULL,
};
static const ime_terms_t terms_q[] =
{
TERMS("qq", 2, "请求,前期"),
RT_NULL,
};
static const ime_terms_t terms_r[] =
{
TERMS("rm", 2, "人民,人们"),
RT_NULL,
};
static const ime_terms_t terms_s[] =
{
TERMS("ss", 2, "试试,事实"),
RT_NULL,
};
static const ime_terms_t terms_t[] =
{
TERMS("td", 2, "通道,态度"),
RT_NULL,
};
static const ime_terms_t terms_w[] =
{
TERMS("wm", 2, "我们,外面"),
RT_NULL,
};
static const ime_terms_t terms_x[] =
{
TERMS("xw", 2, "希望,行为"),
TERMS("xz", 2, "现在,下载"),
RT_NULL,
};
static const ime_terms_t terms_y[] =
{
TERMS("yx", 2, "一下,游戏"),
RT_NULL,
};
static const ime_terms_t terms_z[] =
{
TERMS("zhrm", 4, "中华人民,走火入魔"),
TERMS("zhrmghg", 7, "中华人民共和国,"),
TERMS("zhrmghggg", 9, "中华人民共和国国歌,"),
TERMS("zd", 2, "字典,中断,找到,针对,自动"),
TERMS("zx", 2, "执行,主席,这些,总线,现在,中心,最新,咨询,仔细,自行,只需,在线,装修,中学"),
RT_NULL,
};
static const ime_terms_t *dict_terms[26] =
{
terms_a, terms_b, terms_c, terms_d, terms_e, terms_f, terms_g,
terms_h, RT_NULL, terms_j, terms_k, terms_l, terms_m, terms_n,
terms_o, terms_p, terms_q, terms_r, terms_s, terms_t,
RT_NULL, RT_NULL, terms_w, terms_x, terms_y, terms_z
};
rt_inline int isLower(char c) { return (c >= 'a' && c <= 'z'); }
rt_inline int isUpper(char c) { return (c >= 'A' && c <= 'Z'); }
rt_inline int isLetter(char c) { return (isLower(c) || isUpper(c)); }
rt_inline int isNumber(char c) { return (c >= '0'&&c <= '9'); }
rt_inline char toLower(char c) { return (isUpper(c) ? (c + 32) : c); }
rt_inline char toUpper(char c) { return (isLower(c) ? (c - 32) : c); }
static const ime_dicts_t* pinyin_get_dict(char c)
{
const ime_dicts_t *pin = RT_NULL;
if (isLower(c)) pin = dict_list[c - 'a'];
else if (isUpper(c)) pin = dict_list[c - 'A'];
return pin;
}
static const ime_terms_t* pinyin_get_terms(char *ptr)
{
const ime_terms_t *tem = RT_NULL;
if (isLower(*ptr)) tem = dict_terms[*ptr - 'a'];
else if (isUpper(*ptr)) tem = dict_terms[*ptr - 'A'];
if (tem == RT_NULL) return RT_NULL;
int len = rt_strlen(ptr);
while (tem->pin && tem->ci)
{
if (tem->pil == len)
{
if (rt_strcmp(tem->pin, ptr) == 0) return tem;
}
tem++;
}
return RT_NULL;
}
//统计以','分隔的词语的条数
static rt_uint16_t terms_len(char *ci)
{
rt_uint16_t len = 0;
char *sc = ci;
while (*sc) {
if (*sc == ',') len++;
sc++;
}
if (*(sc - 1) != ',') len++;
return len;
}
//去除字符串中指定的字符
static void string_remove_space(char *str, char c)
{
char *s = str;
int i, j = 0;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] != c) s[j++] = str[i];
}
s[j] = '\0';
str = s;
}
static const char* builtin_strchr(const char *str, char c)
{
while(*str && *str != c) str++;
return (*str==c)?str:NULL;
}
static void pinyin_update_zhbuf(ime_pinyin_t *ime)
{
const ime_dicts_t *py = ime->dicts;
const ime_terms_t *tem;
rt_uint16_t len = 0;
int match_count;
ime->zhlen = 0;
if (!py) return;
if (ime->inlen >= 2)
{ //剔除无效拼音,只判断前两个字母,再多就与全检索一遍的效率差不多了
if (!builtin_strchr(dicts_second[ime->inbuf[0] - 'a'], ime->inbuf[1]))
goto findterms;
}
while (py->pin && py->hz)
{
if (py->pil == ime->inlen)
{
if (rt_strcmp(py->pin, ime->inbuf) == 0)
{
ime->zhptr = py->hz;
ime->zhlen = py->len / 2;
ime->wordcnt = 1;
ime->page_numbs = (ime->zhlen + (IME_WPP - 1)) / IME_WPP;
ime->page_index = 0;
ime->type = IME_TYPE_DICTS;
return;
}
}
py++;
}
findterms:
tem = ime->terms;
if (tem == RT_NULL) goto carefully_search;
if (ime->zhlen == 0) //在"字典"中未找到,再查找"词典"
{
if (tem->pil == ime->inlen)
{
if (rt_strcmp(tem->pin, ime->inbuf) == 0)
{
ime->zhptr = tem->ci;
ime->zhlen = tem->len;
ime->wordcnt = tem->cnt;
ime->cnt_per_page = 12 / ime->wordcnt;
ime->page_numbs = (ime->zhlen + (ime->cnt_per_page - 1)) / ime->cnt_per_page;
ime->type = IME_TYPE_TERMS;
return;
}
}
}
carefully_search:
//至此也没有找到完全匹配的词汇,那么尝试搜索键入的pinyin中是否有完整拼音,如果有,使用字库
//例如输入的是cesh,没输入完,这时没有完全匹配的cesh字库,也没有对应的cesh词库,误认为找不到结果,
//此时显示ce的字库比较合理,搜索的效率会很低,即一一尝试匹配完整拼音!
match_count = ime->inlen - 1;//从"次最长"匹配!
py = ime->dicts;
while (match_count >= 1)
{
char tmp[20];
rt_memcpy(tmp, ime->inbuf, match_count), tmp[match_count] = '\0';
while (py->pin && py->hz)
{
if (rt_strcmp(py->pin, tmp) == 0)
{
ime->zhptr = py->hz;
ime->zhlen = py->len / 2;
ime->wordcnt = 1;
ime->page_numbs = (ime->zhlen + (IME_WPP - 1)) / IME_WPP;
ime->page_index = 0;
ime->type = IME_TYPE_DICTS;
return;
}
py++;
}
py = ime->dicts;
match_count--;
}
}
void pinyin_generate_page(ime_pinyin_t *ime)
{
char S[32];//词语字数限定在9个,留点裕量
int i;
ime->wordstr[0] = '\0';//只用作字符串
if (ime->zhlen == 0) return;
if (ime->type == IME_TYPE_DICTS) //字典
{
rt_uint16_t *p = (rt_uint16_t*)ime->zhptr;
if (((ime->page_index + 1) * IME_WPP) < ime->zhlen)
ime->cnt_cur_page = IME_WPP;
else
ime->cnt_cur_page = ime->zhlen - ime->page_index * IME_WPP;
if (ime->cnt_cur_page == 0) return;
p += ime->page_index * IME_WPP;
for (i = 0; i < ime->cnt_cur_page; i++)
{
rt_memcpy(S, p + i, 2), S[2] = '\0';
sprintf(ime->wordstr, "%s%d.%s ", ime->wordstr, i+1, S);
}
}
else //if(ime->type==IME_TYPE_TERMS) 词典
{
char *p = ime->zhptr;
if (((ime->page_index + 1) * ime->cnt_per_page) < ime->zhlen)
ime->cnt_cur_page = ime->cnt_per_page;
else
ime->cnt_cur_page = ime->zhlen - ime->page_index * ime->cnt_per_page;
if (ime->cnt_cur_page == 0) return;
p += ime->page_index * (ime->cnt_per_page * (ime->wordcnt*2+1));
for (i = 0; i < ime->cnt_cur_page; i++)
{
rt_memcpy(S, p+(ime->wordcnt*2+1)*i, ime->wordcnt * 2);
S[ime->wordcnt * 2] = '\0';
sprintf(ime->wordstr, "%s%d.%s ", ime->wordstr, i+1, S);
}
}
}
void pinyin_getout_zhstring(ime_pinyin_t *ime, char *zhstr, int index)
{
if (ime->type == IME_TYPE_DICTS) //字典
{
rt_uint16_t *p = (rt_uint16_t*)ime->zhptr;
p += ime->page_index * IME_WPP;
rt_memcpy(zhstr, p + index, 2);
zhstr[2] = '\0';
}
else //if(ime->type==IME_TYPE_TERMS) 词典
{
char *p = ime->zhptr;
p += ime->page_index * (ime->cnt_per_page * (ime->wordcnt * 2 + 1));
rt_memcpy(zhstr, p + (ime->wordcnt * 2 + 1)*index, ime->wordcnt * 2);
zhstr[ime->wordcnt * 2] = '\0';
}
}
void pinyin_getin_letter(ime_pinyin_t *ime, char c)
{
if(ime->inlen >= 9) return; //最大允许键入9个
ime->inbuf[ime->inlen++] = toLower(c);
if (ime->inlen == 1) //search dict list
{
ime->dicts = pinyin_get_dict(c);
}
ime->terms = pinyin_get_terms(ime->inbuf);
pinyin_update_zhbuf(ime);
pinyin_generate_page(ime);
}
void pinyin_backspace(ime_pinyin_t *ime)
{
if (ime->inlen > 0)
{
ime->inlen--;
ime->inbuf[ime->inlen] = 0;
if (ime->inlen == 0) {
ime->dicts = RT_NULL;
ime->terms = RT_NULL;
} else {
ime->terms = pinyin_get_terms(ime->inbuf);
}
pinyin_update_zhbuf(ime);
ime->page_numbs = (ime->zhlen + 8) / 9;
pinyin_generate_page(ime);
}
}
void pinyin_page_add(ime_pinyin_t *ime)
{
if (ime->page_numbs > 1)
{
if (ime->page_index > 0)
ime->page_index -= 1;
pinyin_generate_page(ime);
}
}
void pinyin_page_sub(ime_pinyin_t *ime)
{
if (ime->page_numbs > 1)
{
if ((ime->page_index + 1) < ime->page_numbs)
ime->page_index += 1;
pinyin_generate_page(ime);
}
}
void pinyin_init(ime_pinyin_t *ime)
{
rt_memset(ime, 0, sizeof(ime_pinyin_t));
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/guitarhua/pinyin.git
git@gitee.com:guitarhua/pinyin.git
guitarhua
pinyin
pinyin
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385