string-upcase(3scm)
π string-upcase(3scm) β string case conversion, bestie edition
okay so this is string-upcase(3scm) from the Scheme Programmer's Manual, and it's literally the glow-up page for your strings β¨ four whole procedures that change the case of your text and honestly they ate.
β¨ NAME β¨
string-upcase, string-downcase, string-titlecase, string-foldcase β string case conversion π
π LIBRARY π
import these depending on which report you're living in, no cap:
(import (rnrs)) ;R6RS
(import (rnrs unicode)) ;R6RS
(import (scheme char)) ;R7RS
π¦ SYNOPSIS π¦
(string-upcase string)
(string-downcase string)
(string-titlecase string) ;R6RS
(string-foldcase string)
πΈ DESCRIPTION πΈ
Every one of these hands you back a case-converted version of string. That's the whole vibe. But the way they each do it is different, so let's get into it:
string-upcaseβ converts a string to upper case. LOUD MODE, all caps, main character energy π₯string-downcaseβ converts a string to lower case. soft launch, lowercase era πstring-foldcaseβ converts the string to its case-folded counterpart, using the full case-folding mapping, but without the special mappings for Turkic languages. iykyk πstring-titlecaseβ converts the first cased character of each word to title case, and downcases all other cased characters. every word gets its moment π
Heads up bestie: these procedures are defined in terms of Unicode's locale-independent case mappings from Unicode scalar-value sequences to scalar-value sequences. Which means β and this is the part that gets people β the length of the result string can be different from the length of the input string. not a typo, fr fr π
And since these procedures are locale-independent, they may not be appropriate for some locales. lowkey a limitation but that's the deal π«Ά
R7RS π§
The Unicode Standard prescribes special treatment of the Greek letter Ξ£, whose normal lower-case form is Ο but which becomes Ο at the end of a word. See Unicode Standard Annex #44 for details.
However β and this is the important part β implementations of string-downcase are not required to provide this behavior, and may choose to change Ξ£ to Ο in all cases. so don't come for an implementation that doesn't do the fancy thing π
π οΈ IMPLEMENTATION NOTES π οΈ
The case mappings you need to actually implement these procedures can be extracted from UnicodeData.txt, SpecialCasing.txt, WordBreakProperty.txt, and CaseFolding.txt from the Unicode Consortium. in case you were wondering where the data lives β¨
Word breaking, as needed for the correct casing of Ξ£ and for string-titlecase, is specified in Unicode Standard Annex #29.
π RETURN VALUES π
These procedures return a single value; a string. one value, one string, slay.
When the specified result is equal in the sense of string=?(3scm) to the argument, these procedures may return the argument instead of a newly allocated string. so don't go assuming it's a fresh object, okay? π
β EXAMPLES β
the receipts π§Ύ
(string-upcase "Hi") => "HI"
(string-downcase "Hi") => "hi"
(string-foldcase "Hi") => "hi"
(string-upcase "StraΓe") => "STRASSE"
(string-downcase "StraΓe") => "straΓe"
(string-foldcase "StraΓe") => "strasse"
(string-downcase "STRASSE") => "strasse"
(string-downcase "Ξ£") => "Ο"
watch the length change on StraΓe β STRASSE, iconic π₯
;; Chi Alpha Omicron Sigma.
;; See the note on R7RS in the description.
(string-upcase "XAOΞ£") => "XAOΞ£"
(string-downcase "XAOΞ£") => "ΟΞ±oΟ"
(string-downcase "XAOΣΣ") => "ΟΞ±oΟΟ"
(string-downcase "XAOΞ£ Ξ£") => "ΟΞ±oΟ Ο"
(string-foldcase "XAOΣΣ") => "ΟΞ±oΟΟ"
(string-upcase "ΟΞ±oΟ") => "XAOΞ£"
(string-upcase "ΟΞ±oΟ") => "XAOΞ£"
that's the whole Ξ£ situation in action, see the R7RS note above π
(string-titlecase "kNock KNoCK") => "Knock Knock"
(string-titlecase "who's there?") => "Who's There?"
(string-titlecase "r6rs") => "R6rs"
(string-titlecase "R6RS") => "R6rs"
title case is unbothered by your SHOUTING, it's giving serene ποΈ
π COMPATIBILITY π
In R6RS implementations, case conversion differs according to which Unicode version is supported. and important: R7RS does not have string-titlecase. so if it's missing, that's why π«
π ERRORS π
This procedure can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed or an argument was outside its domain. classic.- R7RS β the assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophically. no cap π
π SEE ALSO π
char-upper-case?(3scm)- Unicode Standard Annex #44: Unicode Character Database.
- Unicode Standard Annex #29: Unicode Text Segmentation.
π STANDARDS π
R6RS, R7RS
π HISTORY π
The first Scheme report with these procedures is R6RS. They were later also added in R7RS, except for string-titlecase. she got left out, tragic β¨
π«Ά AUTHORS π«Ά
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.
that's the whole page bestie, go forth and case-convert responsibly π
scheme-manpages, dated 2022-05-13, filed under string-upcase(3scm) β mwah, take care π¦
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms