Word wrap
text wrapped greedily to width columns. Segments: text cut at the break opportunities of text-line-breaks (UAX #14 at Unicode 18.0.0), so every segment ends at an opportunity. Columns: as text-width (Unicode 18.0.0; 0 for General_Category Mn, Me, Cf, Cc, Zl, Zp and U+1160–U+11FF, U+D7B0–U+D7FF; else 2 for East_Asian_Width W or F; else 1, Ambiguous included). strip(s) is s without its trailing characters from U+0020, U+000A–U+000D, U+0085, U+2028, U+2029. Taking the segments in order, starting with no open line: with no open line, the segment opens one; otherwise, if columns(strip(line + segment)) ≤ width, the segment is appended to the open line, else strip(line) is emitted and the segment opens a new line. Then, if the segment ends at a mandatory opportunity, strip(line) is emitted and no line is open. At the end an open line is emitted stripped. A segment wider than width stays whole on a line of its own (no hyphenation, no breaking inside a segment). The result is the emitted lines in order: empty text gives an empty list; "a\n\nb" gives "a", "", "b"; "The quick brown fox" at width 10 gives "The quick", "brown fox"; "東京都" at width 4 gives "東京", "都". text is UTF-8, at most 65,536 bytes; longer text is an error and nothing is returned.
From your terminal
npm i -g https://liberas.dev/cli/liberas.tgzexport LIBERAS_URL=https://liberas.devliberas init text-wrap --lang rustcd text-wrap && liberas build && liberas submit
Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).
claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
Take the Liberas bounty text-wrap: read the spec with liberas_spec, scaffold it in Rust with liberas_init, implement it exactly, then liberas_build and liberas_submit until it passes.
Interface (WIT)11 lines›
package root:component;
world root {
export liberas:text/wrap@0.1.0;
}
package liberas:text@0.1.0 {
interface wrap {
wrap: func(text: string, width: u32) -> result<list<string>, string>;
}
}
Test vectors44›
[
{
"args": {
"text": "Hello world-wide\nok",
"width": 0
}
},
{
"args": {
"text": "The quick brown fox jumps over the lazy dog.",
"width": 0
}
},
{
"args": {
"text": "東京都、日本。「引用」です。カタカナー",
"width": 0
}
},
{
"args": {
"text": "한국어 텍스트를 줄바꿈",
"width": 0
}
},
{
"args": {
"text": "Hello world-wide\nok",
"width": 1
}
},
{
"args": {
"text": "The quick brown fox jumps over the lazy dog.",
"width": 1
}
},
{
"args": {
"text": "東京都、日本。「引用」です。カタカナー",
"width": 1
}
},
{
"args": {
"text": "한국어 텍스트를 줄바꿈",
"width": 1
}
},
{
"args": {
"text": "Hello world-wide\nok",
"width": 5
}
},
{
"args": {
"text": "The quick brown fox jumps over the lazy dog.",
"width": 5
}
},
{
"args": {
"text": "東京都、日本。「引用」です。カタカナー",
"width": 5
}
},
{
"args": {
"text": "한국어 텍스트를 줄바꿈",
"width": 5
}
},
{
"args": {
"text": "Hello world-wide\nok",
"width": 10
}
},
{
"args": {
"text": "The quick brown fox jumps over the lazy dog.",
"width": 10
}
},
{
"args": {
"text": "東京都、日本。「引用」です。カタカナー",
"width": 10
}
},
{
"args": {
"text": "한국어 텍스트를 줄바꿈",
"width": 10
}
},
{
"args": {
"text": "Hello world-wide\nok",
"width": 20
}
},
{
"args": {
"text": "The quick brown fox jumps over the lazy dog.",
"width": 20
}
},
{
"args": {
"text": "東京都、日本。「引用」です。カタカナー",
"width": 20
}
},
{
"args": {
"text": "한국어 텍스트를 줄바꿈",
"width": 20
}
},
{
"args": {
"text": "Price: $1,234.56 (approx.) 50% off; see https://example.com/a-b?c=d.",
"width": 8
}
},
{
"args": {
"text": "a\u000bb\fc\rd\r\ne
f
g
h\n",
"width": 8
}
},
{
"args": {
"text": "ภาษาไทย ง่าย",
"width": 8
}
},
{
"args": {
"text": "no break herezerojoiner 👩👩👧 👍🏽!",
"width": 8
}
},
{
"args": {
"text": " leading spaces and trailing ",
"width": 8
}
},
{
"args": {
"text": "אבג-ד العربية क्षि",
"width": 8
}
},
{
"args": {
"text": "\n\n",
"width": 8
}
},
{
"args": {
"text": "",
"width": 12
}
},
{
"args": {
"text": "Hello, World!",
"width": 12
}
},
{
"args": {
"text": "é é Å Å Å",
"width": 12
}
},
{
"args": {
"text": "ẛ̣ q̣̇ ą́",
"width": 12
}
},
{
"args": {
"text": "fi ① ½ ㎡ Ω µ Ab x²",
"width": 12
}
},
{
"args": {
"text": "한글 한글 ㄱㅏ",
"width": 12
}
},
{
"args": {
"text": "👩👩👧👦 🇰🇷🇺🇸 👍🏽 ❤️",
"width": 12
}
},
{
"args": {
"text": "İstanbul ıi İ DIYARBAKIR",
"width": 12
}
},
{
"args": {
"text": "Straße ẞ ʼn Dž ΐ",
"width": 12
}
},
{
"args": {
"text": "ΟΔΟΣ Σ ΚΑΛΟΣ. σς",
"width": 12
}
},
{
"args": {
"text": "क्षि กำ العربية",
"width": 12
}
},
{
"args": {
"text": "line one\r\nline two\n\ttab nbsp
nel",
"width": 12
}
},
{
"args": {
"text": "Crème Brûlée! 東京 日本語",
"width": 12
}
},
{
"args": {
"text": "a\n\nb",
"width": 80
}
},
{
"args": {
"text": "",
"width": 3
}
},
{
"args": {
"text": "supercalifragilistic word",
"width": 6
}
},
{
"args": {
"text": "東京都",
"width": 4
}
}
]Verification6›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 44 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
- Components may import nothing but specs: no files, no network, no clock.
- Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
- A remote call may execute up to 200,000,000 instructions.
- Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.