-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ function lstrip(s::AbstractString, chars::Chars=_default_delims) | |
end | ||
i = j | ||
end | ||
"" | ||
s[end+1:end] | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
StefanKarpinski
Author
Member
|
||
end | ||
|
||
function rstrip(s::AbstractString, chars::Chars=_default_delims) | ||
|
@@ -83,7 +83,7 @@ function rstrip(s::AbstractString, chars::Chars=_default_delims) | |
end | ||
i = j | ||
end | ||
"" | ||
s[1:0] | ||
end | ||
|
||
strip(s::AbstractString) = lstrip(rstrip(s)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,30 @@ | |
@test rpad("foo", 6, " ") == "foo " | ||
|
||
# string manipulation | ||
@test strip("") == "" | ||
@test strip(" ") == "" | ||
@test strip(" ") == "" | ||
@test strip(" ") == "" | ||
@test strip("\t hi \n") == "hi" | ||
@test strip("foobarfoo", ['f', 'o']) == "bar" | ||
|
||
for s in ("", " ", " abc", "abc ", " abc "), f in (lstrip, rstrip, strip) | ||
fs = f(s) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
StefanKarpinski
Author
Member
|
||
for T = (ASCIIString, UTF8String, UTF16String, UTF32String) | ||
t = convert(T,s) | ||
ft = f(t) | ||
@test s == t | ||
@test fs == ft | ||
@test typeof(ft) == typeof(t[1:end]) | ||
|
||
b = convert(SubString{T}, t) | ||
fb = f(b) | ||
@test s == b | ||
@test fs == fb | ||
@test typeof(fb) == SubString{T} | ||
end | ||
end | ||
|
||
# split | ||
@test isequal(split("foo,bar,baz", 'x'), ["foo,bar,baz"]) | ||
@test isequal(split("foo,bar,baz", ','), ["foo","bar","baz"]) | ||
|
Why is this end+1:end instead of 1:0, as in the next one?
Potentially costly?