Skip to main content

Utils

GetLines

The GetLines function takes a string input and splits it into a slice of lines.
It reads the input line by line using a buffered reader and preserves the line endings.
Even the last line is included correctly, whether or not it ends with a newline character.
This function is useful for processing multi-line text, such as source code or configuration files, line by line.

lines := cc_lib.GetLines(string(input))

Parameters

NameTypeDescription
inputstringThe multi-line string to split into lines.

Returns

TypeDescription
[]stringSlice of strings, each representing a line from the input.

Tokenize

The Tokenize function splits a string into a slice of tokens using a regular expression.
It separates sequences of word characters (\w+) and non-word characters (\W+) as individual tokens.
This is useful for lexical analysis, parsing, or any scenario where you need to break text into meaningful units, including punctuation and symbols.

for _, line := range lines {
tokens := cc_lib.Tokenize(line)
for _, tok := range tokens {
fmt.println("%s", tok)
}
}

Parameters

NameTypeDescription
tokensstringThe string to be split into tokens.

Returns

TypeDescription
[]stringSlice of strings representing individual tokens (words and symbols).