## extensible-string.pkg
#
# Extensible string data type.
# Compiled by:
#
src/lib/x-kit/widget/xkit-widget.sublib### "Object-oriented programming is an exceptionally bad idea
### which could only have originated in California."
###
### -- E.J. Dijkstra
# This package is used (only) in
#
#
src/lib/x-kit/widget/old/text/string-editor.pkgpackage extensible_string
: (weak) Extensible_String # Extensible_String is from
src/lib/x-kit/widget/old/text/extensible-string.api{
Extensible_String
=
EXTENSIBLE_STRING
{
suffix: String,
listc: List( Char ),
listl: Int
};
exception BAD_INDEX Int;
fun make_extensible_string s
=
EXTENSIBLE_STRING { suffix=>"", listc => reverse (explode s), listl=>size s };
fun len (EXTENSIBLE_STRING { suffix, listl, ... } )
=
size suffix + listl;
fun gets (EXTENSIBLE_STRING { suffix, listc, ... } )
=
(implode (reverse listc)) + suffix;
fun subs (str, i, len)
=
{ s = gets str;
#
(substring (s, i, int::min((size s)-i, len)))
except
substring = raise exception BAD_INDEX i;
};
fun split (str, i)
=
{ s = gets str;
#
(substring (s, 0, i), substring (s, i, (size s)-i))
except
substring = raise exception BAD_INDEX i;
};
fun ins (s as EXTENSIBLE_STRING { suffix, listc, listl }, i, c)
=
if (i < 0)
#
raise exception BAD_INDEX i;
else
if (i == listl)
#
EXTENSIBLE_STRING { suffix, listc=>c ! listc, listl=>listl+1 };
else
(split (s, i)) -> (pref, suff);
#
EXTENSIBLE_STRING { suffix=>suff, listc=>c ! (reverse (explode pref)), listl=>i+1 };
fi;
fi;
fun del (s as EXTENSIBLE_STRING { suffix, listc, listl }, i)
=
if (i <= 0)
#
raise exception BAD_INDEX i;
else
if (i == listl )
#
EXTENSIBLE_STRING { suffix, listc => tail listc, listl => listl - 1 };
else
my (pref, suff) = split (s, i);
#
EXTENSIBLE_STRING { suffix => suff, listc => tail (reverse (explode pref)), listl => i - 1 };
fi;
fi;
};
## COPYRIGHT (c) 1991 by AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.