summary refs log blame commit diff stats
path: root/doc/pydoc/ranger.ext.waitpid_no_intr.html
blob: c0ef5666e953b3877d9916767bb307793e8132df (plain) (tree)
n class="p">) string hacky_squeeze_out_whitespace(const string& s) { // strip whitespace at start string::const_iterator first = s.begin(); while (first != s.end() && isspace(*first)) ++first; if (first == s.end()) return ""; // strip whitespace at end string::const_iterator last = --s.end(); while (last != s.begin() && isspace(*last)) --last; ++last; // replace runs of spaces/dots with single space until comment or string // TODO: // leave alone dots not surrounded by whitespace // leave alone '#' within word // leave alone '"' within word // squeeze spaces after end of string ostringstream out; bool previous_was_space = false; bool in_comment_or_string = false; for (string::const_iterator curr = first; curr != last; ++curr) { if (in_comment_or_string) out << *curr; else if (isspace(*curr) || *curr == '.') previous_was_space = true; else { if (previous_was_space) out << ' '; out << *curr; previous_was_space = false; if (*curr == '#' || *curr == '"') in_comment_or_string = true; } } return out.str(); }