diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index 30be65175..ef47cd55d 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -2601,10 +2601,174 @@ public class PApplet extends Applet ////////////////////////////////////////////////////////////// + static final public boolean toBoolean(char what) { + return ((what == 't') || (what == 'T') || (what == '1')); + } + + static final public boolean toBoolean(int what) { // this will cover byte + return (what != 0); + } + + static final public boolean toBoolean(float what) { + return (what != 0); + } + + static final public boolean toBoolean(String what) { + return new Boolean(what).booleanValue(); + } + + // + + static final public boolean[] toBoolean(char what[]) { + boolean outgoing[] = new boolean[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = + ((what[i] == 't') || (what[i] == 'T') || (what[i] == '1')); + } + return outgoing; + } + + static final public boolean[] toBoolean(byte what[]) { + boolean outgoing[] = new boolean[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = (what[i] != 0); + } + return outgoing; + } + + static final public boolean[] toBoolean(float what[]) { + boolean outgoing[] = new boolean[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = (what[i] != 0); + } + return outgoing; + } + + static final public boolean[] toBoolean(String what[]) { + boolean outgoing[] = new boolean[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = new Boolean(what[i]).booleanValue(); + } + return outgoing; + } + + // + + static final public byte toByte(boolean what) { + return what ? (byte)1 : 0; + } + + static final public byte toByte(char what) { + return (byte) what; + } + + static final public byte toByte(int what) { + return (byte) what; + } + + static final public byte toByte(float what) { // nonsensical + return (byte) what; + } + + static final public byte[] toByte(String what) { // note: array[] + return what.getBytes(); + } + + // + + static final public byte[] toByte(boolean what[]) { + byte outgoing[] = new byte[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = what[i] ? (byte)1 : 0; + } + return outgoing; + } + + static final public byte[] toByte(char what[]) { + byte outgoing[] = new byte[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = (byte) what[i]; + } + return outgoing; + } + + static final public byte[] toByte(int what[]) { + byte outgoing[] = new byte[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = (byte) what[i]; + } + return outgoing; + } + + static final public byte[] toByte(float what[]) { // nonsensical + byte outgoing[] = new byte[what.length]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = (byte) what[i]; + } + return outgoing; + } + + static final public byte[][] toByte(String what[]) { // note: array[][] + byte outgoing[][] = new byte[what.length][]; + for (int i = 0; i < what.length; i++) { + outgoing[i] = what[i].getBytes(); + } + return outgoing; + } + + // + + static final public char toChar(boolean what) { // 0/1 or T/F ? + return what ? '1' : '0'; + } + + static final public char toChar(int what) { + return (char) what; + } + + static final public char toChar(float what) { // nonsensical + return (char) what; + } + + static final public char[] toChar(String what) { // note: array[] + return what.toCharArray(); + } + + // + static final public int toInt(boolean what) { return what ? 1 : 0; } + static final public int toInt(byte what) { + return what; + } + + static final public int toInt(char what) { + return what; + } + + static final public int toInt(float what) { + return (int) what; + } + + static final public int toInt(String what) { + try { + return Integer.parseInt(what); + } catch (NumberFormatException e) { } + return 0; + } + + static final public int toInt(String what, int otherwise) { + try { + return Integer.parseInt(what); + } catch (NumberFormatException e) { } + + return otherwise; + } + + // + static final public int[] toInt(boolean what[]) { int list[] = new int[what.length]; for (int i = 0; i < what.length; i++) { @@ -2613,10 +2777,6 @@ public class PApplet extends Applet return list; } - static final public int toInt(byte what) { - return what; - } - static final public int[] toInt(byte what[]) { int list[] = new int[what.length]; for (int i = 0; i < what.length; i++) { @@ -2625,10 +2785,6 @@ public class PApplet extends Applet return list; } - static final public int toInt(char what) { - return what; - } - static final public int[] toInt(char what[]) { int list[] = new int[what.length]; for (int i = 0; i < what.length; i++) { @@ -2637,10 +2793,6 @@ public class PApplet extends Applet return list; } - static final public int toInt(float what) { - return (int) what; - } - static public int[] toInt(float what[]) { int inties[] = new int[what.length]; for (int i = 0; i < what.length; i++) { @@ -2650,29 +2802,6 @@ public class PApplet extends Applet } - /** - * Wrapper for tedious Integer.parseInt function - */ - static public int toInt(String what) { - try { - return Integer.parseInt(what); - } catch (NumberFormatException e) { } - return 0; - } - - - /** - * Wrapper for tedious Integer.parseInt function - */ - static public int toInt(String what, int otherwise) { - try { - return Integer.parseInt(what); - } catch (NumberFormatException e) { } - - return otherwise; - } - - /** * Make an array of int elements from an array of String objects. * If the String can't be parsed as a number, it will be set to zero. @@ -2709,10 +2838,22 @@ public class PApplet extends Applet return output; } + // + + // + + static final public String toString(boolean what) { + return what ? "true" : "false"; + } + // ........................................................... + static final public float toFloat(boolean what) { + return what ? 1 : 0; + } + /** * Wrapper for tedious new Float(string).floatValue(). */ @@ -2782,6 +2923,9 @@ public class PApplet extends Applet } + // ........................................................... + + /** * Wrapper for tedious Long.parseLong(). */ diff --git a/processing/todo.txt b/processing/todo.txt index 8cd403eeb..d05dce9fc 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -23,6 +23,8 @@ o readUntil() should do the proper thing if the data is not available o i.e. either return null, or block until it's available? -> ret null X "paste" isn't setting the "modified" bit for PdeEditor X i.e. cut -> new file -> paste doesn't mark any as changed +X "include all chars" and all the bugs it represents +X working on datatype conversions _ System.out isn't being heard from P* classes _ errors inside those classes also causing weirdness