diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-26 15:28:12 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-26 15:28:12 +0800 |
commit | a3d39af759612133912748d9cdcfba62bd8f320d (patch) | |
tree | 0208603033281c31d59e13c65e52500be1a0c37e | |
parent | db0ce5e6ff17128fb5e160cec1019fba114411bc (diff) | |
download | mrust-a3d39af759612133912748d9cdcfba62bd8f320d.tar.gz |
Expand format_args! - Positional argument parse
-rw-r--r-- | src/expand/format_args.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/expand/format_args.cpp b/src/expand/format_args.cpp index 3b967016..5d9940bc 100644 --- a/src/expand/format_args.cpp +++ b/src/expand/format_args.cpp @@ -156,10 +156,11 @@ namespace { continue ; } - const char* s2 = s; - while(*s2 && *s2 != '}') - s2 ++; - auto fmt_frag_str = string_view { s, s2 }; + // Debugging: A view of the formatting fragment + //const char* s2 = s; + //while(*s2 && *s2 != '}') + // s2 ++; + //auto fmt_frag_str = string_view { s, s2 }; unsigned int index = ~0u; const char* trait_name; @@ -169,7 +170,15 @@ namespace { if( *s != ':' && *s != '}' ) { // Parse either an integer or an identifer if( isdigit(*s) ) { - TODO(sp, "Parse positional formatting fragment at \"" << fmt_frag_str << "\""); + unsigned int arg_idx = 0; + do { + arg_idx *= 10; + arg_idx += *s - '0'; + s ++; + } while(isdigit(*s)); + if( arg_idx >= n_free ) + ERROR(sp, E0000, "Positional argument " << arg_idx << " out of range"); + index = arg_idx; } else { const char* start = s; |