diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-11-22 18:06:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-11-22 18:06:34 +0200 |
commit | 1d20a08f83ac65200f647bd001eaceac876ec355 (patch) | |
tree | 2f9601823059b875e2805e37ca344cd1cb47067c /cutl/compiler | |
parent | 69f98bc8e5269916ecdb6225e8bdb0b0e0fcb003 (diff) |
Keep track of backslash escapings when testing for " and '
Diffstat (limited to 'cutl/compiler')
-rw-r--r-- | cutl/compiler/cxx-indenter.hxx | 1 | ||||
-rw-r--r-- | cutl/compiler/cxx-indenter.txx | 58 |
2 files changed, 45 insertions, 14 deletions
diff --git a/cutl/compiler/cxx-indenter.hxx b/cutl/compiler/cxx-indenter.hxx index 0e5e2a1..2e76e0e 100644 --- a/cutl/compiler/cxx-indenter.hxx +++ b/cutl/compiler/cxx-indenter.hxx @@ -8,6 +8,7 @@ #include <set> #include <stack> +#include <deque> #include <string> #include <cstddef> // std::size_t diff --git a/cutl/compiler/cxx-indenter.txx b/cutl/compiler/cxx-indenter.txx index 73e3ceb..4c2018d 100644 --- a/cutl/compiler/cxx-indenter.txx +++ b/cutl/compiler/cxx-indenter.txx @@ -66,15 +66,30 @@ namespace cutl if (construct_ != con_pp_dir && construct_ != con_c_com && construct_ != con_cxx_com && - construct_ != con_char_lit && - (hold_.empty () || hold_.back () != '\\')) + construct_ != con_char_lit) { - // Not an escape sequence. + // We might be in an escape sequence. // - if (construct_ == con_string_lit) - new_con = con_other; - else - construct_ = new_con = con_string_lit; + bool es (!hold_.empty () && hold_.back () == '\\'); + + if (es) + { + // Scan the hold sequence backwards to figure out if this + // backslash is part of this escape sequence or a preceding + // one. + // + for (typename hold::reverse_iterator i (hold_.rbegin () + 1), + e (hold_.rend ()); i != e && *i == '\\'; ++i) + es = !es; + } + + if (!es) + { + if (construct_ == con_string_lit) + new_con = con_other; + else + construct_ = new_con = con_string_lit; + } } break; @@ -84,15 +99,30 @@ namespace cutl if (construct_ != con_pp_dir && construct_ != con_c_com && construct_ != con_cxx_com && - construct_ != con_string_lit && - (hold_.empty () || hold_.back () != '\\')) + construct_ != con_string_lit) { - // Not an escape sequence. + // We might be in an escape sequence. // - if (construct_ == con_char_lit) - new_con = con_other; - else - construct_ = new_con = con_char_lit; + bool es (!hold_.empty () && hold_.back () == '\\'); + + if (es) + { + // Scan the hold sequence backwards to figure out if this + // backslash is part of this escape sequence or a preceding + // one. + // + for (typename hold::reverse_iterator i (hold_.rbegin () + 1), + e (hold_.rend ()); i != e && *i == '\\'; ++i) + es = !es; + } + + if (!es) + { + if (construct_ == con_char_lit) + new_con = con_other; + else + construct_ = new_con = con_char_lit; + } } break; |