diff options
author | Laura Aino Violetta Aléanor <lav@vampires.gay> | 2023-05-11 16:25:10 +0200 |
---|---|---|
committer | Laura Aino Violetta Aléanor <lav@vampires.gay> | 2023-05-11 16:25:10 +0200 |
commit | 37c7d6885280cf339a2b75e52d716343dba56230 (patch) | |
tree | a23839114b22450aee917b6b10649bf9fcdce91e /unicode.hs | |
parent | d0c5183b37913b590444ac85bc3327c7117d82c5 (diff) | |
download | pickme-37c7d6885280cf339a2b75e52d716343dba56230.tar.gz pickme-37c7d6885280cf339a2b75e52d716343dba56230.zip |
add support for 'favorite' emoji
Diffstat (limited to 'unicode.hs')
-rw-r--r-- | unicode.hs | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -8,14 +8,23 @@ import qualified Data.Text as T import qualified Data.Text.IO as IO import Foreign.C.String import Numeric +import System.Directory import System.Environment.Blank +import System.IO import System.IO.Unsafe -unicodeDataPath = (getEnv "XDG_DATA_HOME") >>= \s -> return ( - (case s of +xdgDataHome :: IO [Char] +xdgDataHome = (getEnv "XDG_DATA_HOME") >>= \s-> return + ((case s of Nothing -> "~/.local/share" Just x -> if x == "" then "~/.local/share" else x) - ++ "/pickme/UnicodeData.txt") + ++ "/pickme") + +dataFile :: [Char] -> IO [Char] +dataFile name = xdgDataHome >>= (return . flip (++) ("/" ++ name)) + +unicodeDataPath :: IO [Char] +unicodeDataPath = dataFile "UnicodeData.txt" scsvField :: Int -> T.Text -> T.Text scsvField n t = (T.splitOn (T.pack ";") t)!!n @@ -30,8 +39,19 @@ searchCharacterByName :: CString -> IO CString searchCharacterByName s = peekCString s >>= \z -> characterNames >>= \cns -> unicodeCharacters >>= \ucs -> - newCString $ map + 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 + +favoritesPath :: IO [Char] +favoritesPath = dataFile "favorites" + +favoriteEmojis :: IO CString +favoriteEmojis = favoritesPath >>= doesFileExist >>= \ bool -> case bool of + True -> favoritesPath >>= flip openFile ReadMode >>= hGetLine >>= newCString + False -> newCString "" + + +foreign export ccall favoriteEmojis :: IO CString |