Some string-oriented methods use case mapping.
In String:
In Symbol:
Default Case Mapping¶ ↑By default, all of these methods use full Unicode case mapping, which is suitable for most languages. See Section 3.13 (Default Case Algorithms) of the Unicode standard.
Non-ASCII case mapping and folding are supported for UTF-8, UTF-16BE/LE, UTF-32BE/LE, and ISO-8859-1~16 Strings/Symbols.
Context-dependent case mapping as described in Table 3-17 (Context Specification for Casing) of the Unicode standard is currently not supported.
In most cases, the case conversion of a string has the same number of characters as before. There are exceptions (see also :fold
below):
s = "\u00DF" s.upcase s = "\u0149" s.upcase
Case mapping may also depend on locale (see also :turkic
below):
s = "\u0049" s.downcase s.downcase(:turkic)
Case changes may not be reversible:
s = 'Hello World!' s.downcase s.downcase.upcase
Case changing methods may not maintain Unicode normalization. See String#unicode_normalize
.
Except for casecmp
and casecmp?
, each of the case-mapping methods listed above accepts an optional argument, mapping
.
The argument is one of:
:ascii
: ASCII-only mapping. Uppercase letters (âAâ..âZâ) are mapped to lowercase letters (âaâ..âz); other characters are not changed
s = "Foo \u00D8 \u00F8 Bar" s.upcase s.downcase s.upcase(:ascii) s.downcase(:ascii)
:turkic
: Full Unicode case mapping. For the Turkic languages that distinguish dotted and dotless I, for example Turkish and Azeri.
s = 'Türkiye' s.upcase s.upcase(:turkic) s = 'TÃRKIYE' s.downcase s.downcase(:turkic)
:fold
(available only for String#downcase
, String#downcase!
, and Symbol#downcase
). Unicode case folding, which is more far-reaching than Unicode case mapping.
s = "\u00DF" s.downcase s.downcase(:fold) s.upcase s = "\uFB04" s.downcase s.upcase s.downcase(:fold)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4