Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make character predicates (isspace etc) work for strings arguments too #4102

Merged
merged 1 commit into from
Aug 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,11 @@ for name = ("alnum", "alpha", "cntrl", "digit", "graph",
"lower", "print", "punct", "space", "upper")
f = symbol(string("is",name))
@eval ($f)(c::Char) = bool(ccall($(string("isw",name)), Int32, (Cwchar_t,), c))
@eval $f(s::String) = all($f, s)
end

isblank(c::Char) = c==' ' || c=='\t'
isblank(s::String) = all(isblank, s)

## generic string uses only endof and next ##

Expand Down Expand Up @@ -613,6 +615,7 @@ escape_nul(s::String, i::Int) =
!done(s,i) && '0' <= next(s,i)[1] <= '7' ? "\\x00" : "\\0"

isxdigit(c::Char) = '0'<=c<='9' || 'a'<=c<='f' || 'A'<=c<='F'
isxdigit(s::String) = all(isxdigit, s)
need_full_hex(s::String, i::Int) = !done(s,i) && isxdigit(next(s,i)[1])

function print_escaped(io, s::String, esc::String)
Expand Down
64 changes: 38 additions & 26 deletions doc/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1392,82 +1392,94 @@

"),

("Strings","Base","isalnum","isalnum(c::Char)
("Strings","Base","isalnum","isalnum(c::Union(Char,String))

Tests whether a character is alphanumeric.
Tests whether a character is alphanumeric, or whether this
is true for all elements of a string.

"),

("Strings","Base","isalpha","isalpha(c::Char)
("Strings","Base","isalpha","isalpha(c::Union(Char,String))

Tests whether a character is alphabetic.
Tests whether a character is alphabetic, or whether this
is true for all elements of a string.

"),

("Strings","Base","isascii","isascii(c::Char)
("Strings","Base","isascii","isascii(c::Union(Char,String))

Tests whether a character belongs to the ASCII character set.
Tests whether a character belongs to the ASCII character set, or whether this
is true for all elements of a string.

"),

("Strings","Base","isblank","isblank(c::Char)
("Strings","Base","isblank","isblank(c::Union(Char,String))

Tests whether a character is a tab or space.
Tests whether a character is a tab or space, or whether this
is true for all elements of a string.

"),

("Strings","Base","iscntrl","iscntrl(c::Char)
("Strings","Base","iscntrl","iscntrl(c::Union(Char,String))

Tests whether a character is a control character.
Tests whether a character is a control character, or whether this
is true for all elements of a string.

"),

("Strings","Base","isdigit","isdigit(c::Char)
("Strings","Base","isdigit","isdigit(c::Union(Char,String))

Tests whether a character is a numeric digit (0-9).
Tests whether a character is a numeric digit (0-9), or whether this
is true for all elements of a string.

"),

("Strings","Base","isgraph","isgraph(c::Char)
("Strings","Base","isgraph","isgraph(c::Union(Char,String))

Tests whether a character is printable, and not a space.
Tests whether a character is printable, and not a space, or whether this
is true for all elements of a string.

"),

("Strings","Base","islower","islower(c::Char)
("Strings","Base","islower","islower(c::Union(Char,String))

Tests whether a character is a lowercase letter.
Tests whether a character is a lowercase letter, or whether this
is true for all elements of a string.

"),

("Strings","Base","isprint","isprint(c::Char)
("Strings","Base","isprint","isprint(c::Union(Char,String))

Tests whether a character is printable, including space.
Tests whether a character is printable, including space, or whether this
is true for all elements of a string.

"),

("Strings","Base","ispunct","ispunct(c::Char)
("Strings","Base","ispunct","ispunct(c::Union(Char,String))

Tests whether a character is printable, and not a space or
alphanumeric.
alphanumeric, or whether this is true for all elements of a string.

"),

("Strings","Base","isspace","isspace(c::Char)
("Strings","Base","isspace","isspace(c::Union(Char,String))

Tests whether a character is any whitespace character.
Tests whether a character is any whitespace character, or whether this
is true for all elements of a string.

"),

("Strings","Base","isupper","isupper(c::Char)
("Strings","Base","isupper","isupper(c::Union(Char,String))

Tests whether a character is an uppercase letter.
Tests whether a character is an uppercase letter, or whether this
is true for all elements of a string.

"),

("Strings","Base","isxdigit","isxdigit(c::Char)
("Strings","Base","isxdigit","isxdigit(c::Union(Char,String))

Tests whether a character is a valid hexadecimal digit.
Tests whether a character is a valid hexadecimal digit, or whether this
is true for all elements of a string.

"),

Expand Down
65 changes: 39 additions & 26 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -934,57 +934,70 @@ Strings

Gives the number of columns needed to print a string.

.. function:: isalnum(c::Char)
.. function:: isalnum(c::Union(Char,String))

Tests whether a character is alphanumeric.
Tests whether a character is alphanumeric, or whether this
is true for all elements of a string.

.. function:: isalpha(c::Char)
.. function:: isalpha(c::Union(Char,String))

Tests whether a character is alphabetic.
Tests whether a character is alphabetic, or whether this
is true for all elements of a string.

.. function:: isascii(c::Char)
.. function:: isascii(c::Union(Char,String))

Tests whether a character belongs to the ASCII character set.
Tests whether a character belongs to the ASCII character set, or whether this
is true for all elements of a string.

.. function:: isblank(c::Char)
.. function:: isblank(c::Union(Char,String))

Tests whether a character is a tab or space.
Tests whether a character is a tab or space, or whether this
is true for all elements of a string.

.. function:: iscntrl(c::Char)
.. function:: iscntrl(c::Union(Char,String))

Tests whether a character is a control character.
Tests whether a character is a control character, or whether this
is true for all elements of a string.

.. function:: isdigit(c::Char)
.. function:: isdigit(c::Union(Char,String))

Tests whether a character is a numeric digit (0-9).
Tests whether a character is a numeric digit (0-9), or whether this
is true for all elements of a string.

.. function:: isgraph(c::Char)
.. function:: isgraph(c::Union(Char,String))

Tests whether a character is printable, and not a space.
Tests whether a character is printable, and not a space, or whether this
is true for all elements of a string.

.. function:: islower(c::Char)
.. function:: islower(c::Union(Char,String))

Tests whether a character is a lowercase letter.
Tests whether a character is a lowercase letter, or whether this
is true for all elements of a string.

.. function:: isprint(c::Char)
.. function:: isprint(c::Union(Char,String))

Tests whether a character is printable, including space.
Tests whether a character is printable, including space, or whether this
is true for all elements of a string.

.. function:: ispunct(c::Char)
.. function:: ispunct(c::Union(Char,String))

Tests whether a character is printable, and not a space or alphanumeric.
Tests whether a character is printable, and not a space or
alphanumeric, or whether this is true for all elements of a string.

.. function:: isspace(c::Char)
.. function:: isspace(c::Union(Char,String))

Tests whether a character is any whitespace character.
Tests whether a character is any whitespace character, or whether this
is true for all elements of a string.

.. function:: isupper(c::Char)
.. function:: isupper(c::Union(Char,String))

Tests whether a character is an uppercase letter.
Tests whether a character is an uppercase letter, or whether this
is true for all elements of a string.

.. function:: isxdigit(c::Char)
.. function:: isxdigit(c::Union(Char,String))

Tests whether a character is a valid hexadecimal digit.
Tests whether a character is a valid hexadecimal digit, or whether this
is true for all elements of a string.

.. function:: symbol(str)

Expand Down