Skip to content

std/strings ​

Index ​

fn Compare(a: string, b: string): int
fn Count(s: string, substr: string): int
fn Contains(s: string, substr: string): bool
fn ContainsAny(s: string, chars: string): bool
fn ContainsRune(s: string, r: rune): bool
fn ContainsFunc(s: string, f: fn(rune): bool): bool
fn IndexByte(s: string, c: byte): int
fn LastIndex(s: string, substr: string): int
fn LastIndexByte(s: string, c: byte): int
fn IndexRune(s: string, r: rune): int
fn IndexAny(s: string, chars: string): int
fn LastIndexAny(s: string, chars: string): int
fn SplitN(mut s: string, sep: string, n: int): []string
fn SplitAfterN(mut s: string, sep: string, n: int): []string
fn Split(mut s: string, sep: string): []string
fn SplitAfter(mut s: string, sep: string): []string
fn Join(elems: []string, sep: string): string
fn HasPrefix(s: string, prefix: string): bool
fn HasSuffix(s: string, suffix: string): bool
fn Map(mapping: fn(rune): rune, mut s: string): string
fn Repeat(s: string, count: int): string
fn IndexFunc(s: string, f: fn(rune): bool): int
fn LastIndexFunc(s: string, f: fn(rune): bool): int
fn TrimLeftFunc(s: string, f: fn(rune): bool): string
fn TrimRight(s: string, cutset: string): string
fn TrimRightFunc(s: string, f: fn(rune): bool): string
fn TrimFunc(s: string, f: fn(rune): bool): string
fn TrimPrefix(s: string, prefix: string): string
fn TrimSuffix(s: string, suffix: string): string
fn Trim(s: string, cutset: string): string
fn TrimLeft(s: string, cutset: string): string
fn TrimSpace(s: string): string
fn Replace(s: string, old: string, new: string, mut n: int): string
fn ReplaceAll(s: string, old: string, new: string): string
fn EqualFold(mut s: string, mut t: string): bool
fn Index(s: string, substr: string): int
fn Cut(s: string, sep: string): (before: string, after: string, found: bool)
fn CutPrefix(s: string, prefix: string): (after: string, found: bool)
fn CutSuffix(s: string, suffix: string): (before: string, found: bool)
fn ToUpper(s: string): string
fn ToLower(s: string): string
fn Clone(s: string): string
struct Builder
    fn Write(mut *self, b: []byte)!: (n: int)
    fn WriteString(mut *self, s: string)!: (n: int)
    fn WriteByte(mut *self, b: byte)!
    fn WriteRune(mut *self, r: rune)!: (n: int)
    fn Grow(mut *self, n: int)
    fn String(*self): string
    fn Clear(mut *self)
    fn Len(*self): int
    fn Cap(*self): int
    fn Buf(mut *self): []byte
    fn SetBuf(mut *self, mut buf: []byte)
struct Reader
    fn New(s: string): &Reader
    fn Len(*self): int
    fn Size(*self): i64
    fn Read(*self, mut b: []byte)!: (n: int)
    fn ReadAt(*self, mut b: []byte, off: i64)!: (n: int)
    fn ReadByte(mut *self)!: (byte, int)
    fn UnreadByte(*self)!
    fn ReadRune(*self)!: (ch: rune, size: int)
    fn UnreadRune(*self)!
    fn Seek(*self, offset: i64, whence: int)!: i64
    fn WriteTo(*self, mut w: io::Writer)!: (n: i64)
    fn Reset(mut *self, s: string)
struct Replacer
    fn New(oldnew: ...string): &Replacer
    fn Replace(&self, s: string): string
    fn WriteString(&self, mut w: io::Writer, s: string)!: (n: int)

Compare ​

jule
fn Compare(a: string, b: string): int

Returns an integer comparing two strings lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.

Use compare when you need to perform a three-way comparison (with [slices::SortFunc], for example). It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.

Count ​

jule
fn Count(s: string, substr: string): int

Counts the number of non-overlapping instances of substr in s. If substr is an empty string, returns 1 + the number of Unicode code points in s.

Contains ​

jule
fn Contains(s: string, substr: string): bool

Reports whether substr is within s.

ContainsAny ​

jule
fn ContainsAny(s: string, chars: string): bool

Reports whether any of the UTF-8-encoded code points in chars are within s.

ContainsRune ​

jule
fn ContainsRune(s: string, r: rune): bool

Reports whether the rune is contained in the UTF-8-encoded byte slice s.

ContainsFunc ​

jule
fn ContainsFunc(s: string, f: fn(rune): bool): bool

Reports whether any of the UTF-8-encoded code points r within b satisfy f(r).

IndexByte ​

jule
fn IndexByte(s: string, c: byte): int

Returns the index of the first instance of c in b, or -1 if c is not present in s.

LastIndex ​

jule
fn LastIndex(s: string, substr: string): int

Returns the index of the last instance of substr in s, or -1 if substr is not present in s.

LastIndexByte ​

jule
fn LastIndexByte(s: string, c: byte): int

Returns the index of the last instance of c in s, or -1 if c is not present in s.

IndexRune ​

jule
fn IndexRune(s: string, r: rune): int

Returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in s. If r is [utf8::RuneError], it returns the first instance of any invalid UTF-8 byte sequence.

IndexAny ​

jule
fn IndexAny(s: string, chars: string): int

Returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

LastIndexAny ​

jule
fn LastIndexAny(s: string, chars: string): int

Returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

SplitN ​

jule
fn SplitN(mut s: string, sep: string, n: int): []string

Slices s into substrings separated by sep and returns a slice of the substrings between those separators.

The count determines the number of substrings to return:

  • n > 0: at most n substrings; the last substring will be the unsplit remainder;
  • n == 0: the result is nil (zero substrings);
  • n < 0: all substrings.

Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for [Split].

To split around the first instance of a separator, see [Cut].

SplitAfterN ​

jule
fn SplitAfterN(mut s: string, sep: string, n: int): []string

Slices s into substrings after each instance of sep and returns a slice of those substrings.

The count determines the number of substrings to return:

  • n > 0: at most n substrings; the last substring will be the unsplit remainder;
  • n == 0: the result is nil (zero substrings);
  • n < 0: all substrings.

Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for [SplitAfter].

Split ​

jule
fn Split(mut s: string, sep: string): []string

Slices s into all substrings separated by sep and returns a slice of the substrings between those separators.

If s does not contain sep and sep is not empty, returns a slice of length 1 whose only element is s.

If sep is empty, splits after each UTF-8 sequence. If both s and sep are empty, returns an empty slice.

It is equivalent to [SplitN] with a count of -1.

To split around the first instance of a separator, see [Cut].

SplitAfter ​

jule
fn SplitAfter(mut s: string, sep: string): []string

Slices s into all substrings after each instance of sep and returns a slice of those substrings.

If s does not contain sep and sep is not empty, returns a slice of length 1 whose only element is s.

If sep is empty, splits after each UTF-8 sequence. If both s and sep are empty, returns an empty slice.

It is equivalent to [SplitAfterN] with a count of -1.

Join ​

jule
fn Join(elems: []string, sep: string): string

Concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.

HasPrefix ​

jule
fn HasPrefix(s: string, prefix: string): bool

Reports whether the string s begins with prefix.

HasSuffix ​

jule
fn HasSuffix(s: string, suffix: string): bool

Reports whether the string s ends with suffix.

Map ​

jule
fn Map(mapping: fn(rune): rune, mut s: string): string

Returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.

Repeat ​

jule
fn Repeat(s: string, count: int): string

Returns a new string consisting of count copies of the string s.

It panics if count is negative or if the result of (len(s) * count) overflows.

IndexFunc ​

jule
fn IndexFunc(s: string, f: fn(rune): bool): int

Returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

LastIndexFunc ​

jule
fn LastIndexFunc(s: string, f: fn(rune): bool): int

Returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.

TrimLeftFunc ​

jule
fn TrimLeftFunc(s: string, f: fn(rune): bool): string

Returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.

TrimRight ​

jule
fn TrimRight(s: string, cutset: string): string

Returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

To remove a suffix, use [TrimSuffix] instead.

TrimRightFunc ​

jule
fn TrimRightFunc(s: string, f: fn(rune): bool): string

Returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.

TrimFunc ​

jule
fn TrimFunc(s: string, f: fn(rune): bool): string

Returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.

TrimPrefix ​

jule
fn TrimPrefix(s: string, prefix: string): string

Returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.

TrimSuffix ​

jule
fn TrimSuffix(s: string, suffix: string): string

Returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.

Trim ​

jule
fn Trim(s: string, cutset: string): string

Returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.

TrimLeft ​

jule
fn TrimLeft(s: string, cutset: string): string

Returns a slice of the string s with all leading Unicode code points contained in cutset removed.

To remove a prefix, use [TrimPrefix] instead.

TrimSpace ​

jule
fn TrimSpace(s: string): string

Returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

Replace ​

jule
fn Replace(s: string, old: string, new: string, mut n: int): string

Returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.

ReplaceAll ​

jule
fn ReplaceAll(s: string, old: string, new: string): string

Returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.

EqualFold ​

jule
fn EqualFold(mut s: string, mut t: string): bool

Reports whether s and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.

Index ​

jule
fn Index(s: string, substr: string): int

Returns the index of the first instance of substr in s, or -1 if substr is not present in s.

Cut ​

jule
fn Cut(s: string, sep: string): (before: string, after: string, found: bool)

Slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, returns s, "", false.

CutPrefix ​

jule
fn CutPrefix(s: string, prefix: string): (after: string, found: bool)

Returns s without the provided leading prefix string and reports whether it found the prefix. If s doesn't start with prefix, returns s, false. If prefix is the empty string, returns s, true.

CutSuffix ​

jule
fn CutSuffix(s: string, suffix: string): (before: string, found: bool)

Returns s without the provided ending suffix string and reports whether it found the suffix. If s doesn't end with suffix, returns s, false. If suffix is the empty string, returns s, true.

ToUpper ​

jule
fn ToUpper(s: string): string

Returns s with all Unicode letters mapped to their upper case.

ToLower ​

jule
fn ToLower(s: string): string

Returns s with all Unicode letters mapped to their lower case.

Clone ​

jule
fn Clone(s: string): string

Returns a fresh copy of s. It guarantees to make a copy of s into a new allocation, which can be important when retaining only a small substring of a much larger string. Using Clone can help such programs use less memory. Of course, since using Clone makes a copy, overuse of Clone can make programs use more memory. Clone should typically be used only rarely, and only when profiling indicates that it is needed. For strings of length zero the string "" will be returned and no allocation is made.

Builder ​

jule
struct Builder {
	// NOTE: contains filtered hidden or unexported fields
}

String builder for efficient concatenation. Optimized for single string building not for repeated use.

A Builder must not be copied after first use.

Implemented Traits ​

  • io::Writer
  • io::ByteWriter
  • io::RuneWriter
  • io::StringWriter

Write ​

jule
fn Write(mut *self, b: []byte)!: (n: int)

Writes bytes to buffer. Never throws an error.

WriteString ​

jule
fn WriteString(mut *self, s: string)!: (n: int)

Writes bytes to buffer. Never throws an error.

WriteByte ​

jule
fn WriteByte(mut *self, b: byte)!

Writes byte to buffer. Never throws an error.

WriteRune ​

jule
fn WriteRune(mut *self, r: rune)!: (n: int)

Writes rune into buffer. Returns written byte count. Never throws an error.

Grow ​

jule
fn Grow(mut *self, n: int)

Grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, panics.

String ​

jule
fn String(*self): string

Returns buffer as string. Will not reset the underlying content.

Clear ​

jule
fn Clear(mut *self)

Clears buffer. After calling this function, write calls will allocate new buffer.

Len ​

jule
fn Len(*self): int

Returns length of buffer.

Cap ​

jule
fn Cap(*self): int

Returns capacity of buffer.

Buf ​

jule
unsafe fn Buf(mut *self): []byte

Returns mutable buffer for low-level interactions.

SetBuf ​

jule
unsafe fn SetBuf(mut *self, mut buf: []byte)

Sets mutable internal buffer for low-level interactions.

Reader ​

jule
struct Reader {
	// NOTE: contains filtered hidden or unexported fields
}

Implements the io::Reader, io::ReaderAt, io::ByteReader, io::RuneReader, io::Seeker, and io::WriterTo traits by reading from a string. The zero value for Reader operates like a Reader of an empty string.

Implemented Traits ​

  • io::Reader
  • io::ReaderAt
  • io::ByteReader
  • io::RuneReader
  • io::Seeker
  • io::WriterTo

New ​

jule
fn New(s: string): &Reader

Returns a new Reader reading from s.

Len ​

jule
fn Len(*self): int

Returns the number of bytes of the unread portion of the string.

Size ​

jule
fn Size(*self): i64

Returns the original length of the underlying string. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method.

Read ​

jule
fn Read(*self, mut b: []byte)!: (n: int)

Implements behavior the io::Reader trait.

ReadAt ​

jule
fn ReadAt(*self, mut b: []byte, off: i64)!: (n: int)

Implements behavior the io::ReaderAt trait.

ReadByte ​

jule
fn ReadByte(mut *self)!: (byte, int)

Implements behavior the io::ByteReader trait.

UnreadByte ​

jule
fn UnreadByte(*self)!

Implements behavior the io::ByteScanner trait.

ReadRune ​

jule
fn ReadRune(*self)!: (ch: rune, size: int)

Implements behavior the io::RuneReader trait.

UnreadRune ​

jule
fn UnreadRune(*self)!

Implements behavior the io::RuneScanner trait.

Seek ​

jule
fn Seek(*self, offset: i64, whence: int)!: i64

Implements behavior of the io::Seeker trait.

WriteTo ​

jule
fn WriteTo(*self, mut w: io::Writer)!: (n: i64)

Implements behavior the io::WriterTo trait.

Reset ​

jule
fn Reset(mut *self, s: string)

Resets the Reader to be reading from s.

Replacer ​

jule
struct Replacer {
	// NOTE: contains filtered hidden or unexported fields
}

Replaces a list of strings with replacements. It is more efficient than Replace function for multiple replacements on one string. It is safe for concurrent use by multiple threads.

New ​

jule
fn New(oldnew: ...string): &Replacer

Returns a new [Replacer] from a list of old, new string pairs. Replacements are performed in the order they appear in the target string, without overlapping matches. The old string comparisons are done in argument order.

Panics if given an odd number of arguments.

Replace ​

jule
fn Replace(&self, s: string): string

Returns a copy of s with all replacements performed.

WriteString ​

jule
fn WriteString(&self, mut w: io::Writer, s: string)!: (n: int)

Writes s to w with all replacements performed.