Revision: 2375
http://sourceforge.net/p/swingme/code/2375
Author: yuranet
Date: 2019-05-01 15:05:18 +0000 (Wed, 01 May 2019)
Log Message:
-----------
loading tensorflow TSV support
Modified Paths:
--------------
UtilME/src/net/yura/mobile/io/CSVUtil.java
UtilME/src/net/yura/mobile/io/JSONUtil.java
UtilME/src/net/yura/mobile/io/json/JSONTokener.java
Modified: UtilME/src/net/yura/mobile/io/CSVUtil.java
===================================================================
--- UtilME/src/net/yura/mobile/io/CSVUtil.java 2019-04-19 17:13:35 UTC (rev 2374)
+++ UtilME/src/net/yura/mobile/io/CSVUtil.java 2019-05-01 15:05:18 UTC (rev 2375)
@@ -13,16 +13,21 @@
/**
* @author Yura Mamyrin
*/
-public class CSVUtil {
+public abstract class CSVUtil {
- public interface CSV {
- public void newLine();
- public void newValue(int count,String value);
- public String getValueAt(Object obj, int c);
- }
+ public char separator = ',';
+
+ // new Object
+ public abstract void newLine();
+
+ // set value on object
+ public abstract void newValue(int count,String value);
+
+ public abstract String getValueAt(Object obj, int c);
+
// i took something when i wrote this, it was shiny and a powder
// makes for some crazy code, but at least it works
- public static void load(InputStream inputStream,CSV io) throws IOException {
+ public void load(InputStream inputStream) throws IOException {
InputStreamReader inputStreamTxt = new InputStreamReader(inputStream);
@@ -30,7 +35,7 @@
char how=0;
int count=0;
StringBuffer buf = new StringBuffer();
- io.newLine();
+ newLine();
try {
int c;
@@ -43,24 +48,29 @@
inside = true;
how = (char)c;
+
+ // quotes are escaped as 2 quotes inside a quoted string
+ if (buf.length() > 0) {
+ buf.append((char)c);
+ }
}
else if (c=='\n') {
// ignore the \r char
//if ( !"\r".equals(buf.toString()) ) { // buf.length()>0 &&
- io.newValue(count,buf.toString().trim());
+ newValue(count,buf.toString().trim());
buf = new StringBuffer();
//}
count = 0;
- io.newLine();
+ newLine();
}
- else if (c==',') {
+ else if (c==separator) {
//if (buf.length()>0) {
- io.newValue(count,buf.toString().trim());
+ newValue(count,buf.toString().trim());
buf = new StringBuffer();
//}
@@ -99,11 +109,10 @@
try {if (inputStream!=null) inputStream.close(); }
catch(IOException ex) { Logger.info(null, ex); }
}
-
}
- public static void store(OutputStream out, CSV io,Vector objects,int count) throws IOException {
+ public void store(OutputStream out, Vector objects,int count) throws IOException {
Writer writer = null;
@@ -118,7 +127,7 @@
for (int c=0;c<count;c++) {
- String newString=io.getValueAt(obj,c);
+ String newString=getValueAt(obj,c);
if (newString!=null && newString.indexOf('"')>=0) {
@@ -160,6 +169,4 @@
catch(IOException ex) { Logger.info(null, ex); }
}
}
-
-
}
Modified: UtilME/src/net/yura/mobile/io/JSONUtil.java
===================================================================
--- UtilME/src/net/yura/mobile/io/JSONUtil.java 2019-04-19 17:13:35 UTC (rev 2374)
+++ UtilME/src/net/yura/mobile/io/JSONUtil.java 2019-05-01 15:05:18 UTC (rev 2375)
@@ -16,6 +16,8 @@
*/
public class JSONUtil {
+ public boolean useListForArray;
+
public Object load(Reader in) throws IOException {
JSONTokener tokener = new JSONTokener(in);
return readObject(tokener);
@@ -54,6 +56,9 @@
else if (object instanceof Character) {
serializer.value( ((Character)object).charValue() );
}
+ else if (useListForArray && object instanceof Vector) {
+ saveVector(serializer, (Vector)object);
+ }
else {
serializer.object();
serializer.key("class");
@@ -115,10 +120,15 @@
}
break;
case '[':
- Vector vector = readVector(x);
- Object[] array = new Object[vector.size()];
- vector.copyInto(array);
- result = array;
+ Vector vector = readVector(x);
+ if (useListForArray) {
+ result = vector;
+ }
+ else {
+ Object[] array = new Object[vector.size()];
+ vector.copyInto(array);
+ result = array;
+ }
break;
case '(':
// TODO not currently supported as does not recognise close ')'
@@ -132,7 +142,7 @@
else if (s.equalsIgnoreCase("false")) {
result = Boolean.FALSE;
}
- else if (s.equalsIgnoreCase("null")) {
+ else if (s.equalsIgnoreCase("null") || s.equalsIgnoreCase("None")) {
result = null;
}
else if (s.indexOf('.') >= 0) {
Modified: UtilME/src/net/yura/mobile/io/json/JSONTokener.java
===================================================================
--- UtilME/src/net/yura/mobile/io/json/JSONTokener.java 2019-04-19 17:13:35 UTC (rev 2374)
+++ UtilME/src/net/yura/mobile/io/json/JSONTokener.java 2019-05-01 15:05:18 UTC (rev 2375)
@@ -387,6 +387,9 @@
case 'u':
sb.append((char)Integer.parseInt(next(4), 16));
break;
+ case 'x': // python
+ sb.append((char)Integer.parseInt(next(2), 16));
+ break;
case '"':
case '\'':
case '\\':
@@ -394,7 +397,7 @@
sb.append(c);
break;
default:
- throw syntaxError("Illegal escape.");
+ throw syntaxError("Illegal escape. " + c);
}
break;
default:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|