[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [6341] Refactor for clarity in a fencepost zone
From: |
Greg Chicares |
Subject: |
[lmi-commits] [6341] Refactor for clarity in a fencepost zone |
Date: |
Sat, 10 Oct 2015 00:37:38 +0000 |
Revision: 6341
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6341
Author: chicares
Date: 2015-10-10 00:37:37 +0000 (Sat, 10 Oct 2015)
Log Message:
-----------
Refactor for clarity in a fencepost zone
Modified Paths:
--------------
lmi/trunk/miscellany.cpp
lmi/trunk/miscellany.hpp
lmi/trunk/wx_table_generator.cpp
Modified: lmi/trunk/miscellany.cpp
===================================================================
--- lmi/trunk/miscellany.cpp 2015-10-09 03:22:23 UTC (rev 6340)
+++ lmi/trunk/miscellany.cpp 2015-10-10 00:37:37 UTC (rev 6341)
@@ -70,20 +70,11 @@
return streams_are_identical(ifs0, ifs1);
}
-/// Return the number of lines in a possibly multiline string.
-///
-/// Actually returns one plus the number of newlines in the string.
-/// If, say, a trailing '\n' is found, the count is one greater than
-/// the number of lines--which might be useful, e.g., for adding an
-/// extra blank line to a column header.
-
-std::size_t count_lines(std::string const& s)
+std::size_t count_newlines(std::string const& s)
{
- return 1u + std::count(s.begin(), s.end(), '\n');
+ return std::count(s.begin(), s.end(), '\n');
}
-/// Split a string into lines separated by newline characters.
-
std::vector<std::string> split_into_lines(std::string const& s)
{
// BOOST !! Unfortunately boost::split() can't be easily used with the
@@ -107,7 +98,10 @@
line += *i;
}
}
- LMI_ASSERT(lines.size() == count_lines(s));
+ // Assume that there is no newline at the end (or beginning) of
+ // the string: i.e., // that all newline delimiters are
+ // internal--hence "1u + ".
+ LMI_ASSERT(lines.size() == 1u + count_newlines(s));
return lines;
}
Modified: lmi/trunk/miscellany.hpp
===================================================================
--- lmi/trunk/miscellany.hpp 2015-10-09 03:22:23 UTC (rev 6340)
+++ lmi/trunk/miscellany.hpp 2015-10-10 00:37:37 UTC (rev 6341)
@@ -86,11 +86,11 @@
template<typename T> bool operator< (minmax<T> m, T t) {return m.maximum() <
t;}
template<typename T> bool operator<=(minmax<T> m, T t) {return m.maximum() <=
t;}
-/// Return the number of lines in a possibly multiline string.
+/// Return the number of newline characters in a string.
-std::size_t LMI_SO count_lines(std::string const&);
+std::size_t LMI_SO count_newlines(std::string const&);
-/// Split a string into lines separated by newline characters.
+/// Split an internally-newline-delimited string into lines.
std::vector<std::string> LMI_SO split_into_lines(std::string const&);
Modified: lmi/trunk/wx_table_generator.cpp
===================================================================
--- lmi/trunk/wx_table_generator.cpp 2015-10-09 03:22:23 UTC (rev 6340)
+++ lmi/trunk/wx_table_generator.cpp 2015-10-10 00:37:37 UTC (rev 6341)
@@ -30,7 +30,7 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
-#include "miscellany.hpp" // count_lines(), split_into_lines()
+#include "miscellany.hpp" // count_newlines(), split_into_lines()
namespace
{
@@ -80,8 +80,10 @@
int width = widest_text[0] ? dc_.GetTextExtent(widest_text).x : 0;
// Keep track of the maximal number of lines in a header as this determines
- // the number of lines used for all of them.
- increase_to_if_smaller(max_header_lines_, count_lines(header));
+ // the number of lines used for all of them. This is one plus the number of
+ // newlines in the anticipated case where there is no newline character at
+ // the beginning or end of the header's string representation.
+ increase_to_if_smaller(max_header_lines_, 1u + count_newlines(header));
// Also increase the column width to be sufficiently wide to fit
// this header line if it has fixed width.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [6341] Refactor for clarity in a fencepost zone,
Greg Chicares <=