Text_File_Handler module

consume_next_line

procedure · 2 overloadsSource

Removes the first line from sp and returns it, and whether there was one. A line ends at \n, \r or \r\n. Nothing is trimmed or skipped: empty lines and comments come out as they are. At the end of the text the result is an empty string and false.

consume_next_line :: (sp: *string) -> (string, bool)

Parameters

sp: *string

Returns

string
bool
ExampleOpen in playground ↗
text := "one\r\ntwo\n\nthree";
line, found := consume_next_line(*text);
assert(found && line == "one");
line, found = consume_next_line(*text);
assert(found && line == "two");
line, found = consume_next_line(*text);
assert(found && line == "");
consume_next_line :: (
    handler: *Text_File_Handler
) -> (line: string, found: bool)

The next line of the handler's text that is not skipped, and whether there was one. Lines whose first non-space byte is the comment character are skipped. With strip_comments_from_ends_of_lines the line is cut at the first comment character, and the line is trimmed of spaces. With auto_skip_blank_lines, a line with nothing left is skipped too. At the end the result is an empty string and false.

line_number is advanced for every line looked at, including the ones skipped.

Parameters

Returns

line: string
found: bool

See also