dbfwork: 'to_number(x)' is treated as simply 'x'
[ocaml-dbf.git] / cpcvt.ml
blob02376bd19357d9330dff679ea53e9f6fcf38ff4e
1 value revert_table tbl =
2 let res = String.make 128 '?'
3 in (
4 for i = 128 to 255 do
6 let q = (Char.code tbl.[i-128])
7 in
8 if q >= 128
9 then
10 res.[q - 128] := Char.chr i
11 else
14 done
15 ; res
20 value recode_upper tbl s =
21 let l = String.length s
22 and res = String.copy s
23 in do
25 for i = 0 to (l-1) do
27 let c = Char.code res.[i]
29 if c >= 128
30 then
31 res.[i] := tbl.[c-128]
32 else
35 ; res
40 value tbl_cp_866_to_1251 =
41 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\
42 \xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\
43 \xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\
44 ---\xa6+\xa6\xa6\xac\xac\xa6\xa6\xac---\xacL+T+-+\xa6\xa6L\xe3\
45 \xa6T\xa6=+\xa6\xa6TTLL-\xe3++----\xa6\xa6-\xf0\xf1\xf2\xf3\xf4\
46 \xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff\xa8\xb8\xaa\xba\xaf\
47 \xbf\xa1\xa2\xb0\x95\xb7v\xb9\xa4\xa6\xa0"
49 assert (String.length tbl_cp_866_to_1251 = 128);
51 value tbl_cp_1251_to_866 =
52 "__\x27_\x22:\xc5\xd8_%_<_____\x27\x27\x22\x22\x07--_T_>____\
53 \xff\xf6\xf7_\xfd_\xb3\x15\xf0c\xf2<\xbf-R\xf4\xf8+___\xe7\x14\
54 \xfa\xf1\xfc\xf3>___\xf5\x80\x81\x82\x83\x84\x85\x86\x87\x88\
55 \x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\
56 \x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\
57 \xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xe0\xe1\xe2\xe3\xe4\xe5\
58 \xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
60 assert (String.length tbl_cp_1251_to_866 = 128);
64 type cvtr = { importer : string -> string; exporter : string -> string };
67 value mkpair tbl =
68 let _ = Printf.printf "TBL=\"%s\"\n" (revert_table tbl)
70 { importer = recode_upper tbl
71 ; exporter = recode_upper (revert_table tbl)
77 value default_converter = (* mkpair tbl_cp_866_to_1251 *)
78 { importer = recode_upper tbl_cp_866_to_1251
79 ; exporter = recode_upper tbl_cp_1251_to_866