List of usage examples for java.lang Character isSpaceChar
public static boolean isSpaceChar(int codePoint)
From source file:be.milieuinfo.core.proxy.controller.ProxyServlet.java
/** * <p>Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more * forgiving, we must escape the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment *//* ww w . j a v a 2 s .c o m*/ static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:com.attribyte.essem.util.Util.java
/** * Creates a string that is a valid (safe) "identifier" by * replacing invalid characters with underscore ('_'). * @param str The input string./*from www . j a v a 2s .c o m*/ * @return The valid identifier. */ public static String toValidIdentifier(final String str) { //TODO if (Strings.isNullOrEmpty(str)) { return str; } StringBuilder buf = new StringBuilder(); for (char ch : str.toCharArray()) { if (Character.isSpaceChar(ch)) ch = ' '; if (isValidIdentifier(ch)) { buf.append(ch); } else { buf.append("_"); } } return buf.toString(); }
From source file:org.opengeoportal.proxy.controllers.DynamicOgcController.java
/** * <p>Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more * forgiving, we must escape the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment *//*from w w w .j ava 2s. co m*/ static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO formatter.close(); } } return outBuf != null ? outBuf : in; }
From source file:cn.knet.showcase.demos.servletproxy.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the URI class for the * spec./*from w ww. j a v a 2 s .c om*/ * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:net.sf.jasperreports.functions.standard.TextFunctions.java
private static boolean isDelimiter(char c) { return Character.isWhitespace(c) || Character.isSpaceChar(c); }
From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Determine if the key event was actual text, if so, focus the search bar and then dispatch // the key normally so that it can process this key event if (!mSearchBarController.isSearchFieldFocused() && event.getAction() == KeyEvent.ACTION_DOWN) { final int unicodeChar = event.getUnicodeChar(); final boolean isKeyNotWhitespace = unicodeChar > 0 && !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar); if (isKeyNotWhitespace) { boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder, event.getKeyCode(), event); if (gotKey && mSearchQueryBuilder.length() > 0) { mSearchBarController.focusSearchField(); }//from w w w .ja v a 2s. c o m } } return super.dispatchKeyEvent(event); }
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
/** * Returns the query around the specified (cursor) position. * * @param the position//from ww w.j a v a 2s . c om * @return the query around the specified position */ private QueryWithPosition getQueryAt(int position) { String text = getText(); if (MiscUtils.isNull(text)) { return new QueryWithPosition(0, 0, 0, Constants.EMPTY); } char[] chars = text.toCharArray(); if (position == chars.length) { position--; } int start = -1; int end = -1; boolean wasSpaceChar = false; // determine the start point for (int i = position; i >= 0; i--) { if (chars[i] == Constants.NEW_LINE_CHAR) { if (i == 0 || wasSpaceChar) { break; } else if (start != -1) { if (chars[i - 1] == Constants.NEW_LINE_CHAR) { break; } else if (Character.isSpaceChar(chars[i - 1])) { wasSpaceChar = true; i--; } } } else if (!Character.isSpaceChar(chars[i])) { wasSpaceChar = false; start = i; } } if (start < 0) { // text not found for (int j = 0; j < chars.length; j++) { if (!Character.isWhitespace(chars[j])) { start = j; break; } } } // determine the end point for (int i = start; i < chars.length; i++) { if (chars[i] == Constants.NEW_LINE_CHAR) { if (i == chars.length - 1 || wasSpaceChar) { if (end == -1) { end = i; } break; } else if (end != -1) { if (chars[i + 1] == Constants.NEW_LINE_CHAR) { break; } else if (Character.isSpaceChar(chars[i + 1])) { wasSpaceChar = true; i++; } } } else if (!Character.isSpaceChar(chars[i])) { end = i; wasSpaceChar = false; } } //Log.debug("start: " + start + " end: " + end); String query = text.substring(start, end + 1); //Log.debug(query); if ((MiscUtils.isNull(query) && start != 0)) { // || start == end) { return getQueryAt(start); } return new QueryWithPosition(position, start, end + 1, query); }
From source file:org.owasp.appsensor.block.proxy.servlet.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the URI class for the * spec./*from w w w.j a v a2s .c o m*/ * * @param in example: name=value&foo=bar#fragment */ @SuppressWarnings("resource") protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:httpmultiplexer.httpproxy.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>/*w w w . j av a 2s . c o m*/ * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient insists that the outgoing proxied request has a valid * URI because it uses Java's {@link URI}. To be more forgiving, we must * escape the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) { outBuf.append(c); } } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:io.hops.hopsworks.api.kibana.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * <p>//from w w w . ja va 2 s . co m * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses * Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the * URI class for the * spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape //pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) { outBuf.append(c); } } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }