comparison src/luan/modules/BinaryLuan.java @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents core/src/luan/modules/BinaryLuan.java@cdc70de628b5
children e38f5869e9df
comparison
equal deleted inserted replaced
774:3e30cf310e56 775:1a68fc55a80c
1 package luan.modules;
2
3 import luan.Luan;
4 import luan.LuanState;
5 import luan.LuanTable;
6 import luan.LuanFunction;
7 import luan.LuanException;
8 import luan.LuanMethod;
9
10
11 public final class BinaryLuan {
12
13 static int start(byte[] binary,int i) {
14 int len = binary.length;
15 return i==0 ? 0 : i > 0 ? Math.min(i-1,len) : Math.max(len+i,0);
16 }
17
18 static int start(byte[] binary,Integer i,int dflt) {
19 return i==null ? dflt : start(binary,i);
20 }
21
22 static int end(byte[] binary,int i) {
23 int len = binary.length;
24 return i==0 ? 0 : i > 0 ? Math.min(i,len) : Math.max(len+i+1,0);
25 }
26
27 static int end(byte[] binary,Integer i,int dflt) {
28 return i==null ? dflt : end(binary,i);
29 }
30
31 @LuanMethod public static Byte[] byte_(byte[] binary,Integer i,Integer j) throws LuanException {
32 Utils.checkNotNull(binary);
33 int start = start(binary,i,1);
34 int end = end(binary,j,start+1);
35 Byte[] bytes = new Byte[end-start];
36 for( int k=0; k<bytes.length; k++ ) {
37 bytes[k] = binary[start+k];
38 }
39 return bytes;
40 }
41
42 @LuanMethod public static byte[] binary(byte... bytes) {
43 return bytes;
44 }
45
46 public static String to_string(byte[] binary) {
47 return new String(binary);
48 }
49
50 }