commit
cbdd0699ec
|
@ -1,5 +1,8 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
|
||||
import info.nightscout.utils.StringUtils;
|
||||
|
||||
public class EventNetworkChange extends Event {
|
||||
|
||||
public boolean mobileConnected = false;
|
||||
|
@ -9,6 +12,6 @@ public class EventNetworkChange extends Event {
|
|||
public boolean roaming = false;
|
||||
|
||||
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