-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsv.ijs
126 lines (96 loc) · 3.29 KB
/
rsv.ijs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
NB.*rsv s-- j script for encoding and decoding rsv files.
NB.
NB. verbatim: see:
NB.
NB. https://github.com/Stenway/RSV-Specification
NB. https://github.com/Stenway/RSV-Challenge
NB. https://www.youtube.com/watch?v=tb_70o6ohMA
NB.
NB. interface word(s):
NB. ------------------------------------------------------------------------------
NB. read - reads a file as a list of bytes
NB. rsvdec - decode rsv bytes - marks nulls with (NULLMARK)
NB. rsvenc - encode rsv bytes - marks nulls with (NULLMARK)
NB. rsvok - 1 if blblcl rsv nouns have no bad bytes - 0 otherwise
NB. write - writes a list of bytes to file
NB.
NB. created: 2024jan08
NB. changes: ---------------------------------------------------------------------
coclass 'rsv'
NB.*end-header
NB. interface words (IFACEWORDSrsv) group
IFACEWORDSrsv=:<;._1 ' read rsvdec rsvenc rsvok write'
NB. string used to mark RSV nulls
NULLMARK=:'null'
NB. row terminator byte - hex: FD
REOR=:253{a.
NB. value terminator byte - hex: FF
REOV=:255{a.
NB. null value byte - hex: FE
RNULL=:254{a.
NB. root words (ROOTWORDSrsv) group
ROOTWORDSrsv=:<;._1 ' IFACEWORDSrsv ROOTWORDSrsv VMDrsv read rsvdec rsvenc rsvok write'
NB. bytes that should never be emitted by UTF8 encoders
UTF8BADBYTES=:_8{.a.
NB. version, make count, and date
VMDrsv=:'0.9.0';18;'06 Sep 2024 14:16:04'
NB. signal with optional message
assert=:0 0"_ $ 13!:8^:((0: e. ])`(12"_))
NB. tests for character data
ischar=:2&=@(3!:0)
NB. reads a file as a list of bytes
read=:1!:1&(]`<@.(32&>@(3!:0)))
rsvdec=:3 : 0
NB.*rsvdec v-- decode rsv bytes - marks nulls with (NULLMARK).
NB.
NB. monad: blblcl =. rsvdec clRsv
NB.
NB. rsv=. read jpath '~RSVTEST/Valid_001.rsv'
NB. rsvdec rsv
]`(NULLMARK"_)@.((,RNULL)&-:)L:0 <;._2&.> <;._2 y
)
rsvenc=:3 : 0
NB.*rsvenc v-- encode rsv bytes - marks nulls with (NULLMARK).
NB.
NB. monad: clRsv =. rsvenc blblclRsv
NB.
NB. rsv=. rsvdec read jpath '~RSVTEST/Valid_001.rsv'
NB. rsvenc rsv
(0=#y) }. ; ,&REOR&.> ;&.> REOV -.&.>~ ,&REOV L: 0 (]`(RNULL"_))@.(NULLMARK&-:) L: 0 y
)
rsvok=:3 : 0
NB.*rsvok v-- 1 if blblcl rsv nouns have no bad bytes - 0 otherwise.
NB.
NB. monad: pa =. rsvok blblclRsv
NB.
NB. NB. check blblcl for bad bytes before encoding
NB. lol=: (<"1 <"0 ?2 2$1000), (<'') , <"0 ;:'some words'
NB. lol=: utf8@": L: 0 ,&.> lol
NB.
NB. NB. no bad bytes in utf8 formatted cells - result 1
NB. rsvok lol
NB.
NB. NB. add an RSV delimiter byte - result 0
NB. rsvok lol,<,<RSVEOR
NB. sublists must be list of lists of char
msg=. 'not a list of lists of characters'
msg assert 1 = #@$y
msg assert *./ ischar&> ;y
msg assert -.0 e. #@$ &> y
NB. without bad bytes
-. +./ ;; L: 1 ] 1&e.@(UTF8BADBYTES&e.) L: 0 y
)
NB. writes a list of bytes to file
write=:1!:2 ]`<@.(32&>@(3!:0))
NB.POST_rsv post processor.
smoutput IFACE_rsv=: (0 : 0)
NB. (rsv) interface word(s): 20240906j141604
NB. ------------------------
NB. read NB. reads a file as a list of bytes
NB. rsvdec NB. decode rsv bytes - marks nulls with (NULLMARK)
NB. rsvenc NB. encode rsv bytes - marks nulls with (NULLMARK)
NB. rsvok NB. 1 if blblcl rsv nouns have no bad bytes - 0 otherwise
NB. write NB. writes a list of bytes to file
)
cocurrent 'base'
coinsert 'rsv'