mirror of
https://github.com/dlang/tools.git
synced 2025-04-26 21:22:22 +03:00
rewritten in D
This commit is contained in:
parent
da0a2e0a37
commit
6f79f28c99
1 changed files with 4 additions and 42 deletions
46
tolf.d
46
tolf.d
|
@ -6,50 +6,12 @@
|
|||
/* Replace line endings with LF
|
||||
*/
|
||||
|
||||
import std.file;
|
||||
import std.path;
|
||||
import std.file, std.path, std.string;
|
||||
|
||||
int main(string[] args)
|
||||
void main(string[] args)
|
||||
{
|
||||
foreach (f; args[1 .. $])
|
||||
{
|
||||
auto input = cast(char[]) std.file.read(f);
|
||||
auto output = filter(input);
|
||||
if (output != input)
|
||||
std.file.write(f, output);
|
||||
}
|
||||
return 0;
|
||||
if (f.exists)
|
||||
f.write(f.readText.lineSplitter.join('\n'));
|
||||
}
|
||||
|
||||
|
||||
char[] filter(char[] input)
|
||||
{
|
||||
char[] output;
|
||||
size_t j;
|
||||
|
||||
for (size_t i = 0; i < input.length; i++)
|
||||
{
|
||||
auto c = input[i];
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\r':
|
||||
c = '\n';
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
if (i && input[i - 1] == '\r')
|
||||
continue;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
continue;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
output ~= c;
|
||||
j++;
|
||||
}
|
||||
return output[0 .. j];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue