Skip to content

Commit

Permalink
better matrix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlythe committed Feb 7, 2013
1 parent 3426e4c commit 819f437
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/com/android2/calculator3/view/MatrixView.java
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 819f437

Please sign in to comment.