add KeepWordsLeft and KeepWordsRight for X.L.Renamed and updated CHANGES.md

This commit is contained in:
oogeek
2021-04-05 23:47:39 +08:00
parent 902c2bb17d
commit c3c033bb91
2 changed files with 11 additions and 1 deletions

View File

@@ -46,6 +46,8 @@ data Rename a = CutLeft Int -- ^ Remove a number of characters from the left
| Prepend String -- ^ Add a string on the left
| CutWordsLeft Int -- ^ Remove a number of words from the left
| CutWordsRight Int -- ^ Remove a number of words from the right
| KeepWordsLeft Int -- ^ Keep a number of words from the left
| KeepWordsRight Int -- ^ Keep a number of words from the right
| AppendWords String -- ^ Add a string to the right, prepending a space to it
-- if necessary
| PrependWords String -- ^ Add a string to the left, appending a space to it if
@@ -59,7 +61,10 @@ apply (CutLeft i) s = drop i s
apply (CutRight i) s = take (length s - i) s
apply (CutWordsLeft i) s = unwords $ drop i $ words s
apply (CutWordsRight i) s = let ws = words s
in unwords $ take (length ws - i) ws
in unwords $ take (length ws - i) ws
apply (KeepWordsLeft i) s = unwords $ take i $ words s
apply (KeepWordsRight i) s = let ws = words s
in unwords $ drop (length ws - i) ws
apply (Replace s) _ = s
apply (Append s') s = s ++ s'
apply (Prepend s') s = s' ++ s