kojote/vendor/hare-unicode/cmd/linebreak/main.ha
Lobo Torres c70ec9f648 Add 'vendor/hare-unicode/' from commit '1488c26f46f7f8568235eaee6224983ac46e78ff'
git-subtree-dir: vendor/hare-unicode
git-subtree-mainline: 57979aa6fc
git-subtree-split: 1488c26f46
2024-12-04 13:29:21 -03:00

40 lines
831 B
Hare

use encoding::hex;
use fmt;
use os;
use strings;
use unicode;
export fn main() void = {
const input = os::args[1];
const data = strings::toutf8(input);
hex::dump(os::stdout, data)!;
fmt::println(input)!;
let ix = 0u;
const lb = unicode::new_line_breaker(input);
for (const (pos, _, mand) => unicode::next_line_break(&lb)) {
for (ix < pos; ix += 1) {
fmt::print(' ')!;
};
ix += 1;
if (mand) {
fmt::println('|')!;
} else {
fmt::print('^')!;
};
};
fmt::println()!;
fmt::println()!;
fmt::println("Line break opportunities:")!;
const lb = unicode::new_line_breaker(input);
for (const (pos, bpos, mand) => unicode::next_line_break(&lb)) {
fmt::printfln("- {}:{} {} (before '{}'/0x{:x})", pos, bpos,
if (mand) "(mandatory)" else "",
strings::sub(input, pos, pos+1),
data[bpos])!;
};
};