Skip to content

Commit e3aa71d

Browse files
committed
---
yaml --- r: 2101 b: refs/heads/master c: 99a697b h: refs/heads/master i: 2099: 064435a v: v3
1 parent 5ee9a54 commit e3aa71d

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5c0f4c1939b392e0bd0bcbce86fa83eb7a421992
2+
refs/heads/master: 99a697b56abba8e4ab94fc14b5b4769bee9702f0

trunk/src/comp/front/extfmt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
246246
case (ty_hex(_)) {
247247
ret make_conv_call(arg.span, "uint", cnv, arg);
248248
}
249+
case (ty_bits) {
250+
ret make_conv_call(arg.span, "uint", cnv, arg);
251+
}
249252
case (_) {
250253
log unsupported;
251254
fail;

trunk/src/lib/ExtFmt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ mod RT {
315315
case (ty_hex_lower) {
316316
ret _uint.to_str(u, 16u);
317317
}
318+
case (ty_hex_upper) {
319+
ret _str.to_upper(_uint.to_str(u, 16u));
320+
}
321+
case (ty_bits) {
322+
ret _uint.to_str(u, 2u);
323+
}
318324
}
319325
}
320326

trunk/src/lib/_str.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,24 @@ fn connect(vec[str] v, str sep) -> str {
470470
ret s;
471471
}
472472

473+
// FIXME: This only handles ASCII
474+
fn to_upper(str s) -> str {
475+
auto outstr = "";
476+
auto ascii_a = 'a' as u8;
477+
auto ascii_z = 'z' as u8;
478+
auto diff = 32u8;
479+
for (u8 byte in s) {
480+
auto next;
481+
if (ascii_a <= byte && byte <= ascii_z) {
482+
next = byte - diff;
483+
} else {
484+
next = byte;
485+
}
486+
push_byte(outstr, next);
487+
}
488+
ret outstr;
489+
}
490+
473491

474492
// Local Variables:
475493
// mode: rust;

trunk/src/test/run-pass/lib-str.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ fn test_connect() {
8989
t(vec("hi"), " ", "hi");
9090
}
9191

92+
fn test_to_upper() {
93+
// to_upper doesn't understand unicode yet,
94+
// but we need to at least preserve it
95+
auto unicode = "\u65e5\u672c";
96+
auto input = "abcDEF" + unicode + "xyz:.;";
97+
auto expected = "ABCDEF" + unicode + "XYZ:.;";
98+
auto actual = _str.to_upper(input);
99+
check (_str.eq(expected, actual));
100+
}
101+
92102

93103
fn main() {
94104
test_bytes_len();
@@ -98,4 +108,5 @@ fn main() {
98108
test_substr();
99109
test_concat();
100110
test_connect();
111+
test_to_upper();
101112
}

trunk/src/test/run-pass/syntax-extension-fmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ fn main() {
2323
test(#fmt("%b", false), "false");
2424
test(#fmt("%c", 'A'), "A");
2525
test(#fmt("%x", 0xff_u), "ff");
26+
test(#fmt("%X", 0x12ab_u), "12AB");
27+
test(#fmt("%t", 0b11010101_u), "11010101");
2628
}

0 commit comments

Comments
 (0)