Skip early if line doesn't look like a patch
This allows us to skip exception handling (substr) later. 😉
This commit is contained in:
parent
f8a7d5c579
commit
b204b3e855
35
src/main.cpp
35
src/main.cpp
|
@ -53,24 +53,27 @@ int main()
|
||||||
while (std::getline(std::cin, line))
|
while (std::getline(std::cin, line))
|
||||||
{
|
{
|
||||||
const auto line_nc{remove_colors(line)};
|
const auto line_nc{remove_colors(line)};
|
||||||
// Don't color +++ and --- lines
|
// Only look at lines starting with + or -
|
||||||
if (line_nc.length() >= 2
|
if (line_nc.length() >= 2 && (line_nc[0] == '+' || line_nc[0] == '-'))
|
||||||
&& (line_nc.length() < 3
|
|
||||||
|| (line_nc[2] != '+' && line_nc[2] != '-')))
|
|
||||||
{
|
{
|
||||||
if (line_nc[1] == '+')
|
// Don't color +++ and --- lines
|
||||||
|
if (line_nc.length() < 3
|
||||||
|
|| (line_nc[2] != '+' && line_nc[2] != '-'))
|
||||||
{
|
{
|
||||||
const auto pos{get_start_pos(line)};
|
if (line_nc[1] == '+')
|
||||||
std::cout << line.substr(0, pos) << green << line.substr(pos)
|
{
|
||||||
<< reset << '\n';
|
const auto pos{get_start_pos(line)};
|
||||||
continue;
|
std::cout << line.substr(0, pos) << green
|
||||||
}
|
<< line.substr(pos) << reset << '\n';
|
||||||
if (line_nc[1] == '-')
|
continue;
|
||||||
{
|
}
|
||||||
const auto pos{get_start_pos(line)};
|
if (line_nc[1] == '-')
|
||||||
std::cout << line.substr(0, pos) << red << line.substr(pos)
|
{
|
||||||
<< reset << '\n';
|
const auto pos{get_start_pos(line)};
|
||||||
continue;
|
std::cout << line.substr(0, pos) << red << line.substr(pos)
|
||||||
|
<< reset << '\n';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << line << '\n';
|
std::cout << line << '\n';
|
||||||
|
|
Loading…
Reference in New Issue