[DOC] Tweaks for Case Mapping doc

This commit is contained in:
Burdette Lamar 2025-07-04 10:42:29 -05:00 committed by GitHub
parent 38993efb27
commit 350df4fbd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 40 deletions

View file

@ -37,7 +37,7 @@ Context-dependent case mapping as described in
{Table 3-17 (Context Specification for Casing) of the Unicode standard}[https://www.unicode.org/versions/latest/ch03.pdf] {Table 3-17 (Context Specification for Casing) of the Unicode standard}[https://www.unicode.org/versions/latest/ch03.pdf]
is currently not supported. is currently not supported.
In most cases, case conversions of a string have the same number of characters. In most cases, the case conversion of a string has the same number of characters as before.
There are exceptions (see also +:fold+ below): There are exceptions (see also +:fold+ below):
s = "\u00DF" # => "ß" s = "\u00DF" # => "ß"
@ -58,25 +58,18 @@ Case changes may not be reversible:
s.downcase.upcase # => "HELLO WORLD!" # Different from original s. s.downcase.upcase # => "HELLO WORLD!" # Different from original s.
Case changing methods may not maintain Unicode normalization. Case changing methods may not maintain Unicode normalization.
See String#unicode_normalize). See String#unicode_normalize.
== Options for Case Mapping == Case Mappings
Except for +casecmp+ and +casecmp?+, Except for +casecmp+ and +casecmp?+,
each of the case-mapping methods listed above each of the case-mapping methods listed above
accepts optional arguments, <tt>*options</tt>. accepts an optional argument, <tt>mapping</tt>.
The arguments may be: The argument is one of:
- +:ascii+ only. - +:ascii+: ASCII-only mapping.
- +:fold+ only. Uppercase letters ('A'..'Z') are mapped to lowercase letters ('a'..'z);
- +:turkic+ or +:lithuanian+ or both.
The options:
- +:ascii+:
ASCII-only mapping:
uppercase letters ('A'..'Z') are mapped to lowercase letters ('a'..'z);
other characters are not changed other characters are not changed
s = "Foo \u00D8 \u00F8 Bar" # => "Foo Ø ø Bar" s = "Foo \u00D8 \u00F8 Bar" # => "Foo Ø ø Bar"
@ -85,8 +78,8 @@ The options:
s.upcase(:ascii) # => "FOO Ø ø BAR" s.upcase(:ascii) # => "FOO Ø ø BAR"
s.downcase(:ascii) # => "foo Ø ø bar" s.downcase(:ascii) # => "foo Ø ø bar"
- +:turkic+: - +:turkic+: Full Unicode case mapping.
Full Unicode case mapping, adapted for the Turkic languages For the Turkic languages
that distinguish dotted and dotless I, for example Turkish and Azeri. that distinguish dotted and dotless I, for example Turkish and Azeri.
s = 'Türkiye' # => "Türkiye" s = 'Türkiye' # => "Türkiye"
@ -97,11 +90,8 @@ The options:
s.downcase # => "türkiye" s.downcase # => "türkiye"
s.downcase(:turkic) # => "türkıye" # No dot above. s.downcase(:turkic) # => "türkıye" # No dot above.
- +:lithuanian+:
Not yet implemented.
- +:fold+ (available only for String#downcase, String#downcase!, - +:fold+ (available only for String#downcase, String#downcase!,
and Symbol#downcase): and Symbol#downcase).
Unicode case folding, Unicode case folding,
which is more far-reaching than Unicode case mapping. which is more far-reaching than Unicode case mapping.

View file

@ -8056,7 +8056,7 @@ upcase_single(VALUE str)
/* /*
* call-seq: * call-seq:
* upcase!(*options) -> self or nil * upcase!(mapping) -> self or nil
* *
* Upcases the characters in +self+; * Upcases the characters in +self+;
* returns +self+ if any changes were made, +nil+ otherwise: * returns +self+ if any changes were made, +nil+ otherwise:
@ -8066,7 +8066,7 @@ upcase_single(VALUE str)
* s # => "HELLO WORLD!" * s # => "HELLO WORLD!"
* s.upcase! # => nil * s.upcase! # => nil
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#upcase, String#downcase, String#downcase!. * Related: String#upcase, String#downcase, String#downcase!.
@ -8098,14 +8098,14 @@ rb_str_upcase_bang(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* upcase(*options) -> string * upcase(mapping) -> string
* *
* Returns a string containing the upcased characters in +self+: * Returns a string containing the upcased characters in +self+:
* *
* s = 'Hello World!' # => "Hello World!" * s = 'Hello World!' # => "Hello World!"
* s.upcase # => "HELLO WORLD!" * s.upcase # => "HELLO WORLD!"
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#upcase!, String#downcase, String#downcase!. * Related: String#upcase!, String#downcase, String#downcase!.
@ -8158,7 +8158,7 @@ downcase_single(VALUE str)
/* /*
* call-seq: * call-seq:
* downcase!(*options) -> self or nil * downcase!(mapping) -> self or nil
* *
* Downcases the characters in +self+; * Downcases the characters in +self+;
* returns +self+ if any changes were made, +nil+ otherwise: * returns +self+ if any changes were made, +nil+ otherwise:
@ -8168,7 +8168,7 @@ downcase_single(VALUE str)
* s # => "hello world!" * s # => "hello world!"
* s.downcase! # => nil * s.downcase! # => nil
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#downcase, String#upcase, String#upcase!. * Related: String#downcase, String#upcase, String#upcase!.
@ -8200,14 +8200,14 @@ rb_str_downcase_bang(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* downcase(*options) -> string * downcase(mapping) -> string
* *
* Returns a string containing the downcased characters in +self+: * Returns a string containing the downcased characters in +self+:
* *
* s = 'Hello World!' # => "Hello World!" * s = 'Hello World!' # => "Hello World!"
* s.downcase # => "hello world!" * s.downcase # => "hello world!"
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#downcase!, String#upcase, String#upcase!. * Related: String#downcase!, String#upcase, String#upcase!.
@ -8242,7 +8242,7 @@ rb_str_downcase(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* capitalize!(*options) -> self or nil * capitalize!(mapping) -> self or nil
* *
* Upcases the first character in +self+; * Upcases the first character in +self+;
* downcases the remaining characters; * downcases the remaining characters;
@ -8253,7 +8253,7 @@ rb_str_downcase(int argc, VALUE *argv, VALUE str)
* s # => "Hello world!" * s # => "Hello world!"
* s.capitalize! # => nil * s.capitalize! # => nil
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#capitalize. * Related: String#capitalize.
@ -8282,7 +8282,7 @@ rb_str_capitalize_bang(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* capitalize(*options) -> string * capitalize(mapping) -> string
* *
* Returns a string containing the characters in +self+; * Returns a string containing the characters in +self+;
* the first character is upcased; * the first character is upcased;
@ -8291,7 +8291,7 @@ rb_str_capitalize_bang(int argc, VALUE *argv, VALUE str)
* s = 'hello World!' # => "hello World!" * s = 'hello World!' # => "hello World!"
* s.capitalize # => "Hello world!" * s.capitalize # => "Hello world!"
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#capitalize!. * Related: String#capitalize!.
@ -8321,7 +8321,7 @@ rb_str_capitalize(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* swapcase!(*options) -> self or nil * swapcase!(mapping) -> self or nil
* *
* Upcases each lowercase character in +self+; * Upcases each lowercase character in +self+;
* downcases uppercase character; * downcases uppercase character;
@ -8332,7 +8332,7 @@ rb_str_capitalize(int argc, VALUE *argv, VALUE str)
* s # => "hELLO wORLD!" * s # => "hELLO wORLD!"
* ''.swapcase! # => nil * ''.swapcase! # => nil
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#swapcase. * Related: String#swapcase.
@ -8360,7 +8360,7 @@ rb_str_swapcase_bang(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* swapcase(*options) -> string * swapcase(mapping) -> string
* *
* Returns a string containing the characters in +self+, with cases reversed; * Returns a string containing the characters in +self+, with cases reversed;
* each uppercase character is downcased; * each uppercase character is downcased;
@ -8369,7 +8369,7 @@ rb_str_swapcase_bang(int argc, VALUE *argv, VALUE str)
* s = 'Hello World!' # => "Hello World!" * s = 'Hello World!' # => "Hello World!"
* s.swapcase # => "hELLO wORLD!" * s.swapcase # => "hELLO wORLD!"
* *
* The casing may be affected by the given +options+; * The casing may be affected by the given +mapping+;
* see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. * see {Case Mapping}[rdoc-ref:case_mapping.rdoc].
* *
* Related: String#swapcase!. * Related: String#swapcase!.
@ -12482,7 +12482,7 @@ sym_empty(VALUE sym)
/* /*
* call-seq: * call-seq:
* upcase(*options) -> symbol * upcase(mapping) -> symbol
* *
* Equivalent to <tt>sym.to_s.upcase.to_sym</tt>. * Equivalent to <tt>sym.to_s.upcase.to_sym</tt>.
* *
@ -12498,7 +12498,7 @@ sym_upcase(int argc, VALUE *argv, VALUE sym)
/* /*
* call-seq: * call-seq:
* downcase(*options) -> symbol * downcase(mapping) -> symbol
* *
* Equivalent to <tt>sym.to_s.downcase.to_sym</tt>. * Equivalent to <tt>sym.to_s.downcase.to_sym</tt>.
* *
@ -12516,7 +12516,7 @@ sym_downcase(int argc, VALUE *argv, VALUE sym)
/* /*
* call-seq: * call-seq:
* capitalize(*options) -> symbol * capitalize(mapping) -> symbol
* *
* Equivalent to <tt>sym.to_s.capitalize.to_sym</tt>. * Equivalent to <tt>sym.to_s.capitalize.to_sym</tt>.
* *
@ -12532,7 +12532,7 @@ sym_capitalize(int argc, VALUE *argv, VALUE sym)
/* /*
* call-seq: * call-seq:
* swapcase(*options) -> symbol * swapcase(mapping) -> symbol
* *
* Equivalent to <tt>sym.to_s.swapcase.to_sym</tt>. * Equivalent to <tt>sym.to_s.swapcase.to_sym</tt>.
* *