1
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "9"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {NSMutableString,CFStringTransform,kCFStringTransformToLatin,kCFStringTransformStripDiacritics, StringTransform} from "Foundation"
|
||||
import { XuiChineseToPinYinOpts, XuiChineseToPinYinResult } from "../interface.uts"
|
||||
import { XuiChineseToPinYinFailImpl } from "../unierror.uts"
|
||||
|
||||
/** 中文转拼音 */
|
||||
export function toPinYin(opts : XuiChineseToPinYinOpts){
|
||||
try {
|
||||
let c = opts.char;
|
||||
if (c == '') {
|
||||
let errorIml = new XuiChineseToPinYinFailImpl(1002)
|
||||
opts.fail?.(errorIml)
|
||||
opts.complete?.(null)
|
||||
return;
|
||||
}
|
||||
|
||||
let tostrings = new NSMutableString(string = opts.char)
|
||||
let tostrings2 = new NSMutableString(string = opts.char)
|
||||
CFStringTransform(tostrings,null,kCFStringTransformToLatin,false)
|
||||
|
||||
CFStringTransform(tostrings2,null,kCFStringTransformToLatin,false)
|
||||
CFStringTransform(tostrings2,null,kCFStringTransformStripDiacritics,false)
|
||||
const ok : XuiChineseToPinYinResult = {
|
||||
detail: tostrings2 as string,
|
||||
zhuyin: tostrings as string
|
||||
}
|
||||
opts.success?.(ok)
|
||||
opts.complete?.(ok)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
opts.fail?.(new XuiChineseToPinYinFailImpl(1001))
|
||||
opts.complete?.(null)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user