diff --git a/AUTHORS b/AUTHORS index bca6efe21..82bba6ef4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -63,6 +63,7 @@ The following submitted code, packages or analysis, and deserve special thanks: Barton Meeks Martin Klepsch Wim Schuermann + Ralph Bean Thanks to the following, who submitted detailed bug reports and excellent suggestions: diff --git a/DEVELOPER b/DEVELOPER index 4f4a4d15a..d71ed5b98 100644 --- a/DEVELOPER +++ b/DEVELOPER @@ -13,19 +13,6 @@ New Code Needs - text.cpp extractLines needs to be rewritten in a UTF8-aware and color-code sensitive manner. - - Need a function to accept a list of projects, and return an indented list - that reflects the hierarchy. This will likely go into the new 'projects' - command. Something like: - Input - "one" - "one.two" - "one.two.three" - "one.four" - "two" - Output - "one" - " one.two" - " one.two.three" - " one.four" - "two" - Need export_sql.yy script. Any language. This would have value as an example, or template script serving as a starting-point for anyone who needed this format. @@ -145,6 +132,7 @@ Current Codebase Condition --- +2011-12-23 Removed entry for tree-indentation function. 2011-10-16 Removed obsolete entries, added test suite description. 2011-10-16 Removed obsolete entries. 2011-08-21 Small changes, new work listed. diff --git a/src/util.cpp b/src/util.cpp index 1d097316f..6de8ac71e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -25,7 +25,6 @@ // //////////////////////////////////////////////////////////////////////////////// - #define L10N // Localization complete. #include @@ -559,6 +558,54 @@ const std::string escape (const std::string& value, char c) return modified; } +//////////////////////////////////////////////////////////////////////////////// +// Accept a list of projects, and return an indented list +// that reflects the hierarchy. +// +// Input - "one" +// "one.two" +// "one.two.three" +// "one.four" +// "two" +// Output - "one" +// " one.two" +// " one.two.three" +// " one.four" +// "two" +// +// There are two optional arguments, 'whitespace', and 'delimiter', +// +// - whitespace is the string used to build the prefixes of indented items. +// - defaults to two spaces, " " +// - delimiter is the character used to split up projects into subprojects. +// - defaults to the period, '.' +// +const std::vector indentTree ( + const std::vector& values, + const std::string& whitespace /* = " " */, + char delimiter/* = '.' */) +{ + std::vector modified; + std::vector ::const_iterator i; + for (i = values.begin (); i != values.end (); ++i) + { + // Count the delimiters in *i. + int count = 0; + std::string::size_type pos = 0; + while ((pos = i->find (delimiter, pos + 1)) != std::string::npos) + ++count; + + // Construct a prefix string which is a concatenated set of whitespace + // strings. + std::string prefix; + for (int indent = 0; indent < count; ++indent) + prefix += whitespace; + + modified.push_back (prefix + *i); + } + + return modified; +} //////////////////////////////////////////////////////////////////////////////// diff --git a/src/util.h b/src/util.h index dc97155b5..ca9f51459 100644 --- a/src/util.h +++ b/src/util.h @@ -74,5 +74,10 @@ const std::string decode (const std::string&); const std::string escape (const std::string&, char); +const std::vector indentTree ( + const std::vector&, + const std::string& whitespace = " ", + char delimiter='.'); + #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/test/util.t.cpp b/test/util.t.cpp index 94b3d495a..7d6aa2184 100644 --- a/test/util.t.cpp +++ b/test/util.t.cpp @@ -35,7 +35,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (30); + UnitTest t (36); // TODO bool confirm (const std::string&); // TODO int confirm3 (const std::string&); @@ -113,6 +113,22 @@ int main (int argc, char** argv) t.is (vleft[3], 4, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); t.is (vleft[4], 5, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); + // std::vector indentTree (const std::vector&, const std::string whitespace=" ", char delimiter='.'); + std::vector flat; + flat.push_back ("one"); + flat.push_back ("one.two"); + flat.push_back ("one.two.three"); + flat.push_back ("one.four"); + flat.push_back ("two"); + + std::vector structured = indentTree (flat, " ", '.'); + t.is (structured.size (), (size_t) 5, "indentTree yields 5 strings"); + t.is (structured[0], "one", "indentTree 'one' -> 'one'"); + t.is (structured[1], " one.two", "indentTree 'one.two' -> ' one.two'"); + t.is (structured[2], " one.two.three", "indentTree 'one.two.three' -> ' one.two.three'"); + t.is (structured[3], " one.four", "indentTree 'one.four' -> ' one.four'"); + t.is (structured[4], "two", "indentTree 'two' -> 'two'"); + return 0; }