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

implement islower, isupper and istitle for String #23394

Closed
wants to merge 1 commit into from

Conversation

rfourquet
Copy link
Member

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).

Note: I'm still confused by the difference between isupper and istitle for characters - this may need to be adjusted.

`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
Copy link
Sponsor Member

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.

@JeffBezanson JeffBezanson added strings "Strings!" unicode Related to unicode characters and encodings labels Aug 22, 2017
@StefanKarpinski
Copy link
Sponsor Member

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
Copy link
Member

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

@stevengj
Copy link
Member

What is the use-case for this function?

@rfourquet
Copy link
Member Author

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.

@stevengj
Copy link
Member

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

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

@oscardssmith
Copy link
Member

we have isuppercase, islowercase now.

@DilumAluthge DilumAluthge deleted the rf/str-pred-case branch August 24, 2021 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!" unicode Related to unicode characters and encodings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants