From 1d20a08f83ac65200f647bd001eaceac876ec355 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 22 Nov 2009 18:06:34 +0200 Subject: Keep track of backslash escapings when testing for " and ' --- cutl/compiler/cxx-indenter.hxx | 1 + cutl/compiler/cxx-indenter.txx | 58 ++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 14 deletions(-) (limited to 'cutl') 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 #include +#include #include #include // 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; -- cgit v1.1