List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:com.dubture.composer.test.ComposerCoreTestPlugin.java
/** * Compares expected result with the actual ingoring whitespace characters * /*w w w . jav a2 s . c om*/ * @param expected * @param actual * @return difference string or <code>null</code> in case expected result is * equal to the actual. */ public static String compareContentsIgnoreWhitespace(String expected, String actual) { String tmpExpected = expected; String tmpActual = actual; String diff = StringUtils.difference(tmpExpected, tmpActual); while (diff.length() > 0) { String diff2 = StringUtils.difference(tmpActual, tmpExpected); if (!Character.isWhitespace(diff.charAt(0)) && !Character.isWhitespace(diff2.charAt(0))) { int expectedDiff = StringUtils.indexOfDifference(tmpActual, tmpExpected) + (expected.length() - tmpExpected.length()); int actualDiff = StringUtils.indexOfDifference(tmpExpected, tmpActual) + (actual.length() - tmpActual.length()); return getDiffError(expected, actual, expectedDiff, actualDiff); } tmpActual = diff.trim(); tmpExpected = diff2.trim(); diff = StringUtils.difference(tmpExpected, tmpActual); } return null; }
From source file:com.novartis.pcs.ontology.service.parser.obo.SynonymTagHandler.java
private Synonym.Type parseType(String value, MutableInt fromIndex) { Synonym.Type type = Synonym.Type.RELATED; while (fromIndex.intValue() < value.length() && Character.isWhitespace(value.charAt(fromIndex.intValue()))) { fromIndex.increment();/*from w w w . ja v a 2 s . co m*/ } int start = fromIndex.intValue(); while (fromIndex.intValue() < value.length() && Character.isLetter(value.charAt(fromIndex.intValue()))) { fromIndex.increment(); } if (start < fromIndex.intValue()) { String scope = value.substring(start, fromIndex.intValue()); try { type = Synonym.Type.valueOf(scope.toUpperCase()); } catch (IllegalArgumentException e) { type = Synonym.Type.RELATED; fromIndex.setValue(start); } } return type; }
From source file:com.dsj.core.beans.StringUtils.java
/** * Check if a String has text. More specifically, returns <code>true</code> * if the string not <code>null<code>, it's <code>length is > 0</code>, and * it has at least one non-whitespace character. * <p><pre>//from w w w . ja v a 2 s.c o m * StringUtils.hasText(null) = false * StringUtils.hasText("") = false * StringUtils.hasText(" ") = false * StringUtils.hasText("12345") = true * StringUtils.hasText(" 12345 ") = true * </pre> * @param str the String to check, may be <code>null</code> * @return <code>true</code> if the String is not null, length > 0, * and not whitespace only * @see java.lang.Character#isWhitespace */ public static boolean hasText(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return false; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
From source file:com.xie.javacase.json.XMLTokener.java
/** * Get the next XML outer token, trimming whitespace. There are two kinds * of tokens: the '<' character which begins a markup tag, and the content * text between markup tags./*from w ww . j a va 2 s .c o m*/ * * @return A string, or a '<' Character, or null if there is no more * source text. * @throws org.json.JSONException */ public Object nextContent() throws JSONException { char c; StringBuffer sb; do { c = next(); } while (Character.isWhitespace(c)); if (c == 0) { return null; } if (c == '<') { return XML.LT; } sb = new StringBuffer(); for (;;) { if (c == '<' || c == 0) { back(); return sb.toString().trim(); } if (c == '&') { sb.append(nextEntity(c)); } else { sb.append(c); } c = next(); } }
From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.java
/** * Process a token representing a left parentheses. * @param ast the token representing a left parentheses *///w w w . j a v a 2 s . c om protected void processLeft(DetailAST ast) { final String line = getLines()[ast.getLineNo() - 1]; final int after = ast.getColumnNo() + 1; if (after < line.length()) { if (option == PadOption.NOSPACE && Character.isWhitespace(line.charAt(after))) { log(ast.getLineNo(), after, WS_FOLLOWED, OPEN_PARENTHESIS); } else if (option == PadOption.SPACE && !Character.isWhitespace(line.charAt(after)) && line.charAt(after) != CLOSE_PARENTHESIS) { log(ast.getLineNo(), after, WS_NOT_FOLLOWED, OPEN_PARENTHESIS); } } }
From source file:com.reprezen.swagedit.editor.SwaggerDocument.java
/** * Returns position of the symbol ':' in respect to the given offset. * //www . j a v a2 s.co m * Will return -1 if reaches beginning of line of other symbol before finding ':'. * * @param offset * @return position */ public int getDelimiterPosition(int offset) { while (true) { try { char c = getChar(--offset); if (Character.isLetterOrDigit(c)) { return -1; } if (c == ':') { return offset; } if (Character.isWhitespace(c)) { continue; } if (c != ':' && !Character.isLetterOrDigit(c)) { return -1; } } catch (BadLocationException e) { return -1; } } }
From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceBeforeCheck.java
@Override public void visitToken(DetailAST ast) { final String line = getLine(ast.getLineNo() - 1); final int before = ast.getColumnNo() - 1; if ((before < 0 || Character.isWhitespace(line.charAt(before))) && !isInEmptyForInitializer(ast)) { boolean flag = !allowLineBreaks; // verify all characters before '.' are whitespace for (int i = 0; !flag && i < before; i++) { if (!Character.isWhitespace(line.charAt(i))) { flag = true;// w w w . j ava 2s. c om } } if (flag) { log(ast.getLineNo(), before, MSG_KEY, ast.getText()); } } }
From source file:de.micromata.genome.gwiki.utils.CommaListParser.java
/** * Parses the comma list./* w w w. j av a 2 s. c o m*/ * * @param input the input * @param trimValues the trim values * @return the list */ public static List<String> parseCommaList(String input, boolean trimValues) { if (input == null || input.length() == 0) { return Collections.emptyList(); } List<String> ret = new ArrayList<String>(); int lastBegin = 0; State state = State.StartField; loop: for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); switch (state) { case StartField: if (trimValues == true && Character.isWhitespace(c) == true) { lastBegin = i + 1; continue; } if (c == ',') { ret.add(""); lastBegin = i + 1; continue; } if (c == '"') { lastBegin = i + 1; state = State.InQuotedField; continue; } state = State.InField; lastBegin = i; break; case InField: if (c == ',') { int lc = i; if (trimValues == true) { lc = seekNonWsBack(input, lc - 1); } ret.add(input.substring(lastBegin, lc)); state = State.StartField; continue; } continue; case InQuotedField: if (c == '\\') { if (i + 1 >= input.length()) { ret.add(input.substring(lastBegin, i + 1)); break loop; } char nc = input.charAt(i + 1); if (nc == '\"' || nc == '\\') { ++i; continue; } continue; } else if (c == '"') { String t = input.substring(lastBegin, i); t = unquote(t); ret.add(t); i = skeepWs(input, i + 1); if (i >= input.length()) { lastBegin = i; break loop; } char c2 = input.charAt(i); if (c2 != ',') { throw new RuntimeException("In Input at position " + i + " expects ',', got: " + c2); } ++i; lastBegin = i; state = State.StartField; } break; } } if (lastBegin < input.length()) { switch (state) { case InField: { String t = input.substring(lastBegin, input.length()); t = StringUtils.trim(t); ret.add(t); break; } case InQuotedField: throw new RuntimeException("In Input at position " + (input.length() - 1) + " expects ending '\"', got end of input. text: '" + input + "'"); case StartField: if (ret.size() > 0) { ret.add(""); } break; } } else if (state == State.StartField && ret.size() > 0) { ret.add(""); } return ret; }
From source file:com.cyc.tool.distributedrepresentations.Word2VecSpaceFromFile.java
private String getVocabString(DataInputStream s) throws IOException { sb.setLength(0);/*from w w w. j a v a2s .c o m*/ for (char ch = (char) s.read(); (!Character.isWhitespace(ch) && ch >= 0 && ch <= 256); ch = (char) s.read()) { sb.append((char) ch); } return sb.toString(); }
From source file:org.springframework.core.util.StringUtils.java
/** * Check whether the given CharSequence has actual text. * More specifically, returns <code>true</code> if the string not <code>null</code>, * its length is greater than 0, and it contains at least one non-whitespace character. * <p><pre>/*from w w w.j ava 2 s. co m*/ * org.springframework.core.util.StringUtils.hasText(null) = false * org.springframework.core.util.StringUtils.hasText("") = false * org.springframework.core.util.StringUtils.hasText(" ") = false * org.springframework.core.util.StringUtils.hasText("12345") = true * org.springframework.core.util.StringUtils.hasText(" 12345 ") = true * </pre> * * @param str the CharSequence to check (may be <code>null</code>) * @return <code>true</code> if the CharSequence is not <code>null</code>, * its length is greater than 0, and it does not contain whitespace only * @see Character#isWhitespace */ public static boolean hasText(final CharSequence str) { if (!hasLength(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }