Skip to content

Commit 15e3a18

Browse files
David Rajchenbach-Tellerbrson
David Rajchenbach-Teller
authored andcommitted
---
yaml --- r: 6149 b: refs/heads/master c: 1087f4b h: refs/heads/master i: 6147: c6bf174 v: v3
1 parent a8999b7 commit 15e3a18

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b17847b2323167b557b84b088f0c865724829c30
2+
refs/heads/master: 1087f4b7b0d82698aeed25399226e7784450174a

trunk/src/lib/str.rs

+62-7
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,23 @@ fn byte_len(s: str) -> uint unsafe {
139139
}
140140

141141
/*
142-
Function byte_len_range
142+
Function: byte_len_range
143143
144144
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`
145159
*/
146160
fn byte_len_range(s: str, byte_offset: uint, char_len: uint) -> uint {
147161
let i = byte_offset;
@@ -334,19 +348,46 @@ fn iter_chars(s: str, it: block(char)) {
334348
}
335349

336350
/*
337-
Function: loop_chars
351+
Function: loop_chars
338352
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+
*/
341365
fn loop_chars(s: str, it: block(char) -> bool) -> bool{
342366
ret loop_chars_sub(s, 0u, byte_len(s), it);
343367
}
344368

345369
/*
346-
Function: loop_chars_sub
370+
Function: loop_chars
347371
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+
*/
350391
fn loop_chars_sub(s: str, byte_offset: uint, byte_len: uint,
351392
it: block(char) -> bool) -> bool {
352393
let i = byte_offset;
@@ -373,6 +414,20 @@ fn char_len(s: str) -> uint {
373414
Function: char_len_range
374415
375416
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`
376431
*/
377432
fn char_len_range(s: str, byte_start: uint, byte_len: uint) -> uint {
378433
let i = byte_start;

0 commit comments

Comments
 (0)