Small style stuff
[zxing.git] / android / src / com / google / zxing / client / android / wifi / NetworkUtil.java
index 9a84d43..6463435 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.google.zxing.client.android.wifi;
 
+import java.util.regex.Pattern;
+
 import android.text.TextUtils;
 
 /**
@@ -28,6 +30,8 @@ import android.text.TextUtils;
  */
 final class NetworkUtil {
 
+  private static final Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+");
+
   private NetworkUtil() {
   }
 
@@ -46,21 +50,8 @@ final class NetworkUtil {
     int lastPos = string.length() - 1;
     if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
       return string;
-    }        
-    return '\"' + string + '\"';
-  }
-
-  private static boolean isHex(CharSequence key) {
-    if (key == null){
-      return false;
     }
-    for (int i = key.length() - 1; i >= 0; i--) {
-      char c = key.charAt(i);
-      if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
-        return false;
-      }
-    }        
-    return true;
+    return '\"' + string + '\"';
   }
 
   /**
@@ -72,9 +63,9 @@ final class NetworkUtil {
     if (wepKey == null) {
       return false;
     }
-    int len = wepKey.length();
+    int length = wepKey.length();
     // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
-    return (len == 10 || len == 26 || len == 58) && isHex(wepKey);
+    return (length == 10 || length == 26 || length == 58) && HEX_DIGITS.matcher(wepKey).matches();
   }
 
-}
+}
\ No newline at end of file