List of usage examples for java.lang CharSequence length
int length();
From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java
/** * ??????????/*from w w w .jav a 2 s . c o m*/ * ???<code>null</code>?????<code>0</code>?????? * @param suspect * @return ???true */ public static boolean isEmpty(CharSequence suspect) { return suspect == null || suspect.length() == 0; }
From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java
/** * ????'\u0020'?'\u007e'??????????// w w w . j a va2 s . c o m * @param suspect * @return ???true */ public static boolean isASCII(CharSequence suspect) { for (int i = 0; i < suspect.length(); i++) { char c = suspect.charAt(i); if (c < '\u0020' || c > '\u007e') { return false; } } return true; }
From source file:com.dnw.json.J.java
/** * Escapes each character to make the string can be denoted as a JSON string. * /* ww w .j ava2 s .c o m*/ * @author manbaum * @since Oct 11, 2014 * @param text a string to have all characters to be escaped. * @return the escaped string. */ private final static String escape(final CharSequence text) { final StringBuffer sb = new StringBuffer(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (ch == 0) { sb.append("\\0"); } else if (ch == '\n') { sb.append("\\n"); } else if (ch == '\r') { sb.append("\\r"); } else if (ch < 32) { sb.append("\\x"); if (ch < 16) { sb.append('0'); } sb.append(Integer.toHexString(ch)); } else if (ch == '\\' || ch == '\'' || ch == '\"') { sb.append("\\"); sb.append(ch); } else if (ch <= 126) { sb.append(ch); } else { int n = Character.codePointAt(text, i); sb.append("\\u"); if (n < 16) { sb.append("000"); } else if (n < 256) { sb.append("00"); } else if (n < 4096) { sb.append("0"); } sb.append(Integer.toHexString(n)); } } return sb.toString(); }
From source file:org.cleverbus.common.Strings.java
/** * @param input the input/*from w ww . ja va2s .c om*/ * @param c the searched character * @return the index or -1 * @since 3.8.2 */ public static int indexOf(CharSequence input, char c) { if (input instanceof String) { return ((String) input).indexOf(c); } for (int i = 0; i < input.length(); i++) { if (c == input.charAt(i)) { return i; } } return -1; }
From source file:com.gamesalutes.utils.WebUtils.java
private static boolean encodeReserved(CharSequence s, int index, boolean isLast) { // FIXME: this does not work properly for & int len = s.length(); // reserved chars // & encode within a given query parameter // / don't encode unless in query // : after the first / following the hostname // ; always?//ww w . ja v a 2 s . c om // = always outside a query name-value separation // ? after the first appearance in a path - denoting the start of the query string // @ always? if (index < 0 || index >= len) return false; char c = s.charAt(index); switch (c) { case '&': { if (isLast) return false; int qi = StringUtils.lastIndexOf(s, '?', index - 1); if (qi == -1) return false; // find prev one int start = StringUtils.lastIndexOf(s, c, index - 1); if (start == -1) start = qi + 1; if (start >= index - 1) return true; // check to see if we name=value return StringUtils.indexOf(false, s, start, '=', index - start) == -1; } case '?': { return StringUtils.lastIndexOf(s, c, index - 1) != -1; } case '/': { return StringUtils.lastIndexOf(s, '?', index - 1) != -1; } case ':': { return StringUtils.indexOf(s, "//", index - 1) != -1 && StringUtils.indexOf(s, c, index - 1) != -1; } case ';': case '@': { return true; } case '=': { if (isLast) return false; int qi = StringUtils.lastIndexOf(s, '?', index - 1); if (qi == -1) return false; // find current token int start = StringUtils.lastIndexOf(s, '&', index - 1); if (start == -1) start = qi + 1; if (start >= index - 1) return true; // if previous character was first a & and not a = then we are good // check to see if we name=value return StringUtils.indexOf(false, s, start, '=', index - start) != -1; } default: return false; } }
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 www .ja v a2 s . c o m * * @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:free.yhc.netmbuddy.utils.Utils.java
/** * Is is valid string?/*from ww w . ja v a 2 s.c o m*/ * Valid means "Not NULL and Not empty". * @param v * @return */ public static boolean isValidValue(CharSequence v) { return !(null == v || v.length() <= 0); }
From source file:org.ocpsoft.rewrite.servlet.config.proxy.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * // w w w.j a va2 s .c om * <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. TODO: * replace/compare to with Rewrite Encoding */ 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(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:jp.co.ctc_g.jse.core.validation.util.Validators.java
/** * ?"Windows-31J"???????????????2?????????? * @param suspect /*from www . j a v a2 s .c om*/ * @return ???true */ public static boolean isZenkaku(CharSequence suspect) { try { byte[] sjis = suspect.toString().getBytes(WINDOWS31_J); return sjis.length == (suspect.length() * 2); } catch (UnsupportedEncodingException e) { return false; } }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String toWords(CharSequence str) { StringBuilder res = new StringBuilder(str.length()); for (int i = 0; i < str.length(); i++) { Character ch = str.charAt(i); if (Character.isUpperCase(ch)) { res.append(' ').append(ch); } else {//w w w.j av a 2s.c o m res.append(ch); } } char c = Character.toUpperCase(res.charAt(0)); res.replace(0, 1, new String(new char[] { c })); return res.toString(); }