diff src/luan/modules/BinaryLuan.java @ 1257:e38f5869e9df

don't reset in send_redirect and other improvements
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 20 Sep 2018 21:04:41 -0600
parents 1a68fc55a80c
children 25746915a241
line wrap: on
line diff
--- a/src/luan/modules/BinaryLuan.java	Wed Sep 19 20:15:16 2018 -0600
+++ b/src/luan/modules/BinaryLuan.java	Thu Sep 20 21:04:41 2018 -0600
@@ -1,5 +1,6 @@
 package luan.modules;
 
+import java.io.UnsupportedEncodingException;
 import luan.Luan;
 import luan.LuanState;
 import luan.LuanTable;
@@ -43,8 +44,17 @@
 		return bytes;
 	}
 
-	public static String to_string(byte[] binary) {
-		return new String(binary);
+	private static String toString(byte[] a) {
+		char[] ac = new char[a.length];
+		for( int i=0; i<a.length; i++ ) {
+			ac[i] = (char)a[i];
+		}
+		return new String(ac);
+	}
+
+	public static String to_string(byte[] binary,String charsetName) throws LuanException, UnsupportedEncodingException {
+		Utils.checkNotNull(binary);
+		return charsetName!=null ? new String(binary,charsetName) : toString(binary);
 	}
 
 }