Skip to content

Commit

Permalink
checkwhitespace: output line numbers, report files with invalid UTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Jul 8, 2015
1 parent 92c3700 commit 5de2730
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/checkwhitespace.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@ int main(string[] args)
auto r = regex(r" +\n");
foreach(a; args[1..$])
{
auto str = a.readText();
if (str.canFind("\r\n"))
try
{
writefln("Error - file '%s' contains windows line endings", a);
error = true;
ptrdiff_t pos;
auto str = a.readText();
if ((pos = str.indexOf("\r\n")) >= 0)
{
writefln("Error - file '%s' contains windows line endings at line %d", a, str[0..pos].count('\n') + 1);
error = true;
}
if (a.extension() != ".mak" && (pos = str.indexOf('\t')) >= 0)
{
writefln("Error - file '%s' contains tabs at line %d", a, str[0..pos].count('\n') + 1);
error = true;
}
auto m = str.matchFirst(r);
if (!m.empty)
{
pos = m.front.ptr - str.ptr; // assume the match is a slice of the string
writefln("Error - file '%s' contains trailing whitespace at line %d", a, str[0..pos].count('\n') + 1);
error = true;
}
}
if (a.extension() != ".mak" && str.canFind('\t'))
catch(Exception e)
{
writefln("Error - file '%s' contains tabs", a);
error = true;
}
if (!str.matchFirst(r).empty)
{
writefln("Error - file '%s' contains trailing whitespace", a);
error = true;
writefln("Exception - file '%s': %s", a, e.msg);
}
}
return error ? 1 : 0;
Expand Down

0 comments on commit 5de2730

Please sign in to comment.