]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Fix wrapping long words on indented lines
authorPetr Machata <pmachata@redhat.com>
Fri, 1 Oct 2010 11:51:08 +0000 (13:51 +0200)
committerPetr Machata <pmachata@redhat.com>
Fri, 1 Oct 2010 11:51:08 +0000 (13:51 +0200)
dwarflint/wrap.cc
dwarflint/wrap.hh

index 736091de927920a22262160f73b73b7acf31f95f..37f47f6eda0421a4b539b0d6c98aaa68f912ee49 100644 (file)
@@ -98,8 +98,9 @@ wrap_str::wrap_str (std::string const &str, unsigned width)
 
       // While skipping back, we might end at the very beginning.  If
       // that's the case, we have a word that doesn't fit user limit.
-      // Include it whole anyway.
-      if (space == last)
+      // Include it whole anyway.  For newline, account for
+      // freshly-introduced indent.
+      if (space <= last + (newline ? indent : 0))
        {
          space = pos;
          while (space < str.size () && !isspace (str[space]))
@@ -131,10 +132,16 @@ wrap_str::join () const
 {
   std::string ret;
   for (const_iterator it = begin (); it != end (); ++it)
-    ret += it->build (_m_image) + "\n";
+    ret += build (it) + "\n";
   return ret;
 }
 
+std::string
+wrap_str::build (wrap_str::const_iterator it) const
+{
+  return it->build (_m_image);
+}
+
 namespace
 {
   class tests
@@ -164,6 +171,9 @@ namespace
       assert (wrap ("\n\n", 5) == "\n\n");
       assert (wrap ("\n\n", 0) == "\n\n");
       assert (wrap ("ab\ncd ef gh ij", 5) == "ab\ncd ef\ngh ij\n");
+      assert (wrap (" - abcd abbb accc", 3) == " - abcd\n   abbb\n   accc\n");
+      assert (wrap (" -abcd abbb accc", 3) == " -abcd\n  abbb\n  accc\n");
+      assert (wrap ("  abcd abbb accc", 3) == "  abcd\n  abbb\n  accc\n");
     }
   } _;
 }
index 50826b668ce7e14db596e893a9a5c31335192cf5..1c009f526cc06b7faf7425a5f23c59441d60bb2b 100644 (file)
@@ -58,6 +58,7 @@ public:
   wrap_str (std::string const &str, unsigned width);
 
   std::string join () const;
+  std::string build (const_iterator it) const;
 };
 
 #endif//DWARFLINT_WRAP_HH