[M3devel] Some earlier work

Dragiša Durić dragisha at m3w.org
Sat Jun 30 10:56:27 CEST 2012


This is how we implemented UTF8 strings over current TEXTs. Current implementation is UNSAFE and uses glibc utf8 methods. Nothing too complicated and nothing we can't implemented in Modula-3/portable C.

=====
INTERFACE UText;

TYPE
  T = TEXT;
  Char = CARDINAL;

PROCEDURE Cat(t, u: T): T;

PROCEDURE Equal(t, u: T): BOOLEAN;

PROCEDURE GetChar(t: T; i: CARDINAL): Char;

PROCEDURE ByteSize(t: T): CARDINAL;

PROCEDURE Length(t: T): CARDINAL;

PROCEDURE Empty(t: T): BOOLEAN;

PROCEDURE Sub(t: T; start: CARDINAL; length: CARDINAL := LAST(CARDINAL)): T;

PROCEDURE SetChars(VAR a: ARRAY OF Char; t: T);

PROCEDURE FromChar(ch: Char): T;

PROCEDURE FromChars(READONLY a: ARRAY OF Char): T;

PROCEDURE Hash(t: T): Word.T;

PROCEDURE Compare(t1, t2: T): [-1..1];

PROCEDURE FindChar(t: T; ch: Char; start: CARDINAL := 0): INTEGER;

PROCEDURE FindCharR(t: T; ch: Char; start: CARDINAL := LAST(INTEGER)): INTEGER;

END UText.


More information about the M3devel mailing list