summaryrefslogtreecommitdiff
path: root/unicode.hs
diff options
context:
space:
mode:
authorLaura Aino Violetta Aléanor <lav@vampires.gay>2023-05-07 19:33:43 +0200
committerLaura Aino Violetta Aléanor <lav@vampires.gay>2023-05-07 19:33:43 +0200
commitc9c7476a205bc7b30f6d7f218a1d794127f1bf2f (patch)
tree09d4b2978570f4b0e51a8a673598c8fc5d337452 /unicode.hs
downloadpickme-c9c7476a205bc7b30f6d7f218a1d794127f1bf2f.tar.gz
pickme-c9c7476a205bc7b30f6d7f218a1d794127f1bf2f.zip
Initial commit
Diffstat (limited to 'unicode.hs')
-rw-r--r--unicode.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/unicode.hs b/unicode.hs
new file mode 100644
index 0000000..cd58fec
--- /dev/null
+++ b/unicode.hs
@@ -0,0 +1,37 @@
+{-# LANGUAGE ForeignFunctionInterface,CPP #-}
+
+module Unicode where
+
+import Data.List
+import Data.Maybe
+import qualified Data.Text as T
+import qualified Data.Text.IO as IO
+import Foreign.C.String
+import Numeric
+import System.Environment.Blank
+import System.IO.Unsafe
+
+unicodeDataPath = (getEnv "XDG_DATA_HOME") >>= \s -> return (
+ (case s of
+ Nothing -> "~/.local/share"
+ Just x -> if x == "" then "~/.local/share" else x)
+ ++ "/pickme/UnicodeData.txt")
+
+scsvField :: Int -> T.Text -> T.Text
+scsvField n t = (T.splitOn (T.pack ";") t)!!n
+
+unicodeCharacters :: IO [T.Text]
+unicodeCharacters = unicodeDataPath >>= IO.readFile >>= return . T.lines
+
+characterNames :: IO [T.Text]
+characterNames = unicodeCharacters >>= \cs -> return $ map (scsvField 1) cs
+
+searchCharacterByName :: CString -> IO CString
+searchCharacterByName s = peekCString s >>= \z ->
+ characterNames >>= \cns ->
+ unicodeCharacters >>= \ucs ->
+ newCString $ map
+ (\x -> toEnum . fst . (!!0) . readHex $ T.unpack (ucs!!(fromJust $ elemIndex x cns)))
+ (filter (\s' -> T.isInfixOf ((T.toUpper . T.pack) z) s') cns)
+
+foreign export ccall searchCharacterByName :: CString -> IO CString