Merge pull request #2 from lioncash/line

output: Shorten countLines
This commit is contained in:
bunnei 2014-11-27 00:13:44 -05:00
commit 8186354abd

View File

@ -1,5 +1,6 @@
#include "output.h"
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
@ -18,12 +19,7 @@ static int countLines(const std::string& str)
if (str.empty())
return 0;
int cnt = 1;
for (const char& c : str) {
if (c == '\n') cnt++;
}
return cnt;
return 1 + std::count_if(str.begin(), str.end(), [](char c) { return c == '\n'; });
}
static void deleteFirstLine(std::string* str)