@@ -4,9 +4,9 @@ Module: str
4
4
String manipulation
5
5
6
6
Strings are a packed UTF-8 representation of text, stored as null terminated
7
- buffers of u8 bytes. Strings should be considered by character ,
8
- for correctness, but some UTF-8 unsafe functions are also provided .
9
- For some heavy-duty uses, we recommend trying std::rope.
7
+ buffers of u8 bytes. Strings should be indexed in bytes, for efficiency ,
8
+ but UTF-8 unsafe operations should be avoided .
9
+ For some heavy-duty uses, try std::rope.
10
10
*/
11
11
12
12
import option:: { some, none} ;
@@ -434,6 +434,7 @@ Failure:
434
434
- If end is greater than the character length of the string
435
435
436
436
FIXME: make faster by avoiding char conversion
437
+ FIXME: delete?
437
438
*/
438
439
fn slice_chars ( s : str , begin : uint , end : uint ) -> str {
439
440
from_chars ( vec:: slice ( chars ( s) , begin, end) )
@@ -498,7 +499,7 @@ Splits a string into a vector of the substrings separated by a given string
498
499
Note that this has recently been changed. For example:
499
500
> assert ["", "XXX", "YYY", ""] == split_str(".XXX.YYY.", ".")
500
501
501
- FIXME: Boyer-Moore variation
502
+ FIXME: Boyer-Moore should be faster
502
503
*/
503
504
fn split_str ( ss : str , sep : str ) -> [ str ] unsafe {
504
505
// unsafe is justified: we are splitting
@@ -670,7 +671,7 @@ fn to_upper(s: str) -> str {
670
671
map ( s, char:: to_upper)
671
672
}
672
673
673
- // FIXME: This is super-inefficient
674
+ // FIXME: This is super-inefficient: stop the extra slicing copies
674
675
/*
675
676
Function: replace
676
677
@@ -894,6 +895,7 @@ fn index_from(ss: str, cc: char, start: uint, end: uint) -> option<uint> {
894
895
//
895
896
// Returns the char index of the first matching char
896
897
// (as option some/none)
898
+ // FIXME: delete?
897
899
fn index_chars ( ss : str , cc : char ) -> option < uint > {
898
900
let bii = 0 u;
899
901
let cii = 0 u;
@@ -938,6 +940,7 @@ fn rindex(ss: str, cc: char) -> option<uint> {
938
940
//
939
941
// Returns the char index of the first matching char
940
942
// (as option some/none)
943
+ // FIXME: delete?
941
944
fn rindex_chars ( ss : str , cc : char ) -> option < uint > {
942
945
let bii = len ( ss) ;
943
946
let cii = len_chars ( ss) ;
@@ -998,6 +1001,7 @@ fn find_from(haystack: str, needle: str, start: uint, end:uint)
998
1001
//
999
1002
// Find the char position of the first instance of one string
1000
1003
// within another, or return option::none
1004
+ // FIXME: delete?
1001
1005
fn find_chars ( haystack : str , needle : str ) -> option < uint > {
1002
1006
alt find ( haystack, needle) {
1003
1007
none { ret none; }
@@ -1065,8 +1069,8 @@ haystack - The string to look in
1065
1069
needle - The string to look for
1066
1070
*/
1067
1071
fn ends_with ( haystack : str , needle : str ) -> bool {
1068
- let haystack_len: uint = len_chars ( haystack) ;
1069
- let needle_len: uint = len_chars ( needle) ;
1072
+ let haystack_len: uint = len ( haystack) ;
1073
+ let needle_len: uint = len ( needle) ;
1070
1074
ret if needle_len == 0 u {
1071
1075
true
1072
1076
} else if needle_len > haystack_len {
@@ -1129,6 +1133,7 @@ pure fn len(s: str) -> uint unsafe {
1129
1133
}
1130
1134
}
1131
1135
1136
+ // FIXME: delete?
1132
1137
fn len_chars ( s : str ) -> uint {
1133
1138
substr_len_chars ( s, 0 u, len ( s) )
1134
1139
}
@@ -1177,6 +1182,8 @@ Safety note:
1177
1182
- This function does not check whether the substring is valid.
1178
1183
- This function fails if `byte_offset` or `byte_len` do not
1179
1184
represent valid positions inside `s`
1185
+
1186
+ FIXME: delete?
1180
1187
*/
1181
1188
fn substr_len_chars ( s : str , byte_start : uint , byte_len : uint ) -> uint {
1182
1189
let i = byte_start;
@@ -1451,12 +1458,13 @@ fn reserve(&ss: str, nn: uint) {
1451
1458
// These functions may create invalid UTF-8 strings and eat your baby.
1452
1459
mod unsafe {
1453
1460
export
1461
+ // FIXME: stop exporting several of these
1454
1462
from_bytes,
1455
1463
from_byte,
1456
- slice_bytes, // FIXME: stop exporting
1457
- slice_bytes_safe_range, // FIXME: stop exporting
1464
+ slice_bytes,
1465
+ slice_bytes_safe_range,
1458
1466
push_byte,
1459
- push_bytes, // note: wasn't exported
1467
+ push_bytes,
1460
1468
pop_byte,
1461
1469
shift_byte;
1462
1470
@@ -1489,7 +1497,6 @@ mod unsafe {
1489
1497
- If end is greater than the length of the string.
1490
1498
*/
1491
1499
unsafe fn slice_bytes ( s : str , begin : uint , end : uint ) -> str unsafe {
1492
- // FIXME: Typestate precondition
1493
1500
assert ( begin <= end) ;
1494
1501
assert ( end <= len ( s) ) ;
1495
1502
0 commit comments