List of usage examples for java.lang CharSequence length
int length();
From source file:Strings.java
/** * Returns the string constructed from the specified character * sequence by deaccenting each of its characters. See {@link * #deAccentLatin1(char)} for details of the de-accenting. * * @param cSeq Character sequence to de accent. * @return De-accented version of input. *///from w ww . ja v a2 s .c o m public static String deAccentLatin1(CharSequence cSeq) { char[] cs = new char[cSeq.length()]; for (int i = 0; i < cs.length; ++i) cs[i] = deAccentLatin1(cSeq.charAt(i)); return new String(cs); }
From source file:Main.java
/** * <p>Finds the first index in the {@code CharSequence} that matches the * specified character.</p>//from w w w .j a v a2 s .c o m * * @param cs the {@code CharSequence} to be processed, not null * @param searchChar the char to be searched for * @param start the start index, negative starts at the string start * @return the index where the search char was found, -1 if not found */ static int indexOf(CharSequence cs, int searchChar, int start) { if (cs instanceof String) { return ((String) cs).indexOf(searchChar, start); } else { int sz = cs.length(); if (start < 0) { start = 0; } for (int i = start; i < sz; i++) { if (cs.charAt(i) == searchChar) { return i; } } return -1; } }
From source file:Main.java
/** * <p>Finds the first index in the {@code CharSequence} that matches the * specified character.</p>//from w w w . j ava 2s.com * * @param cs the {@code CharSequence} to be processed, not null * @param searchChar the char to be searched for * @param start the start index, negative starts at the string start * @return the index where the search char was found, -1 if not found */ static int indexOf(final CharSequence cs, final int searchChar, int start) { if (cs instanceof String) { return ((String) cs).indexOf(searchChar, start); } final int sz = cs.length(); if (start < 0) { start = 0; } for (int i = start; i < sz; i++) { if (cs.charAt(i) == searchChar) { return i; } } return NOT_FOUND; }
From source file:Main.java
/** * <p>Finds the last index in the {@code CharSequence} that matches the * specified character.</p>/* w ww . j a va 2 s . c om*/ * * @param cs the {@code CharSequence} to be processed * @param searchChar the char to be searched for * @param start the start index, negative returns -1, beyond length starts at end * @return the index where the search char was found, -1 if not found */ static int lastIndexOf(CharSequence cs, int searchChar, int start) { if (cs instanceof String) { return ((String) cs).lastIndexOf(searchChar, start); } else { int sz = cs.length(); if (start < 0) { return -1; } if (start >= sz) { start = sz - 1; } for (int i = start; i >= 0; --i) { if (cs.charAt(i) == searchChar) { return i; } } return -1; } }
From source file:Main.java
/** * <p>Finds the last index in the {@code CharSequence} that matches the * specified character.</p>// ww w.ja va 2 s. co m * * @param cs the {@code CharSequence} to be processed * @param searchChar the char to be searched for * @param start the start index, negative returns -1, beyond length starts at end * @return the index where the search char was found, -1 if not found */ static int lastIndexOf(final CharSequence cs, final int searchChar, int start) { if (cs instanceof String) { return ((String) cs).lastIndexOf(searchChar, start); } final int sz = cs.length(); if (start < 0) { return NOT_FOUND; } if (start >= sz) { start = sz - 1; } for (int i = start; i >= 0; --i) { if (cs.charAt(i) == searchChar) { return i; } } return NOT_FOUND; }
From source file:Main.java
/** * <p>Finds the first index in the {@code CharSequence} that matches the * specified character.</p>// w w w .ja va 2s .co m * * @param cs the {@code CharSequence} to be processed, not null * @param searchChar the char to be searched for * @param start the start index, negative starts at the string start * @return the index where the search char was found, -1 if not found */ static int indexOf(final CharSequence cs, final int searchChar, int start) { if (cs instanceof String) { return ((String) cs).indexOf(searchChar, start); } else { final int sz = cs.length(); if (start < 0) { start = 0; } for (int i = start; i < sz; i++) { if (cs.charAt(i) == searchChar) { return i; } } return -1; } }
From source file:Main.java
/** * Checks whether the supplied String is an NCName (Namespace Classified * Name) as specified at <a//from ww w. j av a2 s . co m * href="http://www.w3.org/TR/REC-xml-names/#NT-NCName"> * http://www.w3.org/TR/REC-xml-names/#NT-NCName</a>. */ public static boolean isNCName(CharSequence name) { int nameLength = name.length(); if (nameLength == 0) { return false; } // Check first character char c = name.charAt(0); if (c == '_' || isLetter(c)) { // Check the rest of the characters for (int i = 1; i < nameLength; i++) { c = name.charAt(i); if (!isNCNameChar(c)) { return false; } } // All characters have been checked return true; } return false; }
From source file:Main.java
/** * <p>Finds the last index in the {@code CharSequence} that matches the * specified character.</p>/*from ww w. java 2 s . c o m*/ * * @param cs the {@code CharSequence} to be processed * @param searchChar the char to be searched for * @param start the start index, negative returns -1, beyond length starts at end * @return the index where the search char was found, -1 if not found */ static int lastIndexOf(final CharSequence cs, final int searchChar, int start) { if (cs instanceof String) { return ((String) cs).lastIndexOf(searchChar, start); } else { final int sz = cs.length(); if (start < 0) { return -1; } if (start >= sz) { start = sz - 1; } for (int i = start; i >= 0; --i) { if (cs.charAt(i) == searchChar) { return i; } } return -1; } }
From source file:Main.java
/** * Make UI TextView a html link./*from w w w. ja va2 s. c o m*/ * * @param context the context * @param textView the text view * @param html the html containing link info */ public static void makeTextViewAHTMLLink(final Context context, TextView textView, String html) { textView.setLinksClickable(true); textView.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence sequence = Html.fromHtml(html); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sequence); URLSpan[] urls = spannableStringBuilder.getSpans(0, sequence.length(), URLSpan.class); for (final URLSpan urlSpan : urls) { int start = spannableStringBuilder.getSpanStart(urlSpan); int end = spannableStringBuilder.getSpanEnd(urlSpan); int flags = spannableStringBuilder.getSpanFlags(urlSpan); ClickableSpan clickable = new ClickableSpan() { public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlSpan.getURL())); context.startActivity(intent); } @Override public void updateDrawState(TextPaint textPaint) { super.updateDrawState(textPaint); textPaint.setUnderlineText(false); } }; spannableStringBuilder.removeSpan(urlSpan); spannableStringBuilder.setSpan(clickable, start, end, flags); } textView.setText(spannableStringBuilder); }
From source file:Main.java
/** * Replaces successive XML space characters (<tt>'\t'</tt>, * <tt>'\r'</tt>, <tt>'\n'</tt>, <tt>' '</tt>) by a single space * character (<tt>' '</tt>). * //from w ww . j ava2s. co m * @param value string to be processed * @param buffer buffer used to store processed characters (characters are * appended to this buffer) */ private static void compressWhiteSpace(CharSequence value, StringBuffer buffer) { // No need to convert "\r\n" to a single '\n' because white spaces // are compressed. int length = value.length(); char prevChar = '?'; for (int i = 0; i < length; ++i) { char c = value.charAt(i); switch (c) { case '\t': case '\r': case '\n': c = ' '; break; } if (c == ' ') { if (prevChar != ' ') { buffer.append(c); prevChar = c; } } else { buffer.append(c); prevChar = c; } } }