aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2018-03-01 12:37:49 +0100
committerDan Gudmundsson <[email protected]>2018-03-01 12:37:49 +0100
commit3bba476ad0df599050ccfc0826856111f5ff1bde (patch)
tree8703a51657f3a9716863cb2920e4dce88797be12
parent88c4c305636618af4002c8c484083668a88824e9 (diff)
parent693315d23293cb107c2ad7e50960dee40d7a3ca9 (diff)
downloadotp-3bba476ad0df599050ccfc0826856111f5ff1bde.tar.gz
otp-3bba476ad0df599050ccfc0826856111f5ff1bde.tar.bz2
otp-3bba476ad0df599050ccfc0826856111f5ff1bde.zip
Merge branch 'maint'
* maint: ERL-558 Add the missing function clause for string:prefix (#1702)
-rw-r--r--lib/stdlib/src/string.erl8
-rw-r--r--lib/stdlib/test/string_SUITE.erl4
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/stdlib/src/string.erl b/lib/stdlib/src/string.erl
index e01bb7d85e..4e89819e41 100644
--- a/lib/stdlib/src/string.erl
+++ b/lib/stdlib/src/string.erl
@@ -420,10 +420,12 @@ to_number(_, Number, Rest, _, Tail) ->
%% Return the remaining string with prefix removed or else nomatch
-spec prefix(String::unicode:chardata(), Prefix::unicode:chardata()) ->
'nomatch' | unicode:chardata().
-prefix(Str, []) -> Str;
prefix(Str, Prefix0) ->
- Prefix = unicode:characters_to_list(Prefix0),
- case prefix_1(Str, Prefix) of
+ Result = case unicode:characters_to_list(Prefix0) of
+ [] -> Str;
+ Prefix -> prefix_1(Str, Prefix)
+ end,
+ case Result of
[] when is_binary(Str) -> <<>>;
Res -> Res
end.
diff --git a/lib/stdlib/test/string_SUITE.erl b/lib/stdlib/test/string_SUITE.erl
index c4a469c251..fdff2d24b8 100644
--- a/lib/stdlib/test/string_SUITE.erl
+++ b/lib/stdlib/test/string_SUITE.erl
@@ -486,6 +486,10 @@ to_float(_) ->
prefix(_) ->
?TEST("", ["a"], nomatch),
?TEST("a", [""], "a"),
+ ?TEST("a", [[[]]], "a"),
+ ?TEST("a", [<<>>], "a"),
+ ?TEST("a", [[<<>>]], "a"),
+ ?TEST("a", [[[<<>>]]], "a"),
?TEST("b", ["a"], nomatch),
?TEST("a", ["a"], ""),
?TEST("å", ["a"], nomatch),