このコミットが含まれているのは:
守矢諏訪子 2023-08-23 19:42:14 +09:00
コミット 59a6501322
1個のファイルの変更26行の追加21行の削除

ファイルの表示

@ -61,7 +61,6 @@ pub fn main() !void {
var ischar: bool = false; var ischar: bool = false;
var isword: bool = false; var isword: bool = false;
var isnhed: bool = false; var isnhed: bool = false;
var iAmWord: bool = false;
var byte_cunt: usize = 0; var byte_cunt: usize = 0;
var line_cunt: usize = 0; var line_cunt: usize = 0;
var char_cunt: usize = 0; var char_cunt: usize = 0;
@ -105,9 +104,9 @@ pub fn main() !void {
} }
} }
const stdin = io.getStdIn().reader();
if (fname.items.len == 0) { if (fname.items.len == 0) {
// -l -c -m // -l -c -m
const stdin = io.getStdIn().reader();
var buf: [2048]u8 = undefined; var buf: [2048]u8 = undefined;
while (true) { while (true) {
const lne = try stdin.read(buf[0..]); const lne = try stdin.read(buf[0..]);
@ -125,14 +124,13 @@ pub fn main() !void {
byte_cunt += lne; byte_cunt += lne;
// -w // -w
var insideWord: bool = false;
for (buf[0..lne]) |char| { for (buf[0..lne]) |char| {
if (std.ascii.isAlphanumeric(char) or char == '_' or char == '-' or char == '\'' or char == '~' or char == '&') { if (std.ascii.isWhitespace(char)) {
if (!iAmWord) { insideWord = false;
iAmWord = true; } else if (!insideWord) {
word_cunt += 1; insideWord = true;
} word_cunt += 1;
} else {
iAmWord = false;
} }
} }
} }
@ -160,21 +158,28 @@ pub fn main() !void {
// -l -c -m // -l -c -m
var buf: [2048]u8 = undefined; var buf: [2048]u8 = undefined;
while (true) { while (true) {
const lne = try file.reader().readUntilDelimiterOrEof(buf[0..], '\n') orelse break; const lne = try stdin.read(buf[0..]);
const chr = try std.unicode.utf8CountCodepoints(lne); if (lne == 0) {
line_cunt += 1; break;
}
const chr = try std.unicode.utf8CountCodepoints(buf[0..lne]);
for (buf[0..lne]) |char| {
if (char == '\n') {
line_cunt += 1;
}
}
char_cunt += chr; char_cunt += chr;
byte_cunt += lne.len; byte_cunt += lne;
// -w // -w
for (lne) |char| { var insideWord: bool = false;
if (std.ascii.isAlphanumeric(char) or char == '_' or char == '-' or char == '\'' or char == '~' or char == '&') { for (buf[0..lne]) |char| {
if (!iAmWord) { if (std.ascii.isWhitespace(char)) {
iAmWord = true; insideWord = false;
word_cunt += 1; } else if (!insideWord) {
} insideWord = true;
} else { word_cunt += 1;
iAmWord = false;
} }
} }
} }