diff options
Diffstat (limited to 'gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Util.java')
-rw-r--r-- | gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Util.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Util.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Util.java index 98f13ef5a6..804eee1f8a 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Util.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Util.java @@ -15,7 +15,35 @@ package com.google.gerrit.client.ui; import com.google.gwt.core.client.GWT; +import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder; public class Util { public static final UIConstants C = GWT.create(UIConstants.class); + public static final UIMessages M = GWT.create(UIMessages.class); + + public static String highlight(final String text, final String toHighlight) { + final SafeHtmlBuilder b = new SafeHtmlBuilder(); + if (toHighlight == null || "".equals(toHighlight)) { + b.append(text); + return b.toSafeHtml().asString(); + } + + int pos = 0; + int endPos = 0; + while ((pos = text.toLowerCase().indexOf( + toHighlight.toLowerCase(), pos)) > -1) { + if (pos > endPos) { + b.append(text.substring(endPos, pos)); + } + endPos = pos + toHighlight.length(); + b.openElement("b"); + b.append(text.substring(pos, endPos)); + b.closeElement("b"); + pos = endPos; + } + if (endPos < text.length()) { + b.append(text.substring(endPos)); + } + return b.toSafeHtml().asString(); + } } |