simple_zstring

Memory-Efficient Unicode Strings with Dual-Storage Architecture

MIT License Eiffel 25.02 Design by Contract

Overview

SIMPLE_ZSTRING provides memory-efficient Unicode string handling using a dual-storage architecture. Inspired by the ZSTRING implementation in Eiffel-Loop. Characters are stored in an 8-bit primary area using ISO-8859-15 (Latin-9) encoding, with Unicode characters outside the codec range stored in a compact secondary area.

This approach provides ~70% memory savings for Western European text while supporting the full Unicode range including emoji and CJK characters. The library includes utilities for splitting, searching, escaping, formatting, and fluent string building.

Quick Start

local
    z: SIMPLE_ZSTRING
do
    create z.make_from_string ("Hello World")
    create z.make_from_utf_8 ("Bonjour le monde")
    z.append_character ((0x1F600).to_character_32)  -- Emoji
    print (z.to_string_32)
    print (z.to_utf_8)
end

Features

  • Dual-storage architecture (8-bit primary + 32-bit overflow)
  • UTF-8 encoding/decoding
  • ISO-8859-15 codec (Latin-9 with Euro sign)
  • String splitting, searching, escaping
  • Formatting and templates
  • Fluent builder pattern
  • Design by Contract throughout
  • Void-safe implementation
  • SCOOP-compatible

API Reference

SIMPLE_ZSTRING

Main dual-storage string class with 8-bit primary storage and 32-bit overflow.

Feature Description
make (n) Create with capacity for n characters
make_empty Create empty string
make_from_string (s) Create from general string
make_from_utf_8 (s) Create from UTF-8 bytes
item (i) Character at position i
append_character (c) Append character at end
to_string_32 Convert to full Unicode STRING_32
to_utf_8 Convert to UTF-8 encoded STRING_8

SIMPLE_ZSTRING_SPLITTER

String splitting operations by character, string, lines, or words.

Feature Description
split_by_character (s, c) Split string by character
split_lines (s) Split into lines
split_words (s) Split into words

SIMPLE_ZSTRING_SEARCHER

String searching with wildcards and prefix/suffix matching.

Feature Description
index_of (s, pat, start) Find pattern starting at position
matches_wildcard (s, pat) Match with * and ? wildcards
starts_with (s, prefix) Check prefix

SIMPLE_ZSTRING_ESCAPER

XML, JSON, URL, CSV, and shell escaping/unescaping.

Feature Description
escape_xml (s) Escape for XML
escape_json (s) Escape for JSON
url_encode (s) URL percent-encoding

Installation

Add to your ECF file:

<library name="simple_zstring" location="$SIMPLE_LIBS/simple_zstring/simple_zstring.ecf"/>