string-upcase(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’– 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