Skip to content

Commit

Permalink
UIBased: filter improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Aug 23, 2023
1 parent 406a925 commit c680a19
Showing 1 changed file with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.eveningoutpost.dexdrip.models.JoH.msSince;
import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.lastReadingTimestamp;
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS;
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.UiBased;
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getDexCollectionType;
import static com.eveningoutpost.dexdrip.xdrip.gs;
Expand Down Expand Up @@ -210,20 +209,45 @@ String filterString(final String value) {
if (lastPackage == null) return value;
switch (lastPackage) {
default:
return value
.replace("\u00a0"," ")
.replace("\u2060","")
.replace("\\","/")
.replace("mmol/L", "")
.replace("mmol/l", "")
.replace("mg/dL", "")
.replace("mg/dl", "")
.replace("≤", "")
.replace("≥", "")
return (basicFilterString(arrowFilterString(value)))
.trim();
}
}

String basicFilterString(final String value) {
return value
.replace("\u00a0"," ")
.replace("\u2060","")
.replace("\\","/")
.replace("mmol/L", "")
.replace("mmol/l", "")
.replace("mg/dL", "")
.replace("mg/dl", "")
.replace("≤", "")
.replace("≥", "");
}

String arrowFilterString(final String value) {
return filterUnicodeRange(filterUnicodeRange(filterUnicodeRange(filterUnicodeRange(value,
'\u2190', '\u21FF'),
'\u2700', '\u27BF'),
'\u2900', '\u297F'),
'\u2B00', '\u2BFF');
}

public String filterUnicodeRange(final String input, final char bottom, final char top) {
if (bottom > top) {
throw new RuntimeException("bottom and top of character range invalid");
}
val filtered = new StringBuilder(input.length());
for (final char c : input.toCharArray()) {
if (c < bottom || c > top) {
filtered.append(c);
}
}
return filtered.toString();
}

@SuppressWarnings("UnnecessaryLocalVariable")
private void processRemote(final RemoteViews cview) {
if (cview == null) return;
Expand Down

0 comments on commit c680a19

Please sign in to comment.