strings #

fn dice_coefficient #

fn dice_coefficient(s1 string, s2 string) f32

implementation of Sørensen–Dice coefficient. find the similarity between two strings. returns coefficient between 0.0 (not similar) and 1.0 (exact match).

fn levenshtein_distance #

fn levenshtein_distance(a string, b string) int

#-js use levenshtein distance algorithm to calculate the distance between between two strings (lower is closer)

fn levenshtein_distance_percentage #

fn levenshtein_distance_percentage(a string, b string) f32

use levenshtein distance algorithm to calculate how similar two strings are as a percentage (higher is closer)

fn new_builder #

fn new_builder(initial_size int) Builder

new_builder returns a new string builder, with an initial capacity of initial_size

fn repeat #

fn repeat(c byte, n int) string

strings.repeat - fill a string with n repetitions of the character c

fn repeat_string #

fn repeat_string(s string, n int) string

strings.repeat_string - gives you n repetitions of the substring s NB: strings.repeat, that repeats a single byte, is between 2x and 24x faster than strings.repeat_string called for a 1 char string.

struct Builder #

struct Builder {
pub mut:
	buf          []byte
	str_calls    int
	len          int
	initial_size int = 1
}

strings.Builder is used to efficiently append many strings to a large dynamically growing buffer, then use the resulting large string. Using a string builder is much better for performance/memory usage than doing constantly string concatenation.

fn (Builder) write_bytes #

fn (mut b Builder) write_bytes(bytes byteptr, howmany int)

write_bytes appends bytes to the accumulated buffer

fn (Builder) write_b #

fn (mut b Builder) write_b(data byte)

write_b appends a single data byte to the accumulated buffer

fn (Builder) write #

fn (mut b Builder) write(s string)

write appends the string s to the buffer

fn (Builder) go_back #

fn (mut b Builder) go_back(n int)

go_back discards the last n bytes from the buffer

fn (Builder) cut_last #

fn (mut b Builder) cut_last(n int) string

cut_last cuts the last n bytes from the buffer and returns them

fn (Builder) go_back_to #

fn (mut b Builder) go_back_to(pos int)

go_back_to resets the buffer to the given position pos NB: pos should be < than the existing buffer length.

fn (Builder) writeln #

fn (mut b Builder) writeln(s string)

writeln appends the string s, and then a newline character.

fn (Builder) last_n #

fn (b &Builder) last_n(n int) string

buf == 'hello world' last_n(5) returns 'world'

fn (Builder) after #

fn (b &Builder) after(n int) string

buf == 'hello world' after(6) returns 'world'

fn (Builder) str #

fn (mut b Builder) str() string

str returns all of the accumulated content of the buffer. NB: in order to avoid memleaks and additional memory copies, after a call to b.str(), the builder b will be empty. The returned string owns the accumulated data so far.

fn (Builder) free #

fn (mut b Builder) free()

manually free the contents of the buffer