File: util.ha

package info (click to toggle)
hare-update 0.26.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,044 kB
  • sloc: makefile: 37; sh: 14
file content (24 lines) | stat: -rw-r--r-- 491 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

use fmt;
use io;

fn newline(ctx: *context) (size | io::error) = {
	let n = 0z;
	n += fmt::fprint(ctx.out, "\n")?;
	ctx.linelen = 0;
	for (let i = 0z; i < ctx.indent; i += 1) {
		n += fmt::fprint(ctx.out, "\t")?;
		ctx.linelen += 8;
	};
	return n;
};

fn space(ctx: *context) (size | io::error) = {
	if (ctx.linelen <= ctx.indent * 8) {
		return 0z;
	};
	ctx.linelen += 1;
	return fmt::fprint(ctx.out, " ");
};