From e399236be3482e945afaa12ab6acc05a9eb1bb77 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Sep 2013 11:23:47 +0200 Subject: Improve C++ indenter by handling '},' sequence --- cutl/compiler/cxx-indenter.txx | 43 ++++++++++++++++++++++++++++++++++ tests/compiler/cxx-indenter/driver.cxx | 5 ++++ tests/compiler/cxx-indenter/output.std | 15 ++++++++++++ 3 files changed, 63 insertions(+) diff --git a/cutl/compiler/cxx-indenter.txx b/cutl/compiler/cxx-indenter.txx index 67f9bf0..c3930b3 100644 --- a/cutl/compiler/cxx-indenter.txx +++ b/cutl/compiler/cxx-indenter.txx @@ -376,6 +376,49 @@ namespace cutl break; } + case ',': + { + if (construct_ == con_other) + { + // Handling '},' case. + // + + bool brace (false); + + if (hold_.size () > 1 && hold_.back () == '\n') + { + bool pop_nl (false); + + for (typename hold::reverse_iterator + i (hold_.rbegin ()), e (hold_.rend ()); + i != e; ++i) + { + if (*i != '\n') + { + if (*i == '}') + brace = pop_nl = true; + + break; + } + } + + if (pop_nl) + while (hold_.back () == '\n') + hold_.pop_back (); + } + + output_indentation (); + write (c); + position_++; + + if (brace) + hold_.push_back ('\n'); + } + else + defaulting = true; + + break; + } case ' ': { if (construct_ == con_other) diff --git a/tests/compiler/cxx-indenter/driver.cxx b/tests/compiler/cxx-indenter/driver.cxx index 511b6d4..665c6ab 100644 --- a/tests/compiler/cxx-indenter/driver.cxx +++ b/tests/compiler/cxx-indenter/driver.cxx @@ -115,6 +115,11 @@ main () << "\"'name')\");" << "}"; + os << "namespace N" + << "{" + << "static int i[] = {{0,\n0},{1,\n1}};" + << "}"; + /* @@ TODO: still misindents (if-else association problem) diff --git a/tests/compiler/cxx-indenter/output.std b/tests/compiler/cxx-indenter/output.std index 0e59a26..79e74f4 100644 --- a/tests/compiler/cxx-indenter/output.std +++ b/tests/compiler/cxx-indenter/output.std @@ -86,3 +86,18 @@ while (false); "'name')"); } +namespace N +{ + static int i[] = + { + { + 0, + 0 + }, + { + 1, + 1 + } + }; +} + -- cgit v1.1