1(*
2    Title:      Rebuild the basis library: String and char.
3    Copyright   David C.J. Matthews 2016
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License version 2.1 as published by the Free Software Foundation.
8    
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13    
14    You should have received a copy of the GNU Lesser General Public
15    License along with this library; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17*)
18
19(* Char and String *)
20useBasis "StringSignatures";
21
22structure Char: CHAR =
23struct
24    open Char
25    val maxOrd = FixedInt.toInt maxOrd
26    val chr = chr o FixedInt.fromInt
27    val ord = FixedInt.toInt o ord
28end;
29
30structure String: STRING =
31struct
32    open String
33    val maxSize = FixedInt.toInt maxSize
34    val size = FixedInt.toInt o size
35    val sub = fn (s, i) => sub(s, FixedInt.fromInt i)
36    val substring = fn (s, i, j) => substring(s, FixedInt.fromInt i, FixedInt.fromInt j)
37    val extract = fn(s, i, j) => extract(s, FixedInt.fromInt i, Option.map FixedInt.fromInt j)
38end;
39
40structure Substring: SUBSTRING =
41struct
42    open Substring
43    val base = fn s => let val (a, i, j) = base s in (a, FixedInt.toInt i, FixedInt.toInt j) end
44    val size = FixedInt.toInt o size
45    val sub = fn (s, i) => sub(s, FixedInt.fromInt i)
46    val substring = fn (s, i, j) => substring(s, FixedInt.fromInt i, FixedInt.fromInt j)
47    val extract = fn(s, i, j) => extract(s, FixedInt.fromInt i, Option.map FixedInt.fromInt j)
48    val splitAt = fn (s, i) => splitAt(s, FixedInt.fromInt i)
49    val slice = fn (s, i, j) => slice(s, FixedInt.fromInt i, Option.map FixedInt.fromInt j)
50    val trimr = fn i => trimr(FixedInt.fromInt i)
51    and triml = fn i => triml(FixedInt.fromInt i)
52end;
53
54val ord : char -> int = Char.ord 
55val chr : int -> char = Char.chr 
56val substring : string * int * int -> string = String.substring;
57val size: string -> int = String.size;
58