nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
b6782c7
)
lib/core: introduce replace_first in text/string_search
author
Alexandre Terrasa
<alexandre@moz-code.org>
Tue, 6 Jun 2017 05:44:15 +0000
(
01:44
-0400)
committer
Alexandre Terrasa
<alexandre@moz-code.org>
Tue, 6 Jun 2017 05:44:15 +0000
(
01:44
-0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
lib/core/text/string_search.nit
patch
|
blob
|
history
diff --git
a/lib/core/text/string_search.nit
b/lib/core/text/string_search.nit
index
6d6302e
..
7648816
100644
(file)
--- a/
lib/core/text/string_search.nit
+++ b/
lib/core/text/string_search.nit
@@
-482,6
+482,15
@@
redef class Text
return self.split_with(pattern).join(string)
end
+ # Replace the first occurrence of `pattern` with `string`
+ #
+ # assert "hlelo".replace_first("le", "el") == "hello"
+ # assert "hello".replace_first('l', "") == "helo"
+ fun replace_first(pattern: Pattern, string: Text): String
+ do
+ return self.split_once_on(pattern).join(string)
+ end
+
# Does `self` contains at least one instance of `pattern`?
#
# assert "hello".has('l')