提交 26017a3c 编写于 作者: B baiy 提交者: ninecents

json 工具中 `unicode转中文` 功能 支持 `\Uxxxx` #62

上级 dfccb6e4
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.6.8", "version": "1.6.9",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --port 8081", "serve": "vue-cli-service serve --port 8081",
......
...@@ -55,7 +55,7 @@ const handleNoticeItems = ({code, data, info}) => { ...@@ -55,7 +55,7 @@ const handleNoticeItems = ({code, data, info}) => {
} }
const logError = (e) => { const logError = (e) => {
// console.log(e) console.log(e)
} }
export default { export default {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
import 'codemirror/addon/fold/brace-fold.js' import 'codemirror/addon/fold/brace-fold.js'
import 'codemirror/addon/fold/comment-fold.js' import 'codemirror/addon/fold/comment-fold.js'
import 'codemirror/addon/fold/foldgutter.css' import 'codemirror/addon/fold/foldgutter.css'
import Unicode from "./library/unicode"
export default { export default {
components: { components: {
...@@ -110,29 +111,12 @@ ...@@ -110,29 +111,12 @@
} }
}, },
unicode2zh () { unicode2zh () {
let content = this.current.content return Unicode.decode(
if (content) { this.current.content.replace(/\\U[0-9a-fA-F]{4}/g,(item)=>{
let newStr = '' // \Uxxxx=>\uxxxx
let t = 1 return item.replace("\\U","\\u");
for (let i = 0; i < content.length; i += t) { })
let str = content.charAt(i) )
if (str === '\\' && 'u' === content.charAt(i + 1)) {
console.log(parseInt(parseInt(content.substr(i + 2, 4), 16).toString(10), 10))
newStr += String.fromCharCode(
parseInt(
parseInt(content.substr(i + 2, 4), 16).toString(10),
10
)
)
t = 6
} else {
t = 1
newStr += str
}
}
return newStr
}
return content
}, },
zh2unicode () { zh2unicode () {
let content = this.current.content let content = this.current.content
......
...@@ -16,7 +16,7 @@ export default { ...@@ -16,7 +16,7 @@ export default {
html_entity_16, html_entity_16,
css_entitie css_entitie
}, },
decode(str, type) { decode(str, type = unicode_point_default) {
const errorListener = (item, callback) => { const errorListener = (item, callback) => {
try { try {
return callback && callback() return callback && callback()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册