This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathbinary.lcb
More file actions
211 lines (145 loc) · 6.61 KB
/
binary.lcb
File metadata and controls
211 lines (145 loc) · 6.61 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/**
This library consists of the operations on binary strings provided by the standard library of LiveCode Builder.
*/
module com.livecode.binary
use com.livecode.foreign
public foreign handler MCBinaryExecPutBytesBefore(in Source as Data, inout Target as Data) returns nothing binds to "<builtin>"
public foreign handler MCBinaryExecPutBytesAfter(in Source as Data, inout Target as Data) returns nothing binds to "<builtin>"
public foreign handler MCBinaryEvalConcatenateBytes(in Left as Data, in Right as Data, out Result as Data) returns nothing binds to "<builtin>"
/* No implementation
public foreign handler MCBinaryEvalContainsBytes(in Target as Data, in Needle as Data, out Value as CBool) returns nothing binds to "<builtin>"
*/
public foreign handler MCBinaryEvalIsEqualTo(in Left as Data, in Right as Data, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCBinaryEvalIsNotEqualTo(in Left as Data, in Right as Data, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCBinaryEvalIsLessThan(in Left as Data, in Right as Data, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCBinaryEvalIsGreaterThan(in Left as Data, in Right as Data, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCDataEvalEmpty(out Value as Data) returns nothing binds to "<builtin>"
--
/**
Summary: Prepends <Source> bytes to <Target> bytes.
Source: An expression which evaluates to binary data.
Target: An expression which evaluates to a binary container.
Description:
Use to insert bytes into data without replacement. Can be used either with a chunk expression to insert at a specified location, or without to prepend to the target data.
Tags: Binary
*/
syntax PutBytesBefore is statement
"put" <Source: Expression> "before" <Target: Expression>
begin
MCBinaryExecPutBytesBefore(Source, Target)
end syntax
/**
Summary: Appends <Source> bytes to <Target> bytes.
Source: An expression which evaluates to binary data.
Target: An expression which evaluates to a binary container.
Related: PutBytesAfter
Description:
Use to insert bytes into data without replacement. Can be used either with a chunk expression to insert at a specified location, or without to append to the target data.
Tags: Binary
*/
syntax PutBytesAfter is statement
"put" <Source: Expression> "after" <Target: Expression>
begin
MCBinaryExecPutBytesAfter(Source, Target)
end syntax
--
/**
Summary: Concatenates <Left> and <Right>.
Left: An expression which evaluates to binary data.
Right: An expression which evaluates to binary data.
Returns: Binary data consisting of the value of the left hand expression with the value of the right hand expression appended to the end.
Description:
The result consists of the bytes of <Left> followed by those of <Right>.
Tags: Binary
*/
syntax ConcatenateBytes is left binary operator with concatenation precedence
<Left: Expression> "&" <Right: Expression>
begin
MCBinaryEvalConcatenateBytes(Left, Right, output)
end syntax
--
/**
Summary: Determines whether <Left> and <Right> are equal or not.
Left: An expression which evaluates to binary data.
Right: An expression which evaluates to binary data.
Returns: Returns true if the result of evaluating <Left> is the same as that of <Right>, and false otherwise.
Description:
Performs a byte by byte comparison of <Left> and <Right>, returning false if there is any difference.
Tags: Binary
*/
syntax DataIsData is neutral binary operator with comparison precedence
<Left: Expression> "is" <Right: Expression>
begin
MCBinaryEvalIsEqualTo(Left, Right, output)
end syntax
/**
Summary: Determines whether <Left> and <Right> are equal or not.
Left: An expression which evaluates to binary data.
Right: An expression which evaluates to binary data.
Returns: Returns false if the result of evaluating <Left> is the same as that of <Right>, and true otherwise.
Description:
Performs a byte by byte comparison of <Left> and <Right>, returning true if there is any difference.
Tags: Binary
*/
syntax DataIsNotData is neutral binary operator with comparison precedence
<Left: Expression> "is not" <Right: Expression>
begin
MCBinaryEvalIsNotEqualTo(Left, Right, output)
end syntax
/**
Summary: Determines whether <Left> is less than <Right> under a byte by byte comparison
Left: An expression which evaluates to binary data.
Right: An expression which evaluates to binary data.
Returns: True if <Left> is less than <Right>, and false otherwise.
Description:
<Left> is less than <Right> if they are not equal, and the first byte in <Right> that is not equal to the corresponding byte in <Left> is of greater value.
Tags: Binary
*/
syntax DataIsLessThanData is neutral binary operator with comparison precedence
<Left: Expression> "<" <Right: Expression>
begin
MCBinaryEvalIsLessThan(Left, Right, output)
end syntax
/**
Summary: Determines whether <Left> is greater than <Right> under a byte by byte comparison
Left: An expression which evaluates to binary data.
Right: An expression which evaluates to binary data.
Returns: True if <Left> is greater than <Right>, and false otherwise.
Description:
<Left> is greater than <Right> if they are not equal, and the first byte in <Left> that is not equal to the corresponding byte in <Right> is of greater value.
Tags: Binary
*/
syntax DataIsGreaterThanData is neutral binary operator with comparison precedence
<Left: Expression> ">" <Right: Expression>
begin
MCBinaryEvalIsGreaterThan(Left, Right, output)
end syntax
--
/**
Summary: Designates data of length 0.
Example:
variable tVar as Data
variable tCount as Number
put the empty data into tVar
put the number of bytes in tVar into tCount -- tCount is 0
Description:
Use ```the empty data``` to initialise a data variable.
Tags: Binary
*/
syntax EmptyData is expression
"the" "empty" "data"
begin
MCDataEvalEmpty(output)
end syntax
end module