List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:com.g3net.tool.StringUtils.java
/** * Trim leading whitespace from the given String. * /*from w w w . ja v a2 s. c o m*/ * @param str * the String to check * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimLeadingWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuilder buf = new StringBuilder(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } return buf.toString(); }
From source file:net.sf.jabref.importer.fileformat.BibtexParser.java
private String skipAndRecordWhitespace(int character) throws IOException { StringBuilder stringBuilder = new StringBuilder(); if (character != ' ') { stringBuilder.append((char) character); }//from ww w. j av a2 s . c om while (true) { int nextCharacter = read(); if (isEOFCharacter(nextCharacter)) { eof = true; return stringBuilder.toString(); } if (Character.isWhitespace((char) nextCharacter)) { if (nextCharacter != ' ') { stringBuilder.append((char) nextCharacter); } } else { // found non-whitespace char unread(nextCharacter); break; } } return stringBuilder.toString(); }
From source file:com.krawler.common.util.BaseStringUtil.java
/** * split a line into array of Strings, using a shell-style syntax for * tokenizing words./* www . j av a 2s .c om*/ * * @param line * @return */ public static String[] parseLine(String line) { ArrayList<String> result = new ArrayList<String>(); int i = 0; StringBuilder sb = new StringBuilder(32); int term = TERM_WHITESPACE; boolean inStr = false; scan: while (i < line.length()) { char ch = line.charAt(i++); boolean escapedTerm = false; if (ch == '\\' && i < line.length()) { ch = line.charAt(i++); switch (ch) { case '\\': break; case 'n': ch = '\n'; escapedTerm = true; break; case 't': ch = '\t'; escapedTerm = true; break; case 'r': ch = '\r'; escapedTerm = true; break; case '\'': ch = '\''; escapedTerm = true; break; case '"': ch = '"'; escapedTerm = true; break; default: escapedTerm = Character.isWhitespace(ch); break; } } if (inStr) { if (!escapedTerm && ((term == TERM_WHITESPACE && Character.isWhitespace(ch)) || (term == TERM_SINGLEQUOTE && ch == '\'') || (term == TERM_DBLQUOTE && ch == '"'))) { inStr = false; result.add(sb.toString()); sb = new StringBuilder(32); term = TERM_WHITESPACE; continue scan; } sb.append(ch); } else { if (!escapedTerm) { switch (ch) { case '\'': term = TERM_SINGLEQUOTE; inStr = true; continue scan; case '"': term = TERM_DBLQUOTE; inStr = true; continue scan; default: if (Character.isWhitespace(ch)) continue scan; inStr = true; sb.append(ch); break; } } else { // we had an escaped terminator, start a new string inStr = true; sb.append(ch); } } } if (sb.length() > 0) result.add(sb.toString()); return result.toArray(new String[result.size()]); }
From source file:egovframework.asadal.asapro.com.utl.fcc.service.AsaproEgovStringUtil.java
License:asdf
/** * <p>?? {@link Character#isWhitespace(char)}? ?? * ? .</p>/*from w w w. j a v a 2s .c o m*/ * * <pre> * StringUtil.removeWhitespace(null) = null * StringUtil.removeWhitespace("") = "" * StringUtil.removeWhitespace("abc") = "abc" * StringUtil.removeWhitespace(" ab c ") = "abc" * </pre> * * @param str ? ? ? * @return the ? ? ?, null? ? <code>null</code>? */ public static String removeWhitespace(String str) { if (isEmpty(str)) { return str; } int sz = str.length(); char[] chs = new char[sz]; int count = 0; for (int i = 0; i < sz; i++) { if (!Character.isWhitespace(str.charAt(i))) { chs[count++] = str.charAt(i); } } if (count == sz) { return str; } return new String(chs, 0, count); }
From source file:com.easyjf.util.StringUtils.java
/** * ?? Java ?// w w w . j a v a 2 s . co m * * @param str * ? * @return */ 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:egovframework.asadal.asapro.com.cmm.util.AsaproEgovStringUtil.java
License:asdf
/** * <p>?? {@link Character#isWhitespace(char)}? ?? * ? .</p>/*from w ww . ja va 2 s .com*/ * * <pre> * StringUtil.removeWhitespace(null) = null * StringUtil.removeWhitespace("") = "" * StringUtil.removeWhitespace("abc") = "abc" * StringUtil.removeWhitespace(" ab c ") = "abc" * </pre> * * @param str ? ? ? * @return the ? ? ?, null? ? <code>null</code>? */ public static String removeWhitespace(String str) { if (isEmpty(str)) { return str; } int sz = str.length(); if (sz < 0) return ""; char[] chs = new char[sz]; int count = 0; for (int i = 0; i < sz; i++) { if (!Character.isWhitespace(str.charAt(i))) { chs[count++] = str.charAt(i); } } if (count == sz) { return str; } return new String(chs, 0, count); }
From source file:com.aurel.track.lucene.search.LuceneSearcher.java
/** * Handling of a specific case: possible project specific itemID containing lucene escaping characters * Precoditions:// ww w . j av a 2 s.c o m * 1. should be a single term (no whitespaces inside) * 2. should contain lucene escaping characters (+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ but here we test only - or +). * If the search term does not contain a lucene escaping character then the "default" lucene search suffice * @param queryString the user entered query string * @return */ private static boolean isPossibleProjectSpecificID(String queryString) { if (ApplicationBean.getInstance().getSiteBean().getProjectSpecificIDsOn()) { String trimmedQueryString = queryString.trim(); boolean containsSpecialChar = false; //special lucene characters: escaping them in term with \ does not work in query parser because it replaces them with space: exp-11 -> exp 11 -> i.e. exp OR 11 //we test here only some if the probable escaping characters in a project prefix char[] mightContainChars = new char[] { '+', '-', ':' }; //char[] notContainChars = new char[] {':'}; for (char c : trimmedQueryString.toCharArray()) { if (Character.isWhitespace(c)) { //more than one token: not a term but a possible complex query string return false; } if (!containsSpecialChar) { for (char ch : mightContainChars) { if (c == ch) { containsSpecialChar = true; } } } } if (containsSpecialChar) { //.+ there is at least one character before the digit //? will ensure it does a lazy match instead of a greedy match boolean match = trimmedQueryString.matches("^.+?\\d$"); LOGGER.debug("Match " + match + " possible project specific itemID " + queryString); return match; } } return false; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * @param content//w w w . ja v a 2s . c om * @return */ private String findFirstWord(String content) { int start = 0; while (start < content.length() && Character.isWhitespace(content.charAt(start))) { ++start; } int end = start; while (end < content.length() && !Character.isWhitespace(content.charAt(end))) { end++; } return content.substring(start, end); }
From source file:com.google.dart.tools.core.utilities.io.FileUtilities.java
/** * Return <code>true</code> if the given character can be included in a valid file name. * /*from w ww . ja v a 2 s.c om*/ * @param character the character being tested * @return <code>true</code> if the given character can be included in a valid file name */ private static boolean isValidFileNameChar(char character) { if (Character.isWhitespace(character)) { return false; } String invalidChars; // if (OS.isWindows()) { invalidChars = "\\/:*?\"<>|"; // } else if (OS.isMacOSX()) { // invalidChars = "/:"; // } else { // assume Unix/Linux // invalidChars = "/"; // } return !((invalidChars.indexOf(character) >= 0) // OS-invalid || (character < '\u0020') // ctrls || (character > '\u007e' && character < '\u00a0')); // ctrls }
From source file:com.zimbra.cs.service.FeedManager.java
private static int getLeadingChar(BufferedInputStream is, StringBuilder charset) throws IOException { is.mark(128);/* www . jav a 2 s. c o m*/ // check for any BOMs that would override the specified charset int ch = is.read(); switch (ch) { case 0xEF: if (is.read() == 0xBB && is.read() == 0xBF) { is.mark(128); ch = is.read(); charset.setLength(0); charset.append("utf-8"); } break; case 0xFE: if (is.read() == 0xFF && is.read() == 0x00) { ch = is.read(); charset.setLength(0); charset.append("utf-16"); } break; case 0xFF: if (is.read() == 0xFE) { ch = is.read(); charset.setLength(0); charset.append("utf-16"); } break; } // skip up to 120 bytes of leading whitespace for (int index = 0; index < 120 && (ch == '\0' || Character.isWhitespace(ch)); index++) ch = is.read(); // reset to the original state and return the first non-whtespace character is.reset(); return ch; }