summaryrefslogtreecommitdiff
path: root/format.cc
diff options
context:
space:
mode:
Diffstat (limited to 'format.cc')
-rw-r--r--format.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/format.cc b/format.cc
index e83d7e7b..dda4b7c6 100644
--- a/format.cc
+++ b/format.cc
@@ -130,8 +130,14 @@ element_t * format_t::parse_elements(const std::string& fmt)
case '(': {
++p;
const char * b = p;
- while (*p && *p != ')')
+ int depth = 1;
+ while (*p) {
+ if (*p == ')' && --depth == 0)
+ break;
+ else if (*p == '(')
+ ++depth;
p++;
+ }
if (*p != ')')
throw format_error("Missing ')'");
@@ -149,8 +155,14 @@ element_t * format_t::parse_elements(const std::string& fmt)
case '[': {
++p;
const char * b = p;
- while (*p && *p != ']')
+ int depth = 1;
+ while (*p) {
+ if (*p == ']' && --depth == 0)
+ break;
+ else if (*p == '[')
+ ++depth;
p++;
+ }
if (*p != ']')
throw format_error("Missing ']'");