Skip to content

Commit

Permalink
tidy up replace
Browse files Browse the repository at this point in the history
  • Loading branch information
TeofilC committed Feb 9, 2023
1 parent e275071 commit 22675d7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,9 @@ replace needle@(Text _ _ neeLen)
(Text repArr repOff repLen)
haystack@(Text hayArr hayOff hayLen)
| neeLen == 0 = emptyError "replace"
| hayLen == 0 = empty -- we can't just return 'haystack' in this case as reboxing might duplicate it
| len == 0 = empty -- we can't just return 'haystack' in this case as reboxing might duplicate it
| L.null ixs = haystack
| len > 0 = Text (A.run x) 0 len
| otherwise = empty
| otherwise = Text (A.run x) 0 len
where
ixs = indices needle haystack
len = hayLen - (neeLen - repLen) `mul` L.length ixs
Expand Down

0 comments on commit 22675d7

Please sign in to comment.