ToLowerCase¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
ToLowerCase["string"]
Gives "string" with every letter converted to lowercase.
Examples (11)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (3)¶
In[1]:= ToUpperCase["straße"]
Out[1]= "STRASSE"
In[2]:= ToLowerCase[{"ABC", "ΣΟΦΙΑ"}]
Out[2]= {"abc", "σοφια"}
In[3]:= ToUpperCase[x]
Out[3]= ToUpperCase[x]
Applications (8)¶
Latin-1 capitals
Greek capitals
Full mapping: capital dotted I becomes i plus a combining dot
The two code points of that result
Case mapping is not invertible
Listable
A non-string stays unevaluated
Implementation notes¶
Algorithm. builtin_tolowercase calls case_builtin, which accepts exactly one String argument (the evaluator has already threaded the Listable attribute over lists; any other argument returns NULL, unevaluated and silent) and hands it to map_case(s, len, 0, 0, SIZE_MAX). map_case walks the UTF-8 bytes once: an ASCII byte takes an inline fast path (A–Z), while a multi-byte sequence is decoded with u8_decode, looked up by binary search (case_find) in k_lower_map, and either re-encoded from the table's 1–3 target code points with u8_encode or, when the character has no mapping, copied byte for byte. This is the full (not simple) case mapping, context- and locale-free.
Data structures. k_lower_map is a sorted array of U8CaseMap {cp, n, to[3]} records — every code point whose → mapping differs from itself — generated from Python's unicodedata / str.→() by tools/gen_unicode_tables.py (Unicode 16.0.0) into src/strings/unicode_tables.inc. The output buffer starts at input length + 16 bytes and doubles only when fewer than 13 bytes of headroom remain (room for one character expanding to three 4-byte code points), so a same-size mapping never reallocates; the buffer is adopted into the result String without a copy.
Complexity / limits. O(L log M) for a string of L characters and M table entries (O(L) for pure ASCII). No final-sigma or Turkish/Lithuanian tailoring. There is no packed-array or Compile[] surface: the argument and result are Strings, which no machine buffer or compiled register holds.
Attributes: Listable, Protected.
References¶
See also: ToUpperCase
- The Unicode Consortium, The Unicode Standard, Version 16.0 (2024), §3.13 Default Case Algorithms, and the Unicode Character Database (UnicodeData.txt, SpecialCasing.txt).
- Source:
src/strings/stringcase.c - Specification:
docs/spec/builtins/string-operations.md - Tests:
tests/test_string_review.c
Notes & additional examples¶
Notes¶
- Full Unicode (16.0) lowercase mapping from the generated
k_lower_maptable; a character may map to several code points (İ → i̇, length 2). - No context-sensitive rules: a word-final capital sigma
Σalways becomesσ, never finalς, and there is no locale tailoring. - Attributes
{Listable, Protected}; a non-string is left unevaluated silently. - See also:
ToUpperCase,Decapitalize,LowerCaseQ.