|
1 |
| -#[doc(hidden)]; |
| 1 | +//! Support for fmt! expressions. |
| 2 | +//! |
| 3 | +//! The syntax is close to that of Posix format strings: |
| 4 | +//! |
| 5 | +//! ~~~~~~ |
| 6 | +//! Format := '%' Parameter? Flag* Width? Precision? Type |
| 7 | +//! Parameter := [0-9]+ '$' |
| 8 | +//! Flag := [ 0#+-] |
| 9 | +//! Width := Parameter | [0-9]+ |
| 10 | +//! Precision := '.' [0-9]+ |
| 11 | +//! Type := [bcdfiostuxX?] |
| 12 | +//! ~~~~~~ |
| 13 | +//! |
| 14 | +//! * Parameter is the 1-based argument to apply the format to. Currently not implemented. |
| 15 | +//! * Flag 0 causes leading zeros to be used for padding when converting numbers. |
| 16 | +//! * Flag # causes the conversion to be done in an *alternative* manner. Currently not implemented. |
| 17 | +//! * Flag + causes signed numbers to always be prepended with a sign character. |
| 18 | +//! * Flag - left justifies the result |
| 19 | +//! * Width specifies the minimum field width of the result. By default leading spaces are added. |
| 20 | +//! * Precision specifies the minimum number of digits for integral types and the minimum number |
| 21 | +//! of decimal places for float. |
| 22 | +//! |
| 23 | +//! The types currently supported are: |
| 24 | +//! |
| 25 | +//! * b - bool |
| 26 | +//! * c - char |
| 27 | +//! * d - int |
| 28 | +//! * f - float |
| 29 | +//! * i - int (same as d) |
| 30 | +//! * o - uint as octal |
| 31 | +//! * t - uint as binary |
| 32 | +//! * u - uint |
| 33 | +//! * x - uint as lower-case hexadecimal |
| 34 | +//! * X - uint as upper-case hexadecimal |
| 35 | +//! * s - str (any flavor) |
| 36 | +//! * ? - arbitrary type (does not use the to_str trait) |
| 37 | +
|
2 | 38 | // NB: transitionary, de-mode-ing.
|
3 | 39 | #[forbid(deprecated_mode)];
|
4 | 40 | #[forbid(deprecated_pattern)];
|
@@ -44,6 +80,7 @@ use option::{Some, None};
|
44 | 80 | */
|
45 | 81 |
|
46 | 82 | // Functions used by the fmt extension at compile time
|
| 83 | +#[doc(hidden)] |
47 | 84 | pub mod ct {
|
48 | 85 | pub enum Signedness { Signed, Unsigned, }
|
49 | 86 | pub enum Caseness { CaseUpper, CaseLower, }
|
@@ -277,6 +314,7 @@ pub mod ct {
|
277 | 314 | // decisions made a runtime. If it proves worthwhile then some of these
|
278 | 315 | // conditions can be evaluated at compile-time. For now though it's cleaner to
|
279 | 316 | // implement it 0this way, I think.
|
| 317 | +#[doc(hidden)] |
280 | 318 | pub mod rt {
|
281 | 319 | pub const flag_none : u32 = 0u32;
|
282 | 320 | pub const flag_left_justify : u32 = 0b00000000000001u32;
|
@@ -464,6 +502,7 @@ pub mod rt {
|
464 | 502 | }
|
465 | 503 | }
|
466 | 504 |
|
| 505 | +// Bulk of the tests are in src/test/run-pass/syntax-extension-fmt.rs |
467 | 506 | #[cfg(test)]
|
468 | 507 | mod test {
|
469 | 508 | #[test]
|
|
0 commit comments