2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.android.wifi;
19 import java.util.regex.Pattern;
21 import android.text.TextUtils;
25 * http://chart.apis.google.com/chart?cht=qr&chs=240x240&chl=WIFI:S:linksys;P:mypass;T:WPA;;
27 * TODO(vikrama): Test with binary ssid or password.
29 * @author Vikram Aggarwal
31 final class NetworkUtil {
33 private static final Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+");
35 private NetworkUtil() {
39 * Encloses the incoming string inside double quotes, if it isn't already quoted.
40 * @param string: the input string
41 * @return a quoted string, of the form "input". If the input string is null, it returns null as well.
43 static String convertToQuotedString(String string) {
47 if (TextUtils.isEmpty(string)) {
50 int lastPos = string.length() - 1;
51 if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
54 return '\"' + string + '\"';
58 * Check if wepKey is a valid hexadecimal string.
59 * @param wepKey the input to be checked
60 * @return true if the input string is indeed hex or empty. False if the input string is non-hex or null.
62 static boolean isHexWepKey(CharSequence wepKey) {
66 int length = wepKey.length();
67 // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
68 return (length == 10 || length == 26 || length == 58) && HEX_DIGITS.matcher(wepKey).matches();