String module

normalize_line_endings

procedure · 2 overloadsSource

Removes the carriage return from every \r\n pair in s, in place, and shortens s. A lone \r is kept. s must be writable.

normalize_line_endings :: (s: *string)

Parameters

s: *string
ExampleOpen in playground ↗
text := copy_string("a\r\nb\rc");
defer free(text);
normalize_line_endings(*text);
assert(text == "a\nb\rc");
normalize_line_endings :: (s: string) -> string

A copy of s with the carriage return removed from every \r\n pair. A lone \r is kept. The copy is allocated with the context allocator and the caller frees it.

Parameters

s: string

Returns

string
ExampleOpen in playground ↗
text := normalize_line_endings("one\r\ntwo");
defer free(text);
assert(text == "one\ntwo");

See also