History

move headers and docs to their own dirs to declutter src/

Sigrid Solveig Haflínudóttir committed 3 months ago

Commit 77a7e801 parent 6e4532193 files · +221 −210Browse files

Showing the changes to src/docs/string.sl (1 of 93 files). Show all

Unified · Split

src/docs/string.sl+246−0
@@ -0,0 +1,246 @@
1+(doc-group string
2+ «Strings and runes.»)
3+
4+(defdoc (rune (n #xfffd))
5+ «Construct a rune from a Unicode code point. Without code point
6+ specified, an "invalid" rune (`#xFFFD`) is returned.»
7+ :doc-group string
8+ :doc-see rune?)
9+
10+(defdoc (rune->codepoint r)
11+ «Return a rune's Unicode code point as a fixnum.»
12+ :doc-example
13+ «(rune->codepoint #\й)
14+ ; ↳ 1081»
15+ :doc-group string)
16+
17+(defdoc (rune-alphabetic? r)
18+ «Return `T` if the rune is alphabetic, `NIL` otherwise.»
19+ :doc-example
20+ «(rune-alphabetic? #\9)
21+ ; ↳ NIL»
22+ :doc-example
23+ «(rune-alphabetic? #\й)
24+ ; ↳ T»
25+ :doc-group string
26+ :doc-see rune-numeric?
27+ :doc-see rune-whitespace?)
28+
29+(defdoc (rune-numeric? r)
30+ «Return `T` if the rune is numeric, `NIL` otherwise.»
31+ :doc-example
32+ «(rune-numeric? #\9)
33+ ; ↳ T»
34+ :doc-example
35+ «(rune-numeric? #\й)
36+ ; ↳ NIL»
37+ :doc-group string
38+ :doc-see rune-alphabetic?
39+ :doc-see rune-whitespace?)
40+
41+(defdoc (rune-whitespace? r)
42+ «Return `T` if the rune is whitespace, `NIL` otherwise.»
43+ :doc-example
44+ «(rune-whitespace? #\newline)
45+ ; ↳ T»
46+ :doc-example
47+ «(rune-whitespace? #\_)
48+ ; ↳ NIL»
49+ :doc-group string
50+ :doc-see rune-alphabetic?
51+ :doc-see rune-numeric?)
52+
53+(defdoc (rune-downcase r)
54+ «Return the lower case version of the rune.
55+
56+ The rune is returned unchanged if it has no case.»
57+ :doc-example
58+ «(rune-downcase #\ä)
59+ ; ↳ #\ä»
60+ :doc-example
61+ «(rune-downcase #\DŽ)
62+ ; ↳ #\dž»
63+ :doc-group string
64+ :doc-see rune-lower-case?
65+ :doc-see rune-upcase
66+ :doc-see rune-titlecase)
67+
68+(defdoc (rune-upcase r)
69+ «Return the higher case version of the rune.
70+
71+ The rune is returned unchanged if it has no case.»
72+ :doc-example
73+ «(rune-upcase #\ä)
74+ ; ↳ #\ä»
75+ :doc-example
76+ «(rune-upcase #\dž)
77+ ; ↳ #\DŽ»
78+ :doc-group string
79+ :doc-see rune-upper-case?
80+ :doc-see rune-downcase
81+ :doc-see rune-titlecase)
82+
83+(defdoc (rune-titlecase r)
84+ «Return the title case version of the rune.
85+
86+ For most runes the result is the same as with `rune-upcase`.»
87+ :doc-example
88+ «(rune-titlecase #\й)
89+ ; ↳ #\Й»
90+ :doc-example
91+ «(rune-titlecase #\dž)
92+ ; ↳ #\Dž»
93+ :doc-group string
94+ :doc-see rune-title-case?
95+ :doc-see rune-downcase
96+ :doc-see rune-upcase)
97+
98+(defdoc (rune-title-case? r)
99+ «Return `T` if the rune is a title case one, `NIL` otherwise.
100+
101+ For most runes the result is the same as with `rune-upper-case?`.»
102+ :doc-example
103+ «(rune-title-case? #\DŽ)
104+ ; ↳ NIL»
105+ :doc-example
106+ «(rune-title-case? #\Dž)
107+ ; ↳ T»
108+ :doc-group string
109+ :doc-see rune-titlecase
110+ :doc-see rune-lower-case?
111+ :doc-see rune-upper-case?)
112+
113+(defdoc (rune-upper-case? r)
114+ «Return `T` if the rune is an upper case one, `NIL` otherwise.»
115+ :doc-example
116+ «(rune-upper-case? #\DŽ)
117+ ; ↳ T»
118+ :doc-example
119+ «(rune-upper-case? #\Dž)
120+ ; ↳ NIL»
121+ :doc-group string
122+ :doc-see rune-upcase
123+ :doc-see rune-lower-case?
124+ :doc-see rune-title-case?)
125+
126+(defdoc (rune-lower-case? r)
127+ «Return `T` if the rune is a lower case one, `NIL` otherwise.»
128+ :doc-example
129+ «(rune-lower-case? #\dž)
130+ ; ↳ T»
131+ :doc-example
132+ «(rune-lower-case? #\Dž)
133+ ; ↳ NIL»
134+ :doc-group string
135+ :doc-see rune-downcase
136+ :doc-see rune-upper-case?
137+ :doc-see rune-title-case?)
138+
139+(defdoc (str . terms)
140+ «Return concatenation of terms formatted as strings.
141+
142+ This is equivalent to `(princ terms…)`, except the string is
143+ _returned_, rather than printed.»
144+ :doc-example
145+ «(str "a" 'b 1 #(0))
146+ ; ↳ "ab1#(0)"»
147+ :doc-group string)
148+
149+(defdoc (str-width s)
150+ «Return the number of columns needed to represent a string or a rune.
151+
152+ If a non-printable control rune is encountered, the result is `NIL`,
153+ else it is a non-negative integer. Rune `#\null` is considered of width zero.»
154+ :doc-example
155+ «(str-width #\й)
156+ ; ↳ 1»
157+ :doc-example
158+ «(str-width "⌛!")
159+ ; ↳ 3»
160+ :doc-example
161+ «(str-width "nope\n")
162+ ; ↳ NIL»
163+ :doc-group string)
164+
165+(defdoc (str-rune s n)
166+ «Return the nth rune of the string.
167+
168+ Throws an exception if the index `n` is out of bounds.»
169+ :doc-example
170+ «(str-rune "йцукен" 3)
171+ ; ↳ #\к»
172+ :doc-group string
173+ :doc-see str-sub)
174+
175+(defdoc (str-sub s start (end NIL))
176+ «Return the portion of the string within the specified bounds.
177+
178+ The `start` and `end` index by rune. Specifying any index out of bounds
179+ of the string will result in an exception thrown.
180+
181+ If `end` isn't specified the portion is assumed to begin at `start`
182+ until the end of the original string.»
183+ :doc-example
184+ «(str-sub "hello" 2)
185+ ; ↳ "llo"»
186+ :doc-example
187+ «(str-sub "hello" 3 3)
188+ ; ↳ ""»
189+ :doc-example
190+ «(str-sub "hello" 2 4)
191+ ; ↳ "ll"»
192+ :doc-group string
193+ :doc-see str-rune)
194+
195+(defdoc (str-utf8? s)
196+ «Return `T` if `s` is a valid UTF-8 string, `NIL` otherwise.»
197+ :doc-example
198+ «(str-utf8? "привет")
199+ ; ↳ T»
200+ :doc-example
201+ «(str-utf8? "при\xffвет")
202+ ; ↳ NIL»
203+ :doc-group string
204+ :doc-see str?)
205+
206+(defdoc (str->num s (:base NIL))
207+ «Return the number using the radix `base` in the string `s`.
208+
209+ Returns `NIL` if the number could not be parsed. Any number of leading
210+ and/or trailing whitespace runes is allowed and those will be ignored.»
211+ :doc-example
212+ «(str->num "1.2")
213+ ; ↳ 1.2»
214+ :doc-example
215+ «(str->num "#x123")
216+ ; ↳ 291»
217+ :doc-example
218+ «(str->num "ffff" :base 16)
219+ ; ↳ 65535»
220+ :doc-example
221+ «(str->num "777" :base 8)
222+ ; ↳ 511»
223+ :doc-group string
224+ :doc-see num->str)
225+
226+(defdoc (str-split str (sep " \n\t\v\f") (:trim NIL))
227+ «Return a list of substrings of `str` by splitting at any character in
228+ the string `sep`. The splitting characters are removed.
229+
230+ By default the string is split on space, line feed (newline),
231+ horizontal and vertical tab, and form feed.
232+
233+ Trim removes empty strings from the list.»
234+ :doc-example
235+ «(str-split "hello world")
236+ ; ↳ ("hello" "world")»
237+ :doc-example
238+ «(str-split "multiple spaces ")
239+ ; ↳ ("multiple" "" "" "spaces" "")»
240+ :doc-example
241+ «(str-split "multiple spaces " :trim T)
242+ ; ↳ ("multiple" "spaces")»
243+ :doc-example
244+ «(str-split "too many vowels" "aeiou")
245+ ; ↳ ("t" "" " m" "ny v" "w" "ls")»
246+ :doc-group string)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t