-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
implement islower, isupper and istitle for String #23394
Conversation
`islower` and `isupper` were deprecated to a simplistic behavior which left to be desired; the new functions check that the predicate is true *only* for letters, and that there is at least one letter. This is the behavior of some other languages (e.g. Python) and is inspired by http://www.unicode.org/L2/L1999/99190.htm. Also, `islower(lowercase(s))` is now true for many more strings (false only if s doesn't contain any letter).
@@ -265,7 +265,31 @@ julia> islower('❤') | |||
false | |||
``` | |||
""" | |||
islower(c::Char) = (category_code(c) == UTF8PROC_CATEGORY_LL) | |||
islower(c::Char) = islower(category_code(c)) | |||
islower(ccode::Int32) = ccode == UTF8PROC_CATEGORY_LL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a separate function, not a method of islower
.
I don't think Base should be in the business of implementing subtle Unicode string tests. |
julia> islower("12 ÷ 3 == 4") | ||
false | ||
|
||
julia> islower(lowercase(randstring())) # very unlikely to be false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use a random string here
What is the use-case for this function? |
I have to admit that I only used them at the REPL while testing #23379 and was surpised to see them deprecated; I wanted to use them in the tests of this PR. So I don't badly need those functions. |
Without a real use case, it seems difficult to decide on the best semantics, much less decide whether it is worth including. |
@@ -205,6 +205,11 @@ Library improvements | |||
* Mutating versions of `randperm` and `randcycle` have been added: | |||
`randperm!` and `randcycle!` ([#22723]). | |||
|
|||
* `islower`, `isupper` for strings have beed un-deprecated in favor of a refined behavior: | |||
e.g. `islower(s)` returns `true` if all letters in `s` are lowercase, and if there | |||
is at least on letter in `s` (the old behavior was `all(islower, s)`); also, a new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be: at least one letter
Not: at least on letter
we have |
islower
andisupper
were deprecated to a simplisticbehavior which left to be desired; the new functions
check that the predicate is true only for letters,
and that there is at least one letter. This is the behavior
of some other languages (e.g. Python) and is inspired by
http://www.unicode.org/L2/L1999/99190.htm.
Also,
islower(lowercase(s))
is now true for many morestrings (false only if s doesn't contain any letter).
Note: I'm still confused by the difference between
isupper
andistitle
for characters - this may need to be adjusted.