diff options
Diffstat (limited to 'StringUtils.icl')
-rw-r--r-- | StringUtils.icl | 22 |
1 files changed, 16 insertions, 6 deletions
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 + |