Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【功能请求】选定的文本半角和全角互换 #54

Open
Oswald522 opened this issue Jan 18, 2023 · 2 comments
Open

【功能请求】选定的文本半角和全角互换 #54

Oswald522 opened this issue Jan 18, 2023 · 2 comments

Comments

@Oswald522
Copy link

蚕子大佬好:
经常在PDF中复制文字,发现会出现全角和半角混淆的情况。例如 PDF内复制文字:
全角: 1)输入初始 电 压:u= [u1,u2,u3,...,un],其 中n 表示驱动器个数; 2) 生 成 扰 动 电 压:δu= [δu1,δu2,δu3,..., δun]; 3)发 送 正 向 扰 动 电 压,u+ =u+δu= [u1 + δu1,u2+δu2,u3 +δu3,...,un +δun],计 算 正 向 扰 动指标J+ ; 4)发 送 负 向 扰 动 电 压,u- =u-δu= [u1 δu1,u2-δu2,u3 -δu3,...,un -δun],计 算 负 向 扰 动指标J- ; 5)对 电 压 进 行 迭 代 运 算 ,运 算 公 式 为 u(t+1)=u(t)+ηδu(J+-J- ),
半角:1)输入初始 电 压:u= [u1,u2,u3,...,un],其 中n 表示驱动器个数; 2) 生 成 扰 动 电 压:δu= [δu1,δu2,δu3,..., δun]; 3)发 送 正 向 扰 动 电 压,u+ =u+δu= [u1 + δu1,u2+δu2,u3 +δu3,...,un +δun],计 算 正 向 扰 动指标J+ ; 4)发 送 负 向 扰 动 电 压,u- =u-δu= [u1 δu1,u2-δu2,u3 -δu3,...,un -δun],计 算 负 向 扰 动指标J- ; 5)对 电 压 进 行 迭 代 运 算 ,运 算 公 式 为 u(t+1)=u(t)+ηδu(J+-J- ),

以上为全半角内容对比,希望可以增加功能,半角和全角转换。
提供VScode参考插件,可以实现上述功能:https://github.com/mo-san/Zenkaku-Hankaku.

恳请大佬考虑一下!

@obsidian-canzi
Copy link
Owner

你好,有时间请qq:(312815311)详细交流一下,我需要逐个字符进行确定,如此字符需要如何转换。谢谢

@Oswald522
Copy link
Author

Oswald522 commented Oct 4, 2023

你好,感谢大佬的回复,提供以下代码用于参考,主要基于UTF8,转换的字符包括A-Z,标点符号、数字、等。另外之前完成转换任务都是基于 vscode插件实现mo-san/Zenkaku-Hankaku.,提供源码插件转换核心代码

 full_shape:
    " ": { commit: " " }
    ",": { commit: , }
    ".": { commit: 。 }
    "<": [《, 〈, «, ‹]
    ">": [》, 〉, », ›]
    "/": [/, ÷]
    "?": { commit: ? }
    ";": { commit: ; }
    ":": { commit: : }
    "'": { pair: ["‘", "’"] }
    '"': { pair: ["“", "”"] }
    '\': [、, \]
    "|": [·, |, "§", "¦"]
    "`": 
    "~": 
    "!": { commit: ! }
    "@": ""
    "#": [#, ⌘]
    "%": [%, "°", "℃"]
    "$": [¥, "$", "€", "£", "¥", "¢", "¤"]
    "^": { commit: …… }
    "&": 
    "*": [*, ·, ・, ×, ※, ❂]
    "(": 
    ")": 
    "-": 
    "_": ——
    "+": 
    "=": 
    "[": [「, 【, 〔, []
    "]": [」, 】, 〕, ]]
    "{": [『, 〖, {]
    "}": [』, 〗, }]
  half_shape:
    ",": { commit: , }
    ".": { commit: 。 }
    "<": [《, 〈, «, ‹]
    ">": [》, 〉, », ›]
    "/": "/"
    "?": { commit: ? }
    ";": { commit: ; }
    ":": { commit: : }
    "'": { pair: ["‘", "’"] }
    '"': { pair: ["“", "”"] }
    '\': ""
    "|": [·, "|", |, "§", "¦"]
    "`": "`"
    "~": ""
    "!": { commit: ! }
    "@": "@"
    "#": "#"
    "%": ["%", %, "°", "℃"]
    "$": [¥, "$", "€", "£", "¥", "¢", "¤"]
    "^": { commit: …… }
    "&": "&"
    "*": ["*", *, ·, ・, ×, ※, ❂]
    "(": 
    ")": 
    "-": "-"
    "_": "——"
    "+": "+"
    "=": "="
    "[": ""
    "]": ""
    "{": ""
    "}": ""
// js 实现中文半角he全角转换

// 半角转全角
function ToDBC(str) {
var result = '';
for (var i = 0; i < str.length; i++) {
    code = str.charCodeAt(i);
    if (code >= 33 && code <= 126) {
    result += String.fromCharCode(str.charCodeAt(i) + 65248);
    } else if (code == 32) {
    result += String.fromCharCode(str.charCodeAt(i) + 12288 - 32);
    } else {
    result += str.charAt(i);
    }
}
return result;
}


// 全角转半角
function ToCDB(str) {
var result = '';
for (var i = 0; i < str.length; i++) {
    code = str.charCodeAt(i);
    if (code >= 65281 && code <= 65374) {
    result += String.fromCharCode(str.charCodeAt(i) - 65248);
    } else if (code == 12288) {
    result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
    } else {
    result += str.charAt(i);
    }}
return result;
}
// 测试案例
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
console.log(ToCDB(str)); // ABCDEFGHIJKLMNOPQRSTUVWXYZ
var str2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
console.log(ToDBC(str2)); // ABCDEFGHIJKLMNOPQRSTUVWXYZ

2023-10-04_13-10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants