Revision: 4710 http://sourceforge.net/p/vexi/code/4710 Author: mkpg2 Date: 2014-07-31 15:13:14 +0000 (Thu, 31 Jul 2014) Log Message: ----------- Fix. Encoding issue when creating a reader from a string.
Modified Paths: -------------- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/TestStream.java Added Paths: ----------- branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/utf8_readsymbol.js Modified: branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2014-07-31 06:25:33 UTC (rev 4709) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2014-07-31 15:13:14 UTC (rev 4710) @@ -1,6 +1,8 @@ package org.ibex.js; import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.ibex.js.JS.ConstructorList; import org.ibex.js.parse.*; @@ -335,7 +337,7 @@ } static public String expectArg_string(JS[] args, int index) throws JSExn { String r = getArg_string(args, index); - if(r==null) throw new JSExn("Expected string, got null"); + if(r==null) throw new JSExn("Arg "+index+". Expected string, got null"); return r; } @@ -433,5 +435,13 @@ if(js==null) return null; return JSU.S( Integer.toHexString(js.hashCode())); } + static public Charset getCharSet(String name) throws JSExn { + if(name==null) return StandardCharsets.UTF_8; + try{ + return Charset.forName(name); + }catch(Exception e){ + throw new JSExn("Unsupported charset: "+name+" - "+e.getMessage()); + } + } } Modified: branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp 2014-07-31 06:25:33 UTC (rev 4709) +++ branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp 2014-07-31 15:13:14 UTC (rev 4710) @@ -4,12 +4,12 @@ package org.vexi.js; import org.ibex.js.*; -import org.ibex.js.parse.Parser; import org.ibex.js.parse.Function; import java.io.*; +import java.nio.charset.Charset; + import org.ibex.js.JSU.Wrapper; -import org.ibex.js.parse.Function; import org.ibex.util.Basket.Stack; import org.ibex.util.*; @@ -453,7 +453,10 @@ switch(args.length) { case 1: { //#switch(JSU.toString(method)) - case "fromString": return new Fountain.ByteArray(JSU.toString(args[0]).getBytes()); + case "fromString": { + Charset charset= JSU.getCharSet(JSU.getArg_string(args,1)); + return new Fountain.ByteArray(JSU.expectArg_string(args,0).getBytes(charset)); + } case "nameOf": return JSU.S(Fountain.nameOf(args)); case "url": return fountainForURL(JSU.toString(args[0])); case "unzip": @@ -745,23 +748,25 @@ }; } + static private Reader getReader(JS arg) throws JSExn{ + if(JSU.isString(arg)){ + return new StringReader(JSU.toString(arg)); + }else{ + try{ + Fountain f = (Fountain)arg; + InputStream is = f.getInputStream(false); + if (is == null) { + is = new ByteArrayInputStream(new byte[0]); + } + return new InputStreamReader(is, "UTF8"); + }catch(Exception e){ + throw new JSExn(e); + } + } + } + static private JS new_utf8reader(JS[] args) throws JSExn{ - JSU.checkArgs(args, Fountain.ARGTYPES_afountain); - Fountain f = (Fountain)args[0]; - final BufferedReader r; - try { - InputStream is = f.getInputStream(false); - if (is == null) { - is = new ByteArrayInputStream(new byte[0]); - } - r = new BufferedReader( - new InputStreamReader(is, "UTF8")); - } catch (UnsupportedEncodingException e) { - throw new Error("UF8 not available!"); - } catch (IOException e) { - throw JSU.handleFountainExn(e); - } - + final BufferedReader r = new BufferedReader(getReader(JSU.expectArg(args, 0))); return new JS.Immutable() { public JS get(JS key) throws JSExn { try { Modified: branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/TestStream.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/TestStream.java 2014-07-31 06:25:33 UTC (rev 4709) +++ branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/TestStream.java 2014-07-31 15:13:14 UTC (rev 4710) @@ -42,7 +42,7 @@ public static void main(String[] args) throws Throwable { JSTestSuite jts = new TestStream(); - TestCase t = jts.createTestCase(jts.getResourceDirs(), "progress.js"); + TestCase t = jts.createTestCase(jts.getResourceDirs(), "utf8_readsymbol.js"); t.runBare(); } } Added: branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/utf8_readsymbol.js =================================================================== --- branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/utf8_readsymbol.js (rev 0) +++ branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/utf8_readsymbol.js 2014-07-31 15:13:14 UTC (rev 4710) @@ -0,0 +1,3 @@ + +const reader = sys.stream.utf8reader("\xA3"); +trace(reader.all); \ No newline at end of file Property changes on: branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/stream/utf8_readsymbol.js ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn