Skip to content

Commit

Permalink
Add: 入力欄の全角を半角に変換する機能の追加 (VOICEVOX#1876)
Browse files Browse the repository at this point in the history
音高などの色々な入力欄を入力した際、全角数字や一部記号から半角数字や記号へ変換する
  • Loading branch information
tsym77yoshi authored Feb 26, 2024
1 parent f218028 commit 8b959ab
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/components/Talk/AudioInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ const adjustSliderValue = (
minimalVal: number,
maximamVal: number
) => {
const inputNum = Number(inputStr);
const convertedInputStr = convertFullWidthNumbers(inputStr);
const inputNum = Number(convertedInputStr);
store.dispatch("LOG_INFO", `${inputItemName}:${inputStr}`);
Expand All @@ -933,6 +934,31 @@ const adjustSliderValue = (
return inputNum;
};
const convertFullWidthNumbers = (inputStr: string) => {
const numberConversionMap = [
["", "0"],
["", "1"],
["", "2"],
["", "3"],
["", "4"],
["", "5"],
["", "6"],
["", "7"],
["", "8"],
["", "9"],
["", "."],
["", "."],
["", "-"],
];
let convertedInputStr = inputStr;
for (const [pattern, replacement] of numberConversionMap) {
const regex = new RegExp(pattern, "g");
convertedInputStr = convertedInputStr.replace(regex, replacement);
}
return convertedInputStr;
};
</script>

<style scoped lang="scss">
Expand Down

0 comments on commit 8b959ab

Please sign in to comment.