From 8141816bccdc173b8318ba9eb80043bec2d644b3 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 3 Jul 2015 16:54:12 +0200 Subject: Parser; cleanup --- StringUtils.icl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'StringUtils.icl') diff --git a/StringUtils.icl b/StringUtils.icl index e2b7c3e..811b3d2 100644 --- a/StringUtils.icl +++ b/StringUtils.icl @@ -31,18 +31,28 @@ where s` :: [Char] s` = fromString s -pad_right :: String Int -> String -pad_right s l +pad_right :: Char String Int -> String +pad_right c s l | strlen s >= l = s -| otherwise = s +++ toString (repeatn (l - strlen s) ' ') +| otherwise = s +++ toString (repeatn (l - strlen s) c) -pad_left :: String Int -> String -pad_left s l +pad_left :: Char String Int -> String +pad_left c s l | strlen s >= l = s -| otherwise = toString (repeatn (l - strlen s) ' ') +++ s +| otherwise = toString (repeatn (l - strlen s) c) +++ s join :: String [String] -> String join glue [] = "" join glue [s] = s join glue [s:ss] = s +++ glue +++ join glue ss +repl :: a b c -> String | toString a & toString b & toString c +repl needle replment haystack +| strlen needle` > strlen haystack` = haystack` +| needle` == haystack` % (0,strlen needle` - 1) = replment` +++ repl needle` replment` (haystack` % (strlen needle`, strlen haystack` - 1)) +| otherwise = (haystack` % (0,0)) +++ repl needle` replment` (haystack` % (1, strlen haystack` - 1)) +where + needle` = toString needle + replment` = toString replment + haystack` = toString haystack + -- cgit v1.2.3