List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:org.openmrs.module.emrapi.utils.GeneralUtils.java
/** * THIS METHOD IS COPIED FROM org.openmrs.web.WebUtil IN openmrs-core's web submodule * <p/>/*from w w w. j ava 2 s. c om*/ * This method checks if input locale string contains control characters and tries to clean up * actually contained ones. Also it parses locale object from string representation and * validates it object. * * @param localeString input string with locale parameter * @return locale object for input string if CTLs were cleaned up or weren't exist or null if * could not to clean up CTLs from input string * @should ignore leading spaces * @should accept language only locales * @should not accept invalid locales * @should not fail with empty strings * @should not fail with whitespace only */ public static Locale normalizeLocale(String localeString) { if (localeString == null) return null; localeString = localeString.trim(); if (localeString.isEmpty()) return null; int len = localeString.length(); for (int i = 0; i < len; i++) { char c = localeString.charAt(i); // allow only ASCII letters and "_" character if ((c <= 0x20 || c >= 0x7f) || ((c >= 0x20 || c <= 0x7f) && (!Character.isLetter(c) && c != 0x5f))) { if (c == 0x09) continue; // allow horizontal tabs localeString = localeString.replaceFirst(((Character) c).toString(), ""); len--; i--; } } Locale locale = LocaleUtility.fromSpecification(localeString); if (LocaleUtility.isValid(locale)) return locale; else return null; }
From source file:org.skyinn.quasar.util.StringUtil.java
/** * UpperCase the first character of the given string. * //from w w w. j a v a2 s.co m * TODO:trim() need? * @param str source string * @return source string with first char be uppercased, * if the first char is NOT letter,return the source string * without convert. */ public static String upperCaseFirstChar(String str) { //if str is null or empty,return if (StringUtils.isEmpty(str)) { return str; } //first character char c = str.charAt(0); //is letter? if (Character.isLetter(c)) { //uppercase first character return Character.toUpperCase(c) + str.substring(1); } //if the first char in NOT letter,return the source string return str; }
From source file:org.liquidsite.core.content.User.java
/** * Generates a password suggestion that should be sufficiently * hard to crack./*w w w . j a v a2 s .com*/ * * @return the generated password */ public static String generatePassword() { StringBuffer result = new StringBuffer(); int length = PASSWORD_CHARS.length(); char c; while (result.length() < 8) { c = PASSWORD_CHARS.charAt((int) (Math.random() * length)); if (result.length() > 0 || Character.isLetter(c)) { result.append(c); } } return result.toString(); }
From source file:org.talend.repository.json.util.JSONUtil.java
public static boolean validateLabelForNameSpace(String label) { if (label == null) { return false; }//from w ww.j a v a 2 s .c o m if (label.toLowerCase().startsWith(JSON_FILE)) { return false; } if (label.contains(".")) { //$NON-NLS-1$ return false; } if (!("".equals(label)) && !("".equals(label.trim()))) { //$NON-NLS-1$ //$NON-NLS-2$ char firstChar = label.charAt(0); if (!Character.isLetter(firstChar)) { return false; } char[] array = label.toCharArray(); for (char element : array) { if (Character.isSpaceChar(element) || Character.isWhitespace(element)) { return false; } } } return true; }
From source file:com.eryansky.common.utils.StringUtils.java
/** * ??//from w w w . ja va2s . c o m * * @param str * @return ?? * * <pre> * capitalizeFirstLetter(null) = null; * capitalizeFirstLetter("") = ""; * capitalizeFirstLetter("1ab") = "1ab" * capitalizeFirstLetter("a") = "A" * capitalizeFirstLetter("ab") = "Ab" * capitalizeFirstLetter("Abc") = "Abc" * </pre> */ public static String capitalizeFirstLetter(String str) { return (isEmpty(str) || !Character.isLetter(str.charAt(0))) ? str : Character.toUpperCase(str.charAt(0)) + str.substring(1); }
From source file:egovframework.rte.fdl.string.EgovStringUtil.java
/** * @param str//from w w w .j a v a 2 s.com * @return */ public static boolean isAlpha(String str) { if (str == null) { return false; } int size = str.length(); if (size == 0) return false; for (int i = 0; i < size; i++) { if (!Character.isLetter(str.charAt(i))) { return false; } } return true; }
From source file:org.jboss.tools.openshift.common.core.utils.StringUtils.java
public static boolean startsWithLetterOrUnderscore(String value) { if (isEmpty(value)) { return false; }/*from w w w .java2 s . co m*/ char character = value.charAt(0); return character == '_' || Character.isLetter(character); }
From source file:net.sf.jabref.exporter.layout.format.RTFChars.java
@Override public String format(String field) { StringBuffer sb = new StringBuffer(""); StringBuffer currentCommand = null; boolean escaped = false; boolean incommand = false; for (int i = 0; i < field.length(); i++) { char c = field.charAt(i); if (escaped && (c == '\\')) { sb.append('\\'); escaped = false;// www . ja v a 2s. c om } else if (c == '\\') { escaped = true; incommand = true; currentCommand = new StringBuffer(); } else if (!incommand && ((c == '{') || (c == '}'))) { // Swallow the brace. } else if (Character.isLetter(c) || Globals.SPECIAL_COMMAND_CHARS.contains(String.valueOf(c))) { escaped = false; if (incommand) { // Else we are in a command, and should not keep the letter. currentCommand.append(c); testCharCom: if ((currentCommand.length() == 1) && Globals.SPECIAL_COMMAND_CHARS.contains(currentCommand.toString())) { // This indicates that we are in a command of the type // \^o or \~{n} if (i >= (field.length() - 1)) { break testCharCom; } String command = currentCommand.toString(); i++; c = field.charAt(i); String combody; if (c == '{') { StringInt part = getPart(field, i, true); i += part.i; combody = part.s; } else { combody = field.substring(i, i + 1); } String result = RTF_CHARS.get(command + combody); if (result != null) { sb.append(result); } incommand = false; escaped = false; } } else { sb.append(c); } } else { // if (!incommand || ((c!='{') && !Character.isWhitespace(c))) testContent: if (!incommand || (!Character.isWhitespace(c) && (c != '{') && (c != '}'))) { sb.append(c); } else { assert incommand; // First test for braces that may be part of a LaTeX command: if ((c == '{') && (currentCommand.length() == 0)) { // We have seen something like \{, which is probably the start // of a command like \{aa}. Swallow the brace. continue; } else if ((c == '}') && (currentCommand.length() > 0)) { // Seems to be the end of a command like \{aa}. Look it up: String command = currentCommand.toString(); String result = RTF_CHARS.get(command); if (result != null) { sb.append(result); } incommand = false; escaped = false; continue; } // Then look for italics etc., // but first check if we are already at the end of the string. if (i >= (field.length() - 1)) { break testContent; } if (((c == '{') || (c == ' ')) && (currentCommand.length() > 0)) { String command = currentCommand.toString(); // Then test if we are dealing with a italics or bold // command. If so, handle. if ("em".equals(command) || "emph".equals(command) || "textit".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\i ").append(part.s).append('}'); } else if ("textbf".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\b ").append(part.s).append('}'); } else { LOGGER.info("Unknown command " + command); } if (c == ' ') { // command was separated with the content by ' ' // We have to add the space a } } else { sb.append(c); } } incommand = false; escaped = false; } } char[] chars = sb.toString().toCharArray(); sb = new StringBuffer(); for (char c : chars) { if (c < 128) { sb.append(c); } else { sb.append("\\u").append((long) c).append('?'); } } return sb.toString().replaceAll("---", "{\\\\emdash}").replaceAll("--", "{\\\\endash}") .replaceAll("``", "{\\\\ldblquote}").replaceAll("''", "{\\\\rdblquote}"); }
From source file:net.sf.jabref.logic.layout.format.RTFChars.java
@Override public String format(String field) { StringBuilder sb = new StringBuilder(""); StringBuilder currentCommand = null; boolean escaped = false; boolean incommand = false; for (int i = 0; i < field.length(); i++) { char c = field.charAt(i); if (escaped && (c == '\\')) { sb.append('\\'); escaped = false;/* ww w . j a v a 2s .c o m*/ } else if (c == '\\') { escaped = true; incommand = true; currentCommand = new StringBuilder(); } else if (!incommand && ((c == '{') || (c == '}'))) { // Swallow the brace. } else if (Character.isLetter(c) || Globals.SPECIAL_COMMAND_CHARS.contains(String.valueOf(c))) { escaped = false; if (incommand) { // Else we are in a command, and should not keep the letter. currentCommand.append(c); testCharCom: if ((currentCommand.length() == 1) && Globals.SPECIAL_COMMAND_CHARS.contains(currentCommand.toString())) { // This indicates that we are in a command of the type // \^o or \~{n} if (i >= (field.length() - 1)) { break testCharCom; } String command = currentCommand.toString(); i++; c = field.charAt(i); String combody; if (c == '{') { StringInt part = getPart(field, i, true); i += part.i; combody = part.s; } else { combody = field.substring(i, i + 1); } String result = RTF_CHARS.get(command + combody); if (result != null) { sb.append(result); } incommand = false; escaped = false; } } else { sb.append(c); } } else { testContent: if (!incommand || (!Character.isWhitespace(c) && (c != '{') && (c != '}'))) { sb.append(c); } else { assert incommand; // First test for braces that may be part of a LaTeX command: if ((c == '{') && (currentCommand.length() == 0)) { // We have seen something like \{, which is probably the start // of a command like \{aa}. Swallow the brace. continue; } else if ((c == '}') && (currentCommand.length() > 0)) { // Seems to be the end of a command like \{aa}. Look it up: String command = currentCommand.toString(); String result = RTF_CHARS.get(command); if (result != null) { sb.append(result); } incommand = false; escaped = false; continue; } // Then look for italics etc., // but first check if we are already at the end of the string. if (i >= field.length() - 1) { break testContent; } if (((c == '{') || (c == ' ')) && (currentCommand.length() > 0)) { String command = currentCommand.toString(); // Then test if we are dealing with a italics or bold // command. If so, handle. if ("em".equals(command) || "emph".equals(command) || "textit".equals(command) || "it".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\i ").append(part.s).append('}'); } else if ("textbf".equals(command) || "bf".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\b ").append(part.s).append('}'); } else { LOGGER.info("Unknown command " + command); } if (c == ' ') { // command was separated with the content by ' ' // We have to add the space a } } else { sb.append(c); } } incommand = false; escaped = false; } } char[] chars = sb.toString().toCharArray(); sb = new StringBuilder(); for (char c : chars) { if (c < 128) { sb.append(c); } else { sb.append("\\u").append((long) c).append('?'); } } return sb.toString().replace("---", "{\\emdash}").replace("--", "{\\endash}").replace("``", "{\\ldblquote}") .replace("''", "{\\rdblquote}"); }
From source file:com.android.beyondemail.SSLUtils.java
/** * Escapes the contents a string to be used as a safe scheme name in the URI according to * http://tools.ietf.org/html/rfc3986#section-3.1 * * This does not ensure that the first character is a letter (which is required by the RFC). *///from w w w. j a va2s . c o m public static String escapeForSchemeName(String s) { // According to the RFC, scheme names are case-insensitive. s = s.toLowerCase(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isLetter(c) || Character.isDigit(c) || ('-' == c) || ('.' == c)) { // Safe - use as is. sb.append(c); } else if ('+' == c) { // + is used as our escape character, so double it up. sb.append("++"); } else { // Unsafe - escape. sb.append('+').append((int) c); } } return sb.toString(); }