List of usage examples for java.lang Character isJavaIdentifierPart
public static boolean isJavaIdentifierPart(int codePoint)
From source file:org.traccar.database.QueryBuilder.java
private static String parse(String query, Map<String, List<Integer>> paramMap) { int length = query.length(); StringBuilder parsedQuery = new StringBuilder(length); boolean inSingleQuote = false; boolean inDoubleQuote = false; int index = 1; for (int i = 0; i < length; i++) { char c = query.charAt(i); // String end if (inSingleQuote) { if (c == '\'') { inSingleQuote = false;/* ww w . ja v a 2s. co m*/ } } else if (inDoubleQuote) { if (c == '"') { inDoubleQuote = false; } } else { // String begin if (c == '\'') { inSingleQuote = true; } else if (c == '"') { inDoubleQuote = true; } else if (c == ':' && i + 1 < length && Character.isJavaIdentifierStart(query.charAt(i + 1))) { // Identifier name int j = i + 2; while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) { j++; } String name = query.substring(i + 1, j); c = '?'; i += name.length(); name = name.toLowerCase(); // Add to list List<Integer> indexList = paramMap.get(name); if (indexList == null) { indexList = new LinkedList<>(); paramMap.put(name, indexList); } indexList.add(index); index++; } } parsedQuery.append(c); } return parsedQuery.toString(); }
From source file:org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore.java
private static String fixName(final String name) { final int length = name.length(); StringBuilder result = new StringBuilder(length); for (int i = 0; i < length; i++) { char c = name.charAt(i); if (Character.isJavaIdentifierPart(c)) { result.append(c);/* w ww. j a v a 2 s.co m*/ } } return result.toString(); }
From source file:ar.com.tadp.xml.rinzo.core.contentassist.processors.XMLTemplateProcessor.java
/** * We watch for angular brackets since those are often part of XML * templates.// w ww .j av a 2 s . c o m * * @param viewer the viewer * @param offset the offset left of which the prefix is detected * @return the detected prefix */ protected String extractPrefix(ITextViewer viewer, int offset) { IDocument document = viewer.getDocument(); int i = offset; if (i > document.getLength()) { return ""; } try { while (i > 0) { char ch = document.getChar(i - 1); if (ch != '<' && !Character.isJavaIdentifierPart(ch)) { break; } i--; } return document.get(i, offset - i); } catch (BadLocationException e) { return ""; } }
From source file:com.asakusafw.yaess.tools.GenerateExecutionId.java
private static String normalize(String string) { assert string != null; StringBuilder buf = new StringBuilder(); for (char c : string.toCharArray()) { if (Character.isJavaIdentifierPart(c)) { buf.append(c);// w ww . ja va 2 s .c om } else { buf.append('_'); } } return buf.toString(); }
From source file:com.canoo.webtest.boundary.ResetScriptRunner.java
/** * Add a single object into the script context. * * @param key the name in the context this object is to stored under. * @param bean the object to be stored in the script context. */// ww w. j av a2s . c om public void addBean(final String key, final Object bean) { boolean isValid = key.length() > 0 && Character.isJavaIdentifierStart(key.charAt(0)); for (int i = 1; isValid && i < key.length(); i++) { isValid = Character.isJavaIdentifierPart(key.charAt(i)); } if (isValid) { fBeans.put(key, bean); } }
From source file:info.novatec.testit.livingdoc.util.NameUtils.java
public static String removeNonJavaIdentifierCharacters(String name) { StringBuilder javaIdentifier = new StringBuilder(); for (int index = 0; index < name.length(); index++) { if (Character.isJavaIdentifierPart(name.codePointAt(index))) { javaIdentifier.append(name.charAt(index)); }/*from www.ja v a 2 s. com*/ } return javaIdentifier.toString(); }
From source file:org.wrml.runtime.schema.SchemaBuilder.java
public static String ensureValidJavaIdentifier(final String identifier) { if (identifier == null || RESERVED_WORD_SET.contains(identifier)) { return null; }/*w ww . ja v a 2 s. com*/ String validJavaIdentifier = identifier; int index = validJavaIdentifier.indexOf('-'); if (index > 0) { validJavaIdentifier = validJavaIdentifier.replace('-', '_'); } if (!Character.isJavaIdentifierStart(validJavaIdentifier.charAt(0))) { validJavaIdentifier = "_" + validJavaIdentifier; } final int validJavaIdentifierLength = validJavaIdentifier.length(); String replaceCharacters = ""; for (int i = 1; i < validJavaIdentifierLength; i++) { char c = validJavaIdentifier.charAt(i); if (!Character.isJavaIdentifierPart(c)) { replaceCharacters += c; } } if (!replaceCharacters.isEmpty()) { validJavaIdentifier = StringUtils.replaceChars(validJavaIdentifier, replaceCharacters, "$"); } return validJavaIdentifier; }
From source file:nl.strohalm.cyclos.utils.StringHelper.java
/** * Check if the string is a valid Java identifier. It's not checked if the string is a reserved Java word. *///from w w w.ja v a 2 s.c om public static boolean isValidJavaIdentifier(final String string) { if (StringUtils.isEmpty(string)) { return false; } if (!Character.isJavaIdentifierStart(string.charAt(0))) { return false; } for (int i = 1; i < string.length(); i++) { if (!Character.isJavaIdentifierPart(string.charAt(i))) { return false; } } return true; }
From source file:com.yahoo.bard.webservice.config.ModuleLoader.java
/** * A method used to apply validation rules to module names found in resource property files. * Throws exceptions when invalid./*from w w w . ja va 2s .com*/ * * @param name The name under test. * * @throws SystemConfigException when a name fails a validation rule */ public static void validateModuleName(String name) throws SystemConfigException { char[] nameChars = name.toCharArray(); // Module name should not be a single character if (nameChars.length < 2) { LOG.error(INVALID_MODULE_CONFIGURATION.logFormat(MODULE_NAME_IS_TOO_SHORT, name)); throw new SystemConfigException(INVALID_MODULE_CONFIGURATION.format(MODULE_NAME_IS_TOO_SHORT, name)); } List<Character> invalidCharacters = new ArrayList<>(name.length()); if (!Character.isJavaIdentifierStart(name.charAt(0))) { invalidCharacters.add(name.charAt(0)); } name.substring(1).chars().mapToObj(charCode -> (char) charCode) .filter(character -> !Character.isJavaIdentifierPart(character) && character != '-') .forEach(invalidCharacters::add); if (!invalidCharacters.isEmpty()) { String message = String.format(ILLEGAL_CHARACTER_IN_MODULE_NAME, invalidCharacters); LOG.error(INVALID_MODULE_NAME.logFormat(name, message)); throw new SystemConfigException(INVALID_MODULE_NAME.logFormat(name, message)); } }
From source file:org.openehr.designer.util.WtUtils.java
private static boolean isValidFilenameChar(char c) { if (Character.isJavaIdentifierPart(c)) return true; if (EXTRA_VALID_CHARS.contains(c)) return true; return false; }