-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add converters.vim to separate functions
- Loading branch information
1 parent
ca4c7b1
commit 4f5294f
Showing
2 changed files
with
35 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function! converters#kata_to_hira(str) abort | ||
return a:str->substitute('[ァ-ヶ]', {m->nr2char(char2nr(m[0], v:true) - 96, v:true)}, 'g') | ||
endfunction | ||
|
||
function! converters#hira_to_kata(str) abort | ||
return a:str->substitute('[ぁ-ゖ]', {m->nr2char(char2nr(m[0], v:true) + 96, v:true)}, 'g') | ||
endfunction | ||
|
||
function! converters#hira_to_dakuten(str) abort | ||
return a:str->substitute('[^[:alnum:][:graph:][:space:]]', {m->m[0] .. '゛'}, 'g') | ||
endfunction | ||
|
||
" たまにsplit文字列の描画がおかしくなるので注意 | ||
let s:hankana_list = ('ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトド' | ||
\ .. 'ナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロワワイエヲンヴーカケ') | ||
\ ->split('.[゙゚]\?\zs') | ||
let s:zen_kata_origin = char2nr('ァ', v:true) | ||
let s:griph_map = { 'ー': '-', '〜': '~', '、': '、', '。': '。', '「': '「', '」': '」', '・': '・' } | ||
|
||
function! converters#zen_kata_to_han_kata(str) abort | ||
return a:str->substitute('.', {m->get(s:griph_map,m[0],m[0])}, 'g') | ||
\ ->substitute('[ァ-ヶ]', {m->get(s:hankana_list, char2nr(m[0], v:true) - s:zen_kata_origin, m[0])}, 'g') | ||
\ ->substitute('[!-~]', {m->nr2char(char2nr(m[0], v:true) - 65248, v:true)}, 'g') | ||
endfunction | ||
|
||
function! converters#hira_to_han_kata(str) abort | ||
return converters#zen_kata_to_han_kata(converters#hira_to_kata(a:str)) | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters