1
0
mirror of https://github.com/OlafvdSpek/ctemplate.git synced 2025-09-28 19:05:49 +08:00

make_tpl_varnames_h.cc

This commit is contained in:
olafvdspek@gmail.com 2012-12-19 07:49:16 +00:00
parent d44f73fa42
commit 92208e0adf

View File

@ -198,9 +198,7 @@ static string Boilerplate(const string& progname,
// (space, horizontal tab, vertical tab, form feed, carriage return). // (space, horizontal tab, vertical tab, form feed, carriage return).
static bool LineIsAllWhitespace(const string& input) { static bool LineIsAllWhitespace(const string& input) {
static const string kWhitespace(" \f\t\v\r"); static const string kWhitespace(" \f\t\v\r");
if (input.find_first_not_of(kWhitespace) == string::npos) return input.find_first_not_of(kWhitespace) == string::npos;
return true;
return false;
} }
// Splits the input string into lines using the newline (\n) // Splits the input string into lines using the newline (\n)
@ -214,12 +212,11 @@ static bool LineIsAllWhitespace(const string& input) {
static vector<string> SplitIntoLines(const string &input) { static vector<string> SplitIntoLines(const string &input) {
vector<string> lines; vector<string> lines;
string::size_type begin_index, end_index; string::size_type begin_index = 0;
string::size_type input_len = input.length(); string::size_type input_len = input.length();
begin_index = 0;
while (1) { while (1) {
end_index = input.find_first_of('\n', begin_index); string::size_type end_index = input.find_first_of('\n', begin_index);
if (end_index == string::npos) { if (end_index == string::npos) {
lines.push_back(input.substr(begin_index)); lines.push_back(input.substr(begin_index));
break; break;
@ -274,7 +271,7 @@ static string TextWithDuplicateLinesRemoved(const string& header_entries) {
for (int i = 0; i < lines_len; ++i) { for (int i = 0; i < lines_len; ++i) {
const string& line = lines[i]; const string& line = lines[i];
if (LineIsAllWhitespace(line) || // Blank lines always go in if (LineIsAllWhitespace(line) || // Blank lines always go in
lines_seen.find(line) == lines_seen.end()) { // So do new lines !lines_seen.count(line)) { // So do new lines
output.append(line); output.append(line);
output.append("\n"); output.append("\n");
lines_seen.insert(line); lines_seen.insert(line);