This commit is contained in:
千住柱間 2024-11-12 18:43:49 -04:00
parent 6ad19f1a4c
commit 80ff0f62fe
Signed by: hashirama
GPG key ID: 53E62470A86BC185
3 changed files with 44 additions and 1 deletions

View file

@ -1,3 +1,3 @@
# waza-hs
library for handling japanese text in haskell
wazajisho library for handling japanese text in haskell

7
examples/Main.hs Normal file
View file

@ -0,0 +1,7 @@
import KanaConv (convertHalfToFull)
main :: IO ()
main = do
let input = "おいそこのキミ。あっはいはいはいは~い。"
let output = convertHalfToFull input
putStrLn output

36
src/KanaConv.hs Normal file
View file

@ -0,0 +1,36 @@
-- Copyright © 2024 Hashirama Senju
{-# LANGUAGE OverloadedStrings #-}
module KanaConv (convertHalfToFull) where -- Export convertHalfToFull function
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
-- The Kana mapping for half-width to full-width katakana
halfToFullMapping :: Map.Map String String
halfToFullMapping = Map.fromList
[ ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("ソ", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", ""), ("", ""), ("", "")
, ("", ""), ("", ""), ("", "")
]
-- Function to replace half-width characters with full-width characters
replaceChar :: Char -> String
replaceChar char
| Just full <- Map.lookup [char] halfToFullMapping = full
| otherwise = [char]
-- Function to convert the entire string
convertHalfToFull :: String -> String
convertHalfToFull = concatMap replaceChar