@@ -139,9 +139,23 @@ fn byte_len(s: str) -> uint unsafe {
139
139
}
140
140
141
141
/*
142
- Function byte_len_range
142
+ Function: byte_len_range
143
143
144
144
As byte_len but for a substring
145
+
146
+ Parameters:
147
+ s - A string
148
+ byte_offset - The byte offset at which to start in the string
149
+ char_len - The number of chars (not bytes!) in the range
150
+
151
+ Returns:
152
+ The number of bytes in the substring starting at `byte_offset` and
153
+ containing `char_len` chars.
154
+
155
+ Safety note:
156
+
157
+ This function fails if `byte_offset` or `char_len` do not represent
158
+ valid positions in `s`
145
159
*/
146
160
fn byte_len_range ( s : str , byte_offset : uint , char_len : uint ) -> uint {
147
161
let i = byte_offset;
@@ -334,19 +348,46 @@ fn iter_chars(s: str, it: block(char)) {
334
348
}
335
349
336
350
/*
337
- Function: loop_chars
351
+ Function: loop_chars
338
352
339
- As `iter_chars` but may be interrupted
340
- */
353
+ Loop through a string, char by char
354
+
355
+ Parameters:
356
+ s - A string to traverse. It may be empty.
357
+ it - A block to execute with each consecutive character of `s`.
358
+ Return `true` to continue, `false` to stop.
359
+
360
+ Returns:
361
+
362
+ `true` If execution proceeded correctly, `false` if it was interrupted,
363
+ that is if `it` returned `false` at any point.
364
+ */
341
365
fn loop_chars ( s : str , it : block ( char ) -> bool ) -> bool {
342
366
ret loop_chars_sub ( s, 0 u, byte_len ( s) , it) ;
343
367
}
344
368
345
369
/*
346
- Function: loop_chars_sub
370
+ Function: loop_chars
347
371
348
- As `loop_chars` but on a substring
349
- */
372
+ Loop through a substring, char by char
373
+
374
+ Parameters:
375
+ s - A string to traverse. It may be empty.
376
+ byte_offset - The byte offset at which to start in the string.
377
+ byte_len - The number of bytes to traverse in the string
378
+ it - A block to execute with each consecutive character of `s`.
379
+ Return `true` to continue, `false` to stop.
380
+
381
+ Returns:
382
+
383
+ `true` If execution proceeded correctly, `false` if it was interrupted,
384
+ that is if `it` returned `false` at any point.
385
+
386
+ Safety note:
387
+ - This function does not check whether the substring is valid.
388
+ - This function fails if `byte_offset` or `byte_len` do not
389
+ represent valid positions inside `s`
390
+ */
350
391
fn loop_chars_sub ( s : str , byte_offset : uint , byte_len : uint ,
351
392
it : block ( char ) -> bool ) -> bool {
352
393
let i = byte_offset;
@@ -373,6 +414,20 @@ fn char_len(s: str) -> uint {
373
414
Function: char_len_range
374
415
375
416
As char_len but for a slice of a string
417
+
418
+ Parameters:
419
+ s - A valid string
420
+ byte_start - The position inside `s` where to start counting in bytes.
421
+ byte_len - The number of bytes of `s` to take into account.
422
+
423
+ Returns:
424
+ The number of Unicode characters in `s` in
425
+ segment [byte_start, byte_start+len( .
426
+
427
+ Safety note:
428
+ - This function does not check whether the substring is valid.
429
+ - This function fails if `byte_offset` or `byte_len` do not
430
+ represent valid positions inside `s`
376
431
*/
377
432
fn char_len_range ( s : str , byte_start : uint , byte_len : uint ) -> uint {
378
433
let i = byte_start;
0 commit comments