Transforming text v0.1.0

Source
New strings made from old: concatenation, repetition, replacement and ASCII case.

Join

pub func Join(
    allocator: Allocator,
    parts: StringView[..],
    separator: StringView
) -> String ! TextError

The text of every part of parts in order, with separator between each two. No parts give empty text and one part gives that part, so the separator count is always one less than the parts.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
partsStringView[..]the pieces to join
separatorStringViewwhat goes between them

Returns: the joined text, or why it could not be made

ToUpper

pub func ToUpper(
    allocator: Allocator,
    view: StringView
) -> String ! TextError

The text of view in upper case by Unicode's full, unconditional mappings, so ß becomes SS and ʼn becomes ʼN. The length may change.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on

Returns: the text in upper case, or why it could not be made

ToLower

pub func ToLower(
    allocator: Allocator,
    view: StringView
) -> String ! TextError

The text of view in lower case by Unicode's full, unconditional mappings. A capital sigma always becomes σ, never the final ς, since which one is right depends on the letters around it.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on

Returns: the text in lower case, or why it could not be made

FoldCase

pub func FoldCase(
    allocator: Allocator,
    view: StringView
) -> String ! TextError

The text of view case-folded by Unicode's full folding, the form for comparing text without regard to case: two texts that differ only in case fold to the same bytes, Straße and STRASSE included.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on

Returns: the folded text, or why it could not be made

Concat

pub func Concat(
    allocator: Allocator,
    left: StringView,
    right: StringView
) -> String ! TextError

The text of left followed by the text of right. Fails with what went wrong; no partial text comes back.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
leftStringViewthe first piece
rightStringViewthe second

Returns: the two joined, or why they could not be

Repeat

pub func Repeat(
    allocator: Allocator,
    view: StringView,
    count: uint
) -> String ! TextError

The text of view written count times. A count of zero gives empty text, which is what makes repeating agree with joining: repeating twice is the same as joining a thing to itself.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on
countuinthow many times

Returns: the text repeated that many times, or why it could not be

Replace

pub func Replace(
    allocator: Allocator,
    view: StringView,
    needle: StringView,
    replacement: StringView
) -> String ! TextError

The text of view with every occurrence of needle replaced by replacement. Occurrences are found left to right and never overlap, and what is put in their place is not searched again -- so replacing a with aa terminates rather than growing forever. An empty needle matches nothing, since the alternative is a replacement between every pair of characters and before and after every one of them.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on
needleStringViewthe text to look for
replacementStringViewthe text to put in its place

Returns: the text with every occurrence replaced, or why it could not be

IsAsciiLetter

pub func IsAsciiLetter(byte: char8) -> bool

Whether byte is an ASCII letter.

Source

Parameters

NameTypeDescription
bytechar8the byte

Returns: whether the byte is an ASCII letter

ToAsciiUpper

pub func ToAsciiUpper(
    allocator: Allocator,
    view: StringView
) -> String ! TextError

The text of view with every ASCII lower-case letter raised, and everything else left alone. ASCII only: every byte above 0x7F passes through untouched, which is why this cannot change the length and cannot produce anything that is not UTF-8.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on

Returns: the text with its ASCII letters uppercased and everything else untouched

ToAsciiLower

pub func ToAsciiLower(
    allocator: Allocator,
    view: StringView
) -> String ! TextError

The text of view with every ASCII upper-case letter lowered.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewStringViewthe borrowed text to act on

Returns: the text with its ASCII letters lowercased and everything else untouched