Permalink
Browse files

better matrix validation

  • Loading branch information...
Xlythe committed Feb 7, 2013
1 parent 3426e4c commit 819f437f75c895fc2da66d7ecf86e07d3934d96e
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/com/android2/calculator3/view/MatrixView.java
@@ -19,8 +19,10 @@
public class MatrixView extends TableLayout {
private static String FORMAT = "#.######";
private static DecimalFormat FORMATTER = new DecimalFormat(FORMAT);
- int rows, columns = 0;
- AdvancedDisplay parent;
+ private static final String VALID_MATRIX = "\\[(\\[[\u2212-]?(\\d+(\\.\\d*)?)*(,[\u2212-]?(\\d+(\\.\\d*)?)*)*\\])+\\].*";
+
+ private int rows, columns = 0;
+ private AdvancedDisplay parent;
public MatrixView(Context context) {
super(context);
@@ -252,7 +254,7 @@ public static boolean load(final MutableString text, final AdvancedDisplay paren
}
private static boolean verify(MutableString text) {
- return text.startsWith("[[");
+ return text.getText().matches(VALID_MATRIX);
}
private static int countOccurrences(String haystack, char needle) {

0 comments on commit 819f437

Please sign in to comment.