Renderingen-US

textus

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Primitive string/text type.

Aliases: string

Syntax: string

Category#

type

Examples#

radix/corpus/intrinseca/textus-transformationes.fab (canonical · keyword)#

Primitive string/text type.

# =============================================================================
# string — Primitive string/text type
# =============================================================================
#
# What this teaches:
#   • Primitive string/text type.
#   • Related keywords: string, format, ↦
#
# Common mistakes:
#   • Using `string` transform methods on non-text types — `.slice()`, `.uppercase()`, `.lowercase()`, `.trim()`, `.split()`, `.replace()` are textus-only compiler intrinsics.
#
# See also: string, format, ↦
# =============================================================================

# string slice and transform intrinsics
#
# Compiler-owned string methodi — sectio, maiuscula, minuscula, recide,
# divide, muta.
#
# GRAMMAR:
#   s.slice(lo, hi) | s.uppercase() | s.lowercase() | s.trim()
#   s.split(sep) | s.replace(old, new)
#
# divide returns list<string>; pairs with list/ exempla for collection smoke.
# Derived locals use let to avoid repeating const _ across the transform chain.
# Wasm tier Runnable.
#
# EXPECTED OUTPUT:
#   Smoke asserts exit 0 only.

main {
    let nuntius ← " Ave Roma "

    let secta ← nuntius.slice(1, 4)
    let magna ← nuntius.uppercase()
    let parva ← nuntius.lowercase()
    let rasa ← nuntius.trim()
    let partes ← rasa.split(" ")
    let mutata ← rasa.replace("Roma", "Munde")

    print secta, magna, parva
    print rasa, partes, mutata
}

radix/corpus/bounded/conversio-textus-overflow-decline.fab (supporting · reject)#

Decline: a string literal longer than the target capacity rejects with textus_literal_too_long.

# =============================================================================
# string overflow decline — literal over capacity fails closed
# =============================================================================
#
# Decline row (reject reason in the comment):
#   1. over capacity — `"abcdef" ↦ string<4>` asks a 6-scalar literal to fit
#      a capacity of 4: SEM011 textus_literal_too_long
#
# Common mistakes:
#   • expecting silent truncation — the D7 overflow rule fails closed at
#     check for literals whose scalar count exceeds the target capacity
#
# See also: ↦, string
# =============================================================================

# string literal over capacity — expected compile failure
#
# WHY: pins the fail-closed overflow token in conversio-textus-overflow-decline.expected.

main {
    const string<4> t ← "abcdef" ↦ string<4>
    print t
}

Expected: compilation rejects this example.

radix/corpus/bounded/conversio-textus-to-ascii-decline.fab (supporting · reject)#

Decline: bounded string<N> cannot convert directly to ascii<M>.

# =============================================================================
# bounded string to ascii — unsupported conversion decline
# =============================================================================
#
# What this teaches:
#   • Unicode text and bounded ASCII have different conversion contracts.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • assuming every string value is ASCII-safe without an explicit narrowing
#     check.

fn narrow(string<8> raw) → ascii<4> {
    return raw ↦ ascii<4>
}

Expected: compilation rejects this example.

radix/corpus/bounded/conversio-textus-to-bounded-textus-decline.fab (supporting · reject)#

Decline: bounded string<N> cannot resize directly to bounded string<M>.

# =============================================================================
# bounded string resize — unsupported conversion decline
# =============================================================================
#
# What this teaches:
#   • Bounded string capacities are not interchangeable through a direct
#     resize conversion.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • expecting a resize to truncate Unicode scalars silently.

fn resize(string<8> raw) → string<4> {
    return raw ↦ string<4>
}

Expected: compilation rejects this example.

radix/corpus/bounded/conversio-textus-to-octeti-decline.fab (supporting · reject)#

Decline: bounded string<N> cannot convert directly to bytes<M>.

# =============================================================================
# bounded string to bytes — unsupported conversion decline
# =============================================================================
#
# What this teaches:
#   • A bounded text carrier does not become a bounded byte carrier through a
#     direct `↦` route.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • treating UTF-8 encoding as a width-only conversion.

fn encode(string<8> raw) → bytes<8> {
    return raw ↦ bytes<8>
}

Expected: compilation rejects this example.