List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:com.xie.javacase.json.XML.java
/** * Throw an exception if the string contains whitespace. * Whitespace is not allowed in tagNames and attributes. * @param string//w w w . j a va 2 s . c o m * @throws org.json.JSONException */ public static void noSpace(String string) throws JSONException { int i, length = string.length(); if (length == 0) { throw new JSONException("Empty string."); } for (i = 0; i < length; i += 1) { if (Character.isWhitespace(string.charAt(i))) { throw new JSONException("'" + string + "' contains a space character."); } } }
From source file:StringUtils.java
/** * Returns the index of the first whitespace character or '-' in <var>line</var> * that is at or after <var>start</var>. Returns -1 if no such character is * found.// w w w.j a va 2 s . c om * * @param line * a string * @param start * where to star looking */ public static int findBreakAfter(String line, int start) { int len = line.length(); for (int i = start; i < len; ++i) { char c = line.charAt(i); if (Character.isWhitespace(c) || c == '-') return i; } return -1; }
From source file:Ch5CompletionEditor.java
protected String findMostRecentWord(int startSearchOffset) { int currOffset = startSearchOffset; char currChar; String word = ""; try {// w w w . j a v a 2 s .c o m while (currOffset > 0 && !Character.isWhitespace(currChar = textViewer.getDocument().getChar(currOffset))) { word = currChar + word; currOffset--; } return word; } catch (BadLocationException e) { e.printStackTrace(); return null; } }
From source file:com.caocao.util.StringUtils.java
/** * Check whether the given CharSequence has actual text. * More specifically, returns {@code true} if the string not {@code null}, * its length is greater than 0, and it contains at least one non-whitespace character. * <p><pre>/*from w w w . j av a 2s . 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 CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not {@code null}, * its length is greater than 0, and it does not contain whitespace only * @see Character#isWhitespace */ public static boolean hasText(String str) { if (isEmpty(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
From source file:HttpParser.java
public int parseRequest() throws IOException { String initial, prms[], cmd[], temp[]; int ret, idx, i; ret = 200; // default is OK now initial = reader.readLine();//from w w w. j a va 2s . c om if (initial == null || initial.length() == 0) return 0; if (Character.isWhitespace(initial.charAt(0))) { // starting whitespace, return bad request return 400; } cmd = initial.split("\\s"); if (cmd.length != 3) { return 400; } if (cmd[2].indexOf("HTTP/") == 0 && cmd[2].indexOf('.') > 5) { temp = cmd[2].substring(5).split("\\."); try { ver[0] = Integer.parseInt(temp[0]); ver[1] = Integer.parseInt(temp[1]); } catch (NumberFormatException nfe) { ret = 400; } } else ret = 400; if (cmd[0].equals("GET") || cmd[0].equals("HEAD")) { method = cmd[0]; idx = cmd[1].indexOf('?'); if (idx < 0) url = cmd[1]; else { url = URLDecoder.decode(cmd[1].substring(0, idx), "ISO-8859-1"); prms = cmd[1].substring(idx + 1).split("&"); params = new Hashtable(); for (i = 0; i < prms.length; i++) { temp = prms[i].split("="); if (temp.length == 2) { // we use ISO-8859-1 as temporary charset and then // String.getBytes("ISO-8859-1") to get the data params.put(URLDecoder.decode(temp[0], "ISO-8859-1"), URLDecoder.decode(temp[1], "ISO-8859-1")); } else if (temp.length == 1 && prms[i].indexOf('=') == prms[i].length() - 1) { // handle empty string separatedly params.put(URLDecoder.decode(temp[0], "ISO-8859-1"), ""); } } } parseHeaders(); if (headers == null) ret = 400; } else if (cmd[0].equals("POST")) { ret = 501; // not implemented } else if (ver[0] == 1 && ver[1] >= 1) { if (cmd[0].equals("OPTIONS") || cmd[0].equals("PUT") || cmd[0].equals("DELETE") || cmd[0].equals("TRACE") || cmd[0].equals("CONNECT")) { ret = 501; // not implemented } } else { // meh not understand, bad request ret = 400; } if (ver[0] == 1 && ver[1] >= 1 && getHeader("Host") == null) { ret = 400; } return ret; }
From source file:com.opendoorlogistics.core.utils.strings.Strings.java
public static String toFirstLetterInWordCapitalised(String s) { int n = s.length(); StringBuilder builder = new StringBuilder(); boolean lastIsSpace = true; for (int i = 0; i < n; i++) { char c = s.charAt(i); if (lastIsSpace) { builder.append(Character.toUpperCase(c)); } else {/*from www .j a v a 2s .c o m*/ builder.append(Character.toLowerCase(c)); } lastIsSpace = Character.isWhitespace(c); } return builder.toString(); }
From source file:lucee.commons.lang.StringUtil.java
public static String capitalize(String input, char[] delims) { if (isEmpty(input)) return input; if (ArrayUtil.isEmpty(delims)) delims = new char[] { '.', '-', '(', ')' }; StringBuilder sb = new StringBuilder(input.length()); boolean isLastDelim = true, isLastSpace = true; int len = input.length(); for (int i = 0; i < len; i++) { char c = input.charAt(i); if (Character.isWhitespace(c)) { if (!isLastSpace) sb.append(' '); isLastSpace = true;/*from w ww.j a v a 2 s.c o m*/ } else { sb.append((isLastSpace || isLastDelim) ? Character.toUpperCase(c) : c); isLastDelim = _contains(delims, c); isLastSpace = false; } } return sb.toString(); }
From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck.java
/** * Checks whether token is followed by a whitespace. * @param targetAST Ast token.//from ww w. j a va 2 s . c o m * @param line The line associated with the ast token. * @return true if ast token is followed by a whitespace. */ private static boolean isFollowedByWhitespace(DetailAST targetAST, String line) { final int after = targetAST.getColumnNo() + targetAST.getText().length(); boolean followedByWhitespace = true; if (after < line.length()) { final char charAfter = line.charAt(after); followedByWhitespace = Character.isWhitespace(charAfter) || targetAST.getType() == TokenTypes.SEMI && (charAfter == ';' || charAfter == ')'); } return followedByWhitespace; }
From source file:au.org.ala.delta.directives.args.DirectiveArgsParser.java
protected String readToNextWhiteSpaceOrEnd() throws ParseException { StringBuilder text = new StringBuilder(); while (_currentInt >= 0 && !Character.isWhitespace(_currentChar)) { text.append(_currentChar);//from w w w . j av a 2 s .co m readNext(); } return text.toString(); }
From source file:Base64Decoder.java
/** * Returns the next decoded character from the stream, or -1 if end of * stream was reached.//from ww w . j a v a2 s . c o m * * @return the decoded character, or -1 if the end of the input stream is * reached * @exception IOException * if an I/O error occurs */ public int read() throws IOException { // Read the next non-whitespace character int x; do { x = in.read(); if (x == -1) { return -1; } } while (Character.isWhitespace((char) x)); charCount++; // The '=' sign is just padding if (x == '=') { return -1; // effective end of stream } // Convert from raw form to 6-bit form x = ints[x]; // Calculate which character we're decoding now int mode = (charCount - 1) % 4; // First char save all six bits, go for another if (mode == 0) { carryOver = x & 63; return read(); } // Second char use previous six bits and first two new bits, // save last four bits else if (mode == 1) { int decoded = ((carryOver << 2) + (x >> 4)) & 255; carryOver = x & 15; return decoded; } // Third char use previous four bits and first four new bits, // save last two bits else if (mode == 2) { int decoded = ((carryOver << 4) + (x >> 2)) & 255; carryOver = x & 3; return decoded; } // Fourth char use previous two bits and all six new bits else if (mode == 3) { int decoded = ((carryOver << 6) + x) & 255; return decoded; } return -1; // can't actually reach this line }