diff options
author | Camil Staps | 2015-07-03 16:54:12 +0200 |
---|---|---|
committer | Camil Staps | 2015-07-03 16:59:58 +0200 |
commit | 8141816bccdc173b8318ba9eb80043bec2d644b3 (patch) | |
tree | 1608b2fbddec92af4adb2398633799a0ccb70cd8 /StringUtils.icl | |
parent | Cleanup; simple truthtable; license; readme (diff) |
Parser; cleanup
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 + |