Something went wrong. Try again.
Making a new TUI editor maybe
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112-- I'm just copying this until I figure out what I'm doing with Antelude.module Glyph.Extra.String where
----------------------------------------------------------------------------------------------------
import qualified Data.Char as Charimport qualified Data.List as List
----------------------------------------------------------------------------------------------------
-- | Join a 'List' of 'String's together with no additional charactersjoin :: List String -> Stringjoin = List.intercalate ""
-- | Given a "replaceable" substring to replace, and a "replacement" substring, replace all instances of the "replaceable" within a 'String' with the "replacement".replace :: String -> String -> String -> Stringreplace replaceThis replaceWith = replaceMany [(replaceThis, replaceWith)]
-- | Replace a bunch of things at oncereplaceMany :: List (String, String) -> String -> StringreplaceMany rules = walk where usableRules :: List (String, String) usableRules = List.filter (\(replaceThis, _) -> List.null replaceThis |> not) rules
matchAt :: String -> Maybe (String, String) matchAt string = List.find (\(replaceThis, _) -> replaceThis `List.isPrefixOf` string) usableRules
walk :: String -> String walk [] = [] walk string@(character : remaining) = case matchAt string of Just (replaceThis, replaceWith) -> replaceWith <> walk (List.drop (List.length replaceThis) string) Nothing -> character : walk remaining
isNumeric :: String -> BoolisNumeric = List.all Char.isDigit
isPrintable :: String -> BoolisPrintable str = let nonChars :: List String nonChars = [ "<tab>" , "<space>" , "<esc>" , "<bs>" , "<enter>" , "<left>" , "<right>" , "<up>" , "<down>" , "<upleft>" , "<upright>" , "<downleft>" , "<downright>" , "<center>" , "<backtab>" , "<prtscr>" , "<pause>" , "<ins>" , "<del>" , "<home>" , "<begin>" , "<end>" , "<pageup>" , "<pagedown>" , "<menu>" , "<F1>" , "<F2>" , "<F3>" , "<F4>" , "<F5>" , "<F6>" , "<F7>" , "<F8>" , "<F9>" , "<F10>" , "<F11>" , "<F12>" , "<F13>" , "<F14>" , "<F15>" , "<F16>" , "<F17>" , "<F18>" , "<F19>" , "<F20>" , "<F21>" , "<F22>" , "<F23>" , "<F24>" ] in List.elem str nonChars |> not
toNumber :: List Char -> NaturaltoNumber chars = let digitValue :: Char -> Natural digitValue char | Char.isDigit char = Char.ord char - Char.ord '0' |> toEnum | otherwise = 0 in List.foldl' (\accum char -> accum * 10 + digitValue char) 0 chars