Skip to content

Commit

Permalink
日本語モジュールに全角半角文字置き換えを追加。辞書系の関数参照先を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kebin628 committed Dec 16, 2024
1 parent 04ef693 commit 47e357b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/components/Dialog/DictionaryEditWordDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ import ContextMenu from "@/components/Menu/ContextMenu/Container.vue";
import { useRightClickContextMenu } from "@/composables/useRightClickContextMenu";
import { useStore } from "@/store";
import type { FetchAudioResult } from "@/store/type";
import { convertHankakuToZenkaku } from "@/domain/japanese";
const store = useStore();
Expand Down Expand Up @@ -267,16 +268,6 @@ const setYomiWhenEnter = (event?: KeyboardEvent) => {
void setYomi(yomi.value);
};
const convertHankakuToZenkaku = (text: string) => {
// " "などの目に見えない文字をまとめて全角スペース(0x3000)に置き換える
text = text.replace(/\p{Z}/gu, () => String.fromCharCode(0x3000));
// "!"から"~"までの範囲の文字(数字やアルファベット)を全角に置き換える
return text.replace(/[\u0021-\u007e]/g, (s) => {
return String.fromCharCode(s.charCodeAt(0) + 0xfee0);
});
};
const setSurface = (text: string) => {
// surfaceを全角化する
// 入力は半角でも問題ないが、登録時に全角に変換され、isWordChangedの判断がおかしくなることがあるので、
Expand Down
1 change: 1 addition & 0 deletions src/components/Dialog/DictionaryManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ import { useStore } from "@/store";
import { AccentPhrase, UserDictWord } from "@/openapi";
import { EngineId, SpeakerId, StyleId } from "@/type/preload";
import {
convertHankakuToZenkaku,
convertHiraToKana,
convertLongVowel,
createKanaRegex,
Expand Down
11 changes: 11 additions & 0 deletions src/domain/japanese/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export const createKanaRegex = (includeSeparation?: boolean): RegExp => {
return /^[\u3041-\u3094\u30A1-\u30F4\u30FC]+$/;
};

/** 半角文字を全角文字にする */
export const convertHankakuToZenkaku = (text: string) => {
// " "などの目に見えない文字をまとめて全角スペース(0x3000)に置き換える
text = text.replace(/\p{Z}/gu, () => String.fromCharCode(0x3000));

// "!"から"~"までの範囲の文字(数字やアルファベット)を全角に置き換える
return text.replace(/[\u0021-\u007e]/g, (s) => {
return String.fromCharCode(s.charCodeAt(0) + 0xfee0);
});
};

/** ひらがなをカタカナにする */
export const convertHiraToKana = (text: string): string => {
return text.replace(/[\u3041-\u3094]/g, (s) => {
Expand Down

0 comments on commit 47e357b

Please sign in to comment.