Small fix in the VCF parser (now a bit quicker) and --help (--noutfa
authorNiki Roo <niki@nikiroo.be>
Fri, 4 Mar 2016 10:51:14 +0000 (11:51 +0100)
committerNiki Roo <niki@nikiroo.be>
Fri, 4 Mar 2016 10:51:14 +0000 (11:51 +0100)
does not exist anymore)

src/be/nikiroo/jvcard/parsers/Vcard21Parser.java
src/be/nikiroo/jvcard/tui/Main.java
src/be/nikiroo/jvcard/tui/StringUtils.java

index f2fd07c5aef8a750bce8db49074113bfadb1ce72..6d8b2babc14ca9de578ab4d4b15157e628a7ecad 100644 (file)
@@ -64,8 +64,9 @@ public class Vcard21Parser {
                                        String group = "";
 
                                        if (line.contains(":")) {
-                                               String rest = line.split(":")[0];
-                                               value = line.substring(rest.length() + 1);
+                                               int colIndex = line.indexOf(':');
+                                               String rest = line.substring(0, colIndex);
+                                               value = line.substring(colIndex + 1);
 
                                                if (rest.contains(";")) {
                                                        String tab[] = rest.split(";");
@@ -73,9 +74,11 @@ public class Vcard21Parser {
 
                                                        for (int i = 1; i < tab.length; i++) {
                                                                if (tab[i].contains("=")) {
-                                                                       String tname = tab[i].split("=")[0];
-                                                                       String tvalue = tab[i].substring(tname
-                                                                                       .length() + 1);
+                                                                       int equIndex = tab[i].indexOf('=');
+                                                                       String tname = tab[i]
+                                                                                       .substring(0, equIndex);
+                                                                       String tvalue = tab[i]
+                                                                                       .substring(equIndex + 1);
                                                                        types.add(new TypeInfo(tname, tvalue));
                                                                } else {
                                                                        types.add(new TypeInfo(tab[i], ""));
@@ -89,8 +92,9 @@ public class Vcard21Parser {
                                        }
 
                                        if (name.contains(".")) {
-                                               group = name.split("\\.")[0];
-                                               name = name.substring(group.length() + 1);
+                                               int dotIndex = name.indexOf('.');
+                                               group = name.substring(0, dotIndex);
+                                               name = name.substring(dotIndex + 1);
                                        }
 
                                        datas.add(new Data(types, name, value, group));
index fd6d7de4e6e4e5583a36f742ff44fbb65ef277f2..4c3f7623b96828ad1fd9573efadc9735f1c55cec 100644 (file)
@@ -89,7 +89,6 @@ public class Main {
                                                                + "\t--tui: force pure text mode even if swing treminal is available\n"
                                                                + "\t--gui: force swing terminal mode\n"
                                                                + "\t--noutf: force non-utf8 mode if you need it\n"
-                                                               + "\t--noutfa: force non-utf8 and no accents mode if you need it\n"
                                                                + "everyhing else is either a file to open or a directory to open\n"
                                                                + "(we will only open 1st level files in given directories)");
                                return;
index 3f5d22b2eb283a6a6fa43253affe3b0410408ee0..382922605260260c8f4998da741757d277ba9f4d 100644 (file)
@@ -9,7 +9,6 @@ import com.googlecode.lanterna.gui2.LinearLayout.Alignment;
 public class StringUtils {
        static private Pattern marks = Pattern
                        .compile("[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+");
-       static private Pattern notAscii = Pattern.compile("[^\\p{ASCII}]+");
 
        /**
         * Fix the size of the given {@link String} either with space-padding or by
@@ -122,7 +121,16 @@ public class StringUtils {
                input = Normalizer.normalize(input, Form.NFKC);
 
                if (!allowUnicode) {
-                       input = notAscii.matcher(input).replaceAll("");
+                       StringBuilder builder = new StringBuilder();
+                       for (int index = 0; index < input.length(); index++) {
+                               char car = input.charAt(index);
+                               // displayable chars in ASCII are in the range 32<->255,
+                               // except DEL (127)
+                               if (car >= 32 && car <= 255 && car != 127) {
+                                       builder.append(car);
+                               }
+                       }
+                       input = builder.toString();
                }
 
                return input;