List of usage examples for java.lang CharSequence subSequence
CharSequence subSequence(int start, int end);
From source file:Main.java
public static void main(String[] argv) throws Exception { CharSequence inputStr = "abbabcd"; String patternStr = "(a(b*))+(c*)"; Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(inputStr); boolean matchFound = matcher.find(); if (matchFound) { // Get all groups for this match for (int i = 0; i <= matcher.groupCount(); i++) { // Get the group's captured text String groupStr = matcher.group(i); // Get the group's indices int groupStart = matcher.start(i); int groupEnd = matcher.end(i); // groupStr is equivalent to inputStr.subSequence(groupStart, groupEnd); }/*from w w w .j ava 2 s .c o m*/ } }
From source file:Main.java
/** * <p>Returns a new {@code CharSequence} that is a subsequence of this * sequence starting with the {@code char} value at the specified index.</p> * * <p>This provides the {@code CharSequence} equivalent to {@link String#substring(int)}. * The length (in {@code char}) of the returned sequence is {@code length() - start}, * so if {@code start == end} then an empty sequence is returned.</p> * * @param cs the specified subsequence, null returns null * @param start the start index, inclusive, valid * @return a new subsequence, may be null * @throws IndexOutOfBoundsException if {@code start} is negative or if * {@code start} is greater than {@code length()} */// w w w .j a v a2 s. c o m public static CharSequence subSequence(CharSequence cs, int start) { return cs == null ? null : cs.subSequence(start, cs.length()); }
From source file:Main.java
public static CharSequence trimTrailingWhitespace(CharSequence text) { while (text.charAt(text.length() - 1) == '\n') { text = text.subSequence(0, text.length() - 1); }/*from w ww . j av a 2 s.co m*/ return text; }
From source file:Main.java
/** * <p>Returns a new {@code CharSequence} that is a subsequence of this * sequence starting with the {@code char} value at the specified index.</p> * <p>//from w ww .j a v a 2 s.com * <p>This provides the {@code CharSequence} equivalent to {@link String#substring(int)}. * The length (in {@code char}) of the returned sequence is {@code length() - start}, * so if {@code start == end} then an empty sequence is returned.</p> * * @param cs the specified subsequence, null returns null * @param start the start index, inclusive, valid * @return a new subsequence, may be null * @throws IndexOutOfBoundsException if {@code start} is negative or if * {@code start} is greater than {@code length()} */ public static CharSequence subSequence(final CharSequence cs, final int start) { return cs == null ? null : cs.subSequence(start, cs.length()); }
From source file:Main.java
public static CharSequence getTrimmedString(CharSequence src) { if (src == null || src.length() == 0) { return src; }/*from www.j a v a 2 s . com*/ while (src.length() > 0 && (src.charAt(0) == '\n' || src.charAt(0) == ' ')) { src = src.subSequence(1, src.length()); } while (src.length() > 0 && (src.charAt(src.length() - 1) == '\n' || src.charAt(src.length() - 1) == ' ')) { src = src.subSequence(0, src.length() - 1); } return src; }
From source file:com.slothpetrochemical.bridgeprob.BridgeProblemSignature.java
private static CharSequence stripFlashlight(final CharSequence seq) { int lastIdx = StringUtils.lastIndexOf(seq, FLASHLIGHT); return lastIdx >= 0 ? seq.subSequence(0, lastIdx) : seq; }
From source file:Main.java
public static CharSequence[] split(CharSequence string, String pattern) { String[] parts = string.toString().split(pattern); List<CharSequence> res = new ArrayList<>(); CharSequence temp = string;//from w ww.j a v a2s .c o m int pos = 0; for (String part : parts) { res.add(string.subSequence(pos, pos + part.length())); pos += part.length(); } return res.toArray(new CharSequence[res.size()]); }
From source file:Main.java
public static CharSequence trimTrailingWhitespace(CharSequence source) { if (source == null) return ""; int i = source.length(); // loop back to the first non-whitespace character while (--i >= 0 && Character.isWhitespace(source.charAt(i))) { }//from www. ja va 2s. c om return source.subSequence(0, i + 1); }
From source file:com.keylesspalace.tusky.util.LinkHelper.java
/** * Finds links, mentions, and hashtags in a piece of text and makes them clickable, associating * them with callbacks to notify when they're clicked. * * @param view the returned text will be put in * @param content containing text with mentions, links, or hashtags * @param mentions any '@' mentions which are known to be in the content * @param listener to notify about particular spans that are clicked *//* w w w . jav a 2s .c om*/ public static void setClickableText(TextView view, Spanned content, @Nullable Status.Mention[] mentions, final LinkListener listener) { SpannableStringBuilder builder = new SpannableStringBuilder(content); URLSpan[] urlSpans = content.getSpans(0, content.length(), URLSpan.class); for (URLSpan span : urlSpans) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); int flags = builder.getSpanFlags(span); CharSequence text = builder.subSequence(start, end); if (text.charAt(0) == '#') { final String tag = text.subSequence(1, text.length()).toString(); ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewTag(tag); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } else if (text.charAt(0) == '@' && mentions != null && mentions.length > 0) { String accountUsername = text.subSequence(1, text.length()).toString(); /* There may be multiple matches for users on different instances with the same * username. If a match has the same domain we know it's for sure the same, but if * that can't be found then just go with whichever one matched last. */ String id = null; for (Status.Mention mention : mentions) { if (mention.localUsername.equalsIgnoreCase(accountUsername)) { id = mention.id; if (mention.url.contains(getDomain(span.getURL()))) { break; } } } if (id != null) { final String accountId = id; ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewAccount(accountId); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } else { ClickableSpan newSpan = new CustomURLSpan(span.getURL()); builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } view.setText(builder); view.setLinksClickable(true); view.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.kstenschke.shifter.utils.UtilsTextual.java
/** * @param text Text containing the sequence * @param offsetStart Sub sequence start character offset * @param offsetEnd Sub sequence end character offset * @return Sub sequence of given offsets out of given text *///from ww w . j a va 2s .co m public static String getSubString(CharSequence text, int offsetStart, int offsetEnd) { if (text.length() == 0) return null; return text.subSequence(offsetStart, offsetEnd).toString(); }