Skip to content

Commit

Permalink
split using isspace
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne authored and Viral B. Shah committed May 28, 2018
1 parent 53d6c85 commit 5a3ab0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,20 @@ function rpad(
end

"""
split(s::AbstractString; limit::Integer=0, keepempty::Bool=false)
split(s::AbstractString, chars; limit::Integer=0, keepempty::Bool=true)
split(str::AbstractString, dlm; limit::Integer=0, keepempty::Bool=true)
split(str::AbstractString; limit::Integer=0, keepempty::Bool=false)
Return an array of substrings by splitting the given string on occurrences of the given
character delimiters, which may be specified in any of the formats allowed by
[`findnext`](@ref)'s first argument (i.e. as a string, regular expression or a function),
or as a single character or collection of characters.
Split `str` into an array of substrings on occurences of the delimiter `dlm`. `dlm`
can be any of the formats allowed by [`findnext`](@ref)'s first argument (i.e. as a
string, regular expression or a function), or as a single character or collection of
characters.
If `chars` is omitted, it defaults to the set of all space characters.
If `dlm` is omitted, it defaults to [`isspace`](@ref).
The optional keyword arguments are:
- `limit`: the maximum size of the result. `limit=0` implies no maximum (default)
- `keepempty`: whether empty fields should be kept in the result. Default is `false` without
a `chars` argument, `true` with a `chars` argument.
a `dlm` argument, `true` with a `dlm` argument.
See also [`rsplit`](@ref).
Expand Down Expand Up @@ -322,7 +322,7 @@ end
# a bit oddball, but standard behavior in Perl, Ruby & Python:
split(str::AbstractString;
limit::Integer=0, keepempty::Bool=false) =
split(str, _default_delims; limit=limit, keepempty=keepempty)
split(str, isspace; limit=limit, keepempty=keepempty)

"""
rsplit(s::AbstractString; limit::Integer=0, keepempty::Bool=false)
Expand Down Expand Up @@ -395,7 +395,7 @@ function _rsplit(str::AbstractString, splitter, limit::Integer, keepempty::Bool,
end
rsplit(str::AbstractString;
limit::Integer=0, keepempty::Bool=false) =
rsplit(str, _default_delims; limit=limit, keepempty=keepempty)
rsplit(str, isspace; limit=limit, keepempty=keepempty)

_replace(io, repl, str, r, pattern) = print(io, repl)
_replace(io, repl::Function, str, r, pattern) =
Expand Down
1 change: 1 addition & 0 deletions test/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ end

@test split("a b c") == ["a","b","c"]
@test split("a b \t c\n") == ["a","b","c"]
@test split("α β \u2009 γ\n") == ["α","β","γ"]

@test split("a b c"; limit=2) == ["a","b c"]
@test split("a b \t c\n"; limit=3) == ["a","b","\t c\n"]
Expand Down

0 comments on commit 5a3ab0a

Please sign in to comment.