aboutsummaryrefslogtreecommitdiff
path: root/cutl/compiler/cxx-indenter.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-11-22 18:06:34 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-11-22 18:06:34 +0200
commit1d20a08f83ac65200f647bd001eaceac876ec355 (patch)
tree2f9601823059b875e2805e37ca344cd1cb47067c /cutl/compiler/cxx-indenter.txx
parent69f98bc8e5269916ecdb6225e8bdb0b0e0fcb003 (diff)
Keep track of backslash escapings when testing for " and '
Diffstat (limited to 'cutl/compiler/cxx-indenter.txx')
-rw-r--r--cutl/compiler/cxx-indenter.txx58
1 files changed, 44 insertions, 14 deletions
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;