List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:Main.java
private static String getTagName(String buffer) { // Sample buffer format: // NO '<'/*from w w w . j a v a2 s . c o m*/ // tagName att1="value" att2="value" // NO '>' StringBuffer tagName = new StringBuffer(); // The tag name is every non-whitespace character in the buffer until // a whitespace character is encountered for (int i = 0; i < buffer.length(); i++) { char character = buffer.charAt(i); if (Character.isWhitespace(character)) { break; } tagName.append(character); } return tagName.toString(); }
From source file:de.micromata.genome.gwiki.plugin.wikilink_1_0.GWikiWikiLinkFragment.java
public static GWikiFragment parseText(GWikiFragmentText textFrag) { String text = textFrag.getSource(); ParseState state = ParseState.Start; int startLink = 0; GWikiFragmentChildContainer fcc = new GWikiFragmentChildContainer(); boolean startWord = true; for (int i = 0; i < text.length(); ++i) { char c = text.charAt(i); switch (state) { case Start: boolean ws = Character.isWhitespace(c); if (ws == true || Character.isLetter(c) == false) { // addTextFrag(fcc, text.substring(startLink, i)); // startLink = i; startWord = ws;/* ww w . ja v a2 s . c om*/ continue; } if (startWord == true && Character.isUpperCase(c) == true) { if (startLink != i) { addTextFrag(fcc, text.substring(startLink, i)); } startLink = i; state = ParseState.InWikiLink; break; } startWord = ws; break; case InWikiLink: if (Character.isLetter(c) == false) { String k = text.substring(startLink, i); if (isWikiLinkWord(k) == true) { fcc.addChild(new GWikiWikiLinkFragment(k)); } else { addTextFrag(fcc, k); } startLink = i; state = ParseState.Start; } break; } } if (startLink < text.length()) { String k = text.substring(startLink); if (state == ParseState.InWikiLink && isWikiLinkWord(k) == true) { fcc.addChild(new GWikiWikiLinkFragment(k)); } else { addTextFrag(fcc, k); } } return unfoldParsed(fcc); }
From source file:Main.java
/** * Performs the logic for the <code>split</code> and * <code>splitPreserveAllTokens</code> methods that return a maximum array * length./*w w w .j ava 2 s. com*/ * * @param str the String to parse, may be <code>null</code> * @param separatorChars the separate character * @param max the maximum number of elements to include in the * array. A zero or negative value implies no limit. * @param preserveAllTokens if <code>true</code>, adjacent separators are * treated as empty token separators; if <code>false</code>, adjacent * separators are treated as one separator. * @return an array of parsed Strings, <code>null</code> if null String input */ private static String[] splitWorker(String str, String separatorChars, int max, boolean preserveAllTokens) { // Performance tuned for 2.0 (JDK1.4) // Direct code is quicker than StringTokenizer. // Also, StringTokenizer uses isSpace() not isWhitespace() if (str == null) { return null; } int len = str.length(); if (len == 0) { return new String[0]; } List list = new ArrayList(); int sizePlus1 = 1; int i = 0, start = 0; boolean match = false; boolean lastMatch = false; if (separatorChars == null) { // Null separator means use whitespace while (i < len) { if (Character.isWhitespace(str.charAt(i))) { if (match || preserveAllTokens) { lastMatch = true; if (sizePlus1++ == max) { i = len; lastMatch = false; } list.add(str.substring(start, i)); match = false; } start = ++i; continue; } lastMatch = false; match = true; i++; } } else if (separatorChars.length() == 1) { // Optimise 1 character case char sep = separatorChars.charAt(0); while (i < len) { if (str.charAt(i) == sep) { if (match || preserveAllTokens) { lastMatch = true; if (sizePlus1++ == max) { i = len; lastMatch = false; } list.add(str.substring(start, i)); match = false; } start = ++i; continue; } lastMatch = false; match = true; i++; } } else { // standard case while (i < len) { if (separatorChars.indexOf(str.charAt(i)) >= 0) { if (match || preserveAllTokens) { lastMatch = true; if (sizePlus1++ == max) { i = len; lastMatch = false; } list.add(str.substring(start, i)); match = false; } start = ++i; continue; } lastMatch = false; match = true; i++; } } if (match || (preserveAllTokens && lastMatch)) { list.add(str.substring(start, i)); } return (String[]) list.toArray(new String[list.size()]); }
From source file:com.medallia.tiny.Strings.java
/** Return the given string with any white space on the left side removed */ public static String trimLeft(String s) { int k = 0;//from w ww . j a v a 2 s . co m while (k < s.length() && Character.isWhitespace(s.charAt(k))) k++; return s.substring(k, s.length()); }
From source file:com.puppycrawl.tools.checkstyle.utils.CommonUtils.java
/** * Returns whether the specified string contains only whitespace up to the specified index. * * @param index/* w w w .ja v a2 s . c o m*/ * index to check up to * @param line * the line to check * @return whether there is only whitespace */ public static boolean hasWhitespaceBefore(int index, String line) { for (int i = 0; i < index; i++) { if (!Character.isWhitespace(line.charAt(i))) { return false; } } return true; }
From source file:com.hp.alm.ali.idea.translate.expr.Lexer.java
private boolean allowedInLiteral(char c) { return !Character.isWhitespace(c) && c != '(' && c != ')' && c != '<' && c != '>' && c != '=' && c != '"' && c != '\''; }
From source file:Undent.java
/** undent one file, given an open BufferedReader. * Undent by removing UP TO "nSpaces" leading spaces. *//* w w w . j a v a2 s .c om*/ public void process(BufferedReader is) { //+ // GRRR THIS DOES NOT QUITE WORK - FIX -- Ian try { String inputLine; while ((inputLine = is.readLine()) != null) { int i; for (i = 0; i < nSpaces; i++) { if (!Character.isWhitespace(inputLine.charAt(i))) break; } System.out.println(inputLine.substring(i)); } is.close(); //- } catch (IOException e) { System.out.println("IOException: " + e); } }
From source file:com.github.rvesse.airline.io.printers.UsagePrinter.java
public static String trimEnd(final String str) { if (StringUtils.isEmpty(str)) { return str; }/*from w ww.j av a2s . c om*/ int end = str.length(); while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { end--; } return str.substring(0, end); }
From source file:com.jaeksoft.searchlib.util.StringUtils.java
public static final String replaceConsecutiveSpaces(String source, String replace) { StringBuilder target = new StringBuilder(); int l = source.length(); boolean consecutiveSpace = false; for (int i = 0; i < l; i++) { char c = source.charAt(i); if (Character.isWhitespace(c)) { if (!consecutiveSpace) { if (replace != null) target.append(replace); consecutiveSpace = true; }//w w w .j av a2s .c o m } else { target.append(c); if (consecutiveSpace) consecutiveSpace = false; } } return target.toString(); }