From b8cec4a2571596692c1e0b27cc3953ecff712178 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Jun 2010 09:25:29 +0200 Subject: Add support for single quotes in option files --- cli/options.cli | 8 ++++---- cli/options.cxx | 5 +++-- cli/runtime-source.cxx | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'cli') diff --git a/cli/options.cli b/cli/options.cli index 58f9565..ffa92df 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -214,10 +214,10 @@ class options "Read additional options from with each option appearing on a separate line optionally followed by space and an option value. Empty lines and lines starting with \cb{#} are ignored. Option values can - be enclosed in double quotes (\cb{\"\"}) to preserve leading and - trailing whitespaces as well as to specify empty values. If the value - itself contains trailing or leading double quote, enclose it with an - extra pair of double quotes, for example \cb{\"\"x\"\"}. Non-leading + be enclosed in double (\cb{\"}) or single (\cb{'}) quotes to preserve + leading and trailing whitespaces as well as to specify empty values. + If the value itself contains trailing or leading double quote, enclose + it with an extra pair of quotes, for example \cb{'\"x\"'}. Non-leading and non-trailing quotes are interpreted as being part of the option value. diff --git a/cli/options.cxx b/cli/options.cxx index 3f3c1b9..1c46fd4 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -351,10 +351,11 @@ namespace cli // If the string is wrapped in quotes, remove them. // n = s2.size (); + char cf (s2[0]), cl (s2[n - 1]); - if (s2[0] == '"' || s2[n - 1] == '"') + if (cf == '"' || cf == '\'' || cl == '"' || cl == '\'') { - if (n == 1 || s2[0] != s2[n - 1]) + if (n == 1 || cf != cl) throw unmatched_quote (s2); s2 = string (s2, 1, n - 2); diff --git a/cli/runtime-source.cxx b/cli/runtime-source.cxx index 348d7b7..e2008ad 100644 --- a/cli/runtime-source.cxx +++ b/cli/runtime-source.cxx @@ -392,10 +392,11 @@ generate_runtime_source (context& ctx) << "// If the string is wrapped in quotes, remove them." << endl << "//" << endl << "n = s2.size ();" + << "char cf (s2[0]), cl (s2[n - 1]);" << endl - << "if (s2[0] == '\"' || s2[n - 1] == '\"')" + << "if (cf == '\"' || cf == '\\'' || cl == '\"' || cl == '\\'')" << "{" - << "if (n == 1 || s2[0] != s2[n - 1])" << endl + << "if (n == 1 || cf != cl)" << endl << "throw unmatched_quote (s2);" << endl << "s2 = string (s2, 1, n - 2);" -- cgit v1.1