diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-04-07 23:00:40 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-04-07 23:00:40 +0200 |
commit | b77688107ce20d8363275f7d005742a0e599b7aa (patch) | |
tree | 99bb6bf303e4d3d0859364f0e3f75a3167dcf9db /src/main/java/de/pixart/messenger | |
parent | 19e8116742267235a222b83abbc99ad2ce5d2895 (diff) |
make unicode detector work on labels
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java b/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java index 2e7f221c9..385137c7b 100644 --- a/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java +++ b/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java @@ -86,16 +86,14 @@ public class IrregularUnicodeDetector { builder.append('@'); } if (jid.getDomain() != null) { - int i = jid.getDomain().lastIndexOf('.'); - if (i != -1) { - String second = jid.getDomain().substring(0, i); - String top = jid.getDomain().substring(i, jid.getDomain().length()); - SpannableString secondSpannableString = new SpannableString(second); - colorize(secondSpannableString, patternTuple.domain, color); - builder.append(secondSpannableString); - builder.append(top); - } else { - builder.append(jid.getDomain()); + String[] labels = jid.getDomain().split("\\."); + for (int i = 0; i < labels.length; ++i) { + SpannableString spannableString = new SpannableString(labels[i]); + colorize(spannableString, patternTuple.domain.get(i), color); + if (i != 0) { + builder.append('.'); + } + builder.append(spannableString); } } if (builder.length() != 0 && jid.getResource() != null) { @@ -217,9 +215,9 @@ public class IrregularUnicodeDetector { private static class PatternTuple { private final Pattern local; - private final Pattern domain; + private final List<Pattern> domain; - private PatternTuple(Pattern local, Pattern domain) { + private PatternTuple(Pattern local, List<Pattern> domain) { this.local = local; this.domain = domain; } @@ -232,19 +230,13 @@ public class IrregularUnicodeDetector { localPattern = null; } String domain = jid.getDomain(); - final Pattern domainPattern; + final List<Pattern> domainPatterns = new ArrayList<>(); if (domain != null) { - int i = domain.lastIndexOf('.'); - if (i != -1) { - String secondLevel = domain.substring(0, i); - domainPattern = create(findIrregularCodePoints(secondLevel)); - } else { - domainPattern = null; + for (String label : domain.split("\\.")) { + domainPatterns.add(create(findIrregularCodePoints(label))); } - } else { - domainPattern = null; } - return new PatternTuple(localPattern, domainPattern); + return new PatternTuple(localPattern, domainPatterns); } } }
\ No newline at end of file |