aboutsummaryrefslogtreecommitdiff
path: root/cutl
diff options
context:
space:
mode:
Diffstat (limited to 'cutl')
-rw-r--r--cutl/compiler/cxx-indenter.hxx1
-rw-r--r--cutl/compiler/cxx-indenter.txx58
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;