fixes #1130
This commit is contained in:
parent
de2273836e
commit
e32f33a8d3
3 changed files with 46 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
||||||
package info.nightscout.androidaps.events;
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
|
||||||
|
import info.nightscout.utils.StringUtils;
|
||||||
|
|
||||||
public class EventNetworkChange extends Event {
|
public class EventNetworkChange extends Event {
|
||||||
|
|
||||||
public boolean mobileConnected = false;
|
public boolean mobileConnected = false;
|
||||||
|
@ -9,6 +12,6 @@ public class EventNetworkChange extends Event {
|
||||||
public boolean roaming = false;
|
public boolean roaming = false;
|
||||||
|
|
||||||
public String getSsid() {
|
public String getSsid() {
|
||||||
return ssid.replace("SSID: ","").replaceAll("\"","");
|
return StringUtils.removeSurroundingQuotes(ssid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
app/src/main/java/info/nightscout/utils/StringUtils.java
Normal file
20
app/src/main/java/info/nightscout/utils/StringUtils.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package info.nightscout.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class contains useful String functions
|
||||||
|
*/
|
||||||
|
public class StringUtils {
|
||||||
|
|
||||||
|
private StringUtils() {
|
||||||
|
// this constructor is private, since this class should not get instantiated
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String removeSurroundingQuotes(String string) {
|
||||||
|
if (string.length() >= 2 && string.charAt(0) == '"'
|
||||||
|
&& string.charAt(string.length() - 1) == '"') {
|
||||||
|
string = string.substring(1, string.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
22
app/src/test/java/info/nightscout/utils/StringUtilsTest.java
Normal file
22
app/src/test/java/info/nightscout/utils/StringUtilsTest.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package info.nightscout.utils;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class StringUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeSurroundingQuotesTest() {
|
||||||
|
String compareString = "test";
|
||||||
|
|
||||||
|
assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString));
|
||||||
|
assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""));
|
||||||
|
assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString));
|
||||||
|
|
||||||
|
compareString = "te\"st";
|
||||||
|
assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString));
|
||||||
|
assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""));
|
||||||
|
assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue