List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:at.ofai.music.util.WormFileParseException.java
public static EventList readMatchFile(String fileName) throws Exception { EventList list = new EventList(); boolean startNote = timingCorrection; int eventFlags, numerator, denominator; String element;/*ww w. ja v a 2 s .co m*/ BufferedReader inputFile = new BufferedReader(new FileReader(fileName)); double versionNumber = 1.0; double onset, offset, eOffset, beat, duration; int velocity, pitch, octave; int lineCount = 1; Matcher s = new Matcher(inputFile.readLine()); while (s.hasData()) { eventFlags = 0; beat = UNKNOWN; duration = UNKNOWN; // System.out.println("Processing line " + lineCount); if (s.matchString("info(")) { // meta-data if (s.matchString("timeSignature,")) { numerator = s.getInt(); // ss1 << "beatsPerBar=" << numerator << ends; s.skip('/'); denominator = s.getInt(); // ss2 << "beatUnits=" << denominator; } else if (s.matchString("beatSubdivision,")) { // strcpy(buf, "beatSubdivisions="); // int i = strlen(buf); // f.getline(buf+i, SZ-i, ']'); // strcat(buf, "]"); // parameters->add(buf); s.skip(']'); } else if (s.matchString("matchFileVersion,")) { versionNumber = s.getDouble(); } else if (s.matchString("midiClockUnits,")) { clockUnits = s.getInt(); } else if (s.matchString("midiClockRate,")) { clockRate = s.getInt(); } s.set("%"); // don't expect the second half of the Prolog term } else if (s.matchString("snote(")) { s.skip(','); // identifier s.skip(']'); // note name s.skip(','); // ',' after note name s.skip(','); // octave s.skip(','); // onset time (in beats, integer part, bar:beat) boolean isBt = s.matchString("0"); s.skip(','); // onset time (in beats, fractional part) s.skip(','); // duration (in beats, fraction) try { beat = s.getDouble(); } catch (NumberFormatException e) { System.err.println("Bad beat number on line " + lineCount); beat = UNKNOWN; } if ((beat == Math.rint(beat)) != isBt) System.err.println("Inconsistent beats on line " + lineCount); s.skip(','); // onset time (in beats, decimal) try { duration = s.getDouble() - beat; } catch (NumberFormatException e) { System.err.println("Bad duration on line " + lineCount); duration = UNKNOWN; } s.skip(','); // offset time (in beats, decimal) s.skip('['); // additional info (e.g. melody/arpeggio/grace) do { element = s.getString(); eventFlags |= flags.getFlag(element); } while (s.matchString(",")); s.skip('-'); } else if (s.matchString("trill(")) { eventFlags |= flags.getFlag("trill"); s.skip('-'); } else if (s.matchString("ornament(")) { eventFlags |= flags.getFlag("ornament"); s.skip('-'); } else if (s.matchString("trailing_played_note-") || s.matchString("hammer_bounce-") || s.matchString("no_score_note-") || s.matchString("insertion-")) { eventFlags |= flags.getFlag("unscored"); } else if (!s.matchString("%")) { // Prolog comment throw new MatchFileParseException("error 4; line " + lineCount); } // READ 2nd term of Prolog expression if (s.matchString("note(")) { s.skip('['); // skip identifier String note = s.getString(); switch (Character.toUpperCase(note.charAt(0))) { case 'A': pitch = 9; break; case 'B': pitch = 11; break; case 'C': pitch = 0; break; case 'D': pitch = 2; break; case 'E': pitch = 4; break; case 'F': pitch = 5; break; case 'G': pitch = 7; break; default: throw new MatchFileParseException("Bad note on line " + lineCount); } s.skip(','); String mod = s.getString(); for (int i = 0; i < mod.length(); i++) { switch (mod.charAt(i)) { case '#': pitch++; break; case 'b': pitch--; break; case 'n': break; default: throw new MatchFileParseException("error 5 " + lineCount); } } s.skip(','); octave = s.getInt(); pitch += 12 * octave; s.skip(','); onset = s.getInt(); s.skip(','); offset = s.getInt(); if (versionNumber > 1.0) { s.skip(','); eOffset = s.getInt(); } else eOffset = offset; s.skip(','); velocity = s.getInt(); onset /= clockUnits * 1000000.0 / clockRate; offset /= clockUnits * 1000000.0 / clockRate; eOffset /= clockUnits * 1000000.0 / clockRate; if (timingCorrection) { if (startNote) { timingDisplacement = onset - timingDisplacement; startNote = false; } onset -= timingDisplacement; offset -= timingDisplacement; eOffset -= timingDisplacement; } int m = flags.getFlag("s"); if ((((eventFlags & m) != 0) && !noMelody) || (((eventFlags & m) == 0) && !onlyMelody)) { Event e = new Event(onset, offset, eOffset, pitch, velocity, beat, duration, eventFlags); list.add(e); } } else if (!s.matchString("no_played_note.") && !s.matchString("trailing_score_note.") && !s.matchString("deletion.") && !s.matchString("%")) throw new MatchFileParseException("error 6; line " + lineCount); s.set(inputFile.readLine()); lineCount++; } return list; }
From source file:com.jaspersoft.ireport.jasperserver.ws.CommonsHTTPSender.java
/** * Matches a string against a pattern. The pattern contains two special * characters:// ww w . j a v a 2 s . c om * '*' which means zero or more characters, * * @param pattern the (non-null) pattern to match against * @param str the (non-null) string that must be matched against the * pattern * @param isCaseSensitive * * @return <code>true</code> when the string matches against the pattern, * <code>false</code> otherwise. */ protected static boolean match(String pattern, String str, boolean isCaseSensitive) { char[] patArr = pattern.toCharArray(); char[] strArr = str.toCharArray(); int patIdxStart = 0; int patIdxEnd = patArr.length - 1; int strIdxStart = 0; int strIdxEnd = strArr.length - 1; char ch; boolean containsStar = false; for (int i = 0; i < patArr.length; i++) { if (patArr[i] == '*') { containsStar = true; break; } } if (!containsStar) { // No '*'s, so we make a shortcut if (patIdxEnd != strIdxEnd) { return false; // Pattern and string do not have the same size } for (int i = 0; i <= patIdxEnd; i++) { ch = patArr[i]; if (isCaseSensitive && (ch != strArr[i])) { return false; // Character mismatch } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[i]))) { return false; // Character mismatch } } return true; // String matches against pattern } if (patIdxEnd == 0) { return true; // Pattern contains only '*', which matches anything } // Process characters before first star while ((ch = patArr[patIdxStart]) != '*' && (strIdxStart <= strIdxEnd)) { if (isCaseSensitive && (ch != strArr[strIdxStart])) { return false; // Character mismatch } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxStart]))) { return false; // Character mismatch } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { // All characters in the string are used. Check if only '*'s are // left in the pattern. If so, we succeeded. Otherwise failure. for (int i = patIdxStart; i <= patIdxEnd; i++) { if (patArr[i] != '*') { return false; } } return true; } // Process characters after last star while ((ch = patArr[patIdxEnd]) != '*' && (strIdxStart <= strIdxEnd)) { if (isCaseSensitive && (ch != strArr[strIdxEnd])) { return false; // Character mismatch } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxEnd]))) { return false; // Character mismatch } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { // All characters in the string are used. Check if only '*'s are // left in the pattern. If so, we succeeded. Otherwise failure. for (int i = patIdxStart; i <= patIdxEnd; i++) { if (patArr[i] != '*') { return false; } } return true; } // process pattern between stars. padIdxStart and patIdxEnd point // always to a '*'. while ((patIdxStart != patIdxEnd) && (strIdxStart <= strIdxEnd)) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patArr[i] == '*') { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { // Two stars next to each other, skip the first one. patIdxStart++; continue; } // Find the pattern between padIdxStart & padIdxTmp in str between // strIdxStart & strIdxEnd int patLength = (patIdxTmp - patIdxStart - 1); int strLength = (strIdxEnd - strIdxStart + 1); int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { ch = patArr[patIdxStart + j + 1]; if (isCaseSensitive && (ch != strArr[strIdxStart + i + j])) { continue strLoop; } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxStart + i + j]))) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } // All characters in the string are used. Check if only '*'s are left // in the pattern. If so, we succeeded. Otherwise failure. for (int i = patIdxStart; i <= patIdxEnd; i++) { if (patArr[i] != '*') { return false; } } return true; }
From source file:org.botlibre.util.Utils.java
/** * Capitalize the first character of the string. *//*w w w . j a v a 2 s . c om*/ public static String capitalize(String text) { if (text.length() == 0) { return text; } return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); }
From source file:hudson.Functions.java
/** * Converts "abc" to "Abc".//w w w. j a v a 2s . co m */ public static String capitalize(String s) { if (s == null || s.length() == 0) return s; return Character.toUpperCase(s.charAt(0)) + s.substring(1); }
From source file:CharUtils.java
/** * Make case of string match another string's case. * /*from w ww . j a v a 2 s. c om*/ * @param s * String whose case should be changed. * @param sCaseToMatch * String whose case should be matched. * * @return "s" modified to match case of "sCaseToMatch". * */ public static String makeCaseMatch(String s, String sCaseToMatch) { String result = s; if (isAllCaps(sCaseToMatch)) { result = result.toUpperCase(); } else { boolean isCapitalized = false; if (sCaseToMatch.length() > 0) { if (CharUtils.isSingleQuote(sCaseToMatch.charAt(0))) { isCapitalized = (sCaseToMatch.length() > 1) && CharUtils.isCapitalLetter(sCaseToMatch.charAt(1)); } else { isCapitalized = CharUtils.isCapitalLetter(sCaseToMatch.charAt(0)); } } if (result.length() > 0) { if (CharUtils.isSingleQuote(result.charAt(0))) { String char0 = result.charAt(0) + ""; String rest = ""; if (result.length() > 1) { char char1 = result.charAt(1); if (result.length() > 2) { rest = result.substring(2); } if (isCapitalized) { result = char0 + Character.toUpperCase(char1) + rest; } else { result = char0 + Character.toLowerCase(char1) + rest; } } } else { String rest = ""; char char0 = result.charAt(0); if (result.length() > 1) { rest = result.substring(1); } if (isCapitalized) { result = Character.toUpperCase(char0) + rest; } else { result = Character.toLowerCase(char0) + rest; } } } } return result; }
From source file:com.adito.boot.Util.java
/** * Turn a constant like name into an key like structure. E.g. <i>HTTP_ERROR</i> * would be turned into <i>httpError</i>. * /*from w w w . ja v a 2s . co m*/ * @param constant constant * @return key */ public static String makeConstantKey(String constant) { StringBuffer buf = new StringBuffer(); char ch; boolean firstChar = false; for (int i = 0; i < constant.length(); i++) { ch = constant.charAt(i); if (ch == '_') { firstChar = true; } else { if (firstChar) { ch = Character.toUpperCase(ch); firstChar = false; } else { ch = Character.toLowerCase(ch); } buf.append(ch); } } return buf.toString(); }
From source file:net.jawr.web.resource.bundle.factory.util.PathNormalizer.java
/** * Cygwin prefers lowercase drive letters, but other parts of maven use * uppercase/*from ww w . ja v a 2s.c o m*/ * * @param path * @return String */ static final String uppercaseDrive(String path) { String resultPath = null; if (path != null) { if (path.length() >= 2 && path.charAt(1) == ':') { resultPath = Character.toUpperCase(path.charAt(0)) + path.substring(1); } else { resultPath = path; } } return resultPath; }
From source file:edu.stanford.muse.xword.Crossword.java
public String picClueColumnAsHTML(boolean acrossNotDown, boolean hintsEnabled) throws IOException { StringBuilder sb = new StringBuilder(); int count = 0; for (Word w : placedWords) { if (w.acrossNotDown == acrossNotDown) { Clue clue = w.getClue();//from ww w .j a va 2 s . c om if (clue == null) continue; String hintStr = (hintsEnabled) ? Util.escapeHTML(clue.getHint()) : ""; String awrapper_open = ""; String awrapper_close = ""; String onclick_handler = ""; String attr = "clueNum=\"" + w.getClueNum() + "\" direction=\"" + (w.acrossNotDown ? "across" : "down") + "\""; sb.append(awrapper_open + "<div style=\"display:inline\" title=\"" + hintStr + "\" class=\"clueDiv\" " + onclick_handler + " " + attr + ">"); int cluenum = w.getClueNum(); String clueNumStr = ""; if (cluenum < 10) clueNumStr = " " + Integer.toString(cluenum); else clueNumStr = Integer.toString(cluenum); sb.append("<span style=\"display:inline\" style=\"font-size:9pt\" class=\"clueNum-dummy\">" + clueNumStr + "</span>"); String hint = ""; if (hintsEnabled && !Util.nullOrEmpty(clue.getHint())) hint = clue.getHint(); else if (!Util.nullOrEmpty(w.word)) hint = "Starts with " + Character.toUpperCase(w.word.charAt(0)); // default, simple hint String fullPicURL = clue.getFullPicURL(); if (Util.nullOrEmpty(fullPicURL)) fullPicURL = clue.getPicURL(); sb.append("<a class=\"fancybox\" href=\"" + fullPicURL + "\">"); String pic = clue.getPicURL(); if (!Util.nullOrEmpty(pic)) sb.append("<img title=\"" + hint + "\" src=\"" + pic + "\" height=\"80\"/>"); sb.append("</a>"); sb.append("</div>" + awrapper_close); // answer clue div } if (++count % 3 == 0) sb.append("<br/>"); } } return sb.toString(); }
From source file:com.adito.boot.Util.java
/** * Re-process the case of a space separated string of words. The first * character is capitalised, all others or lower cased. * /*from w w w . ja v a2s .c o m*/ * @param unCased uncased string * @return cased string */ public static String reCase(String unCased) { StringBuffer buf = new StringBuffer(); char ch; boolean wordNext = false; for (int i = 0; i < unCased.length(); i++) { ch = unCased.charAt(i); if (ch == ' ') { wordNext = true; } else { if (wordNext) { ch = Character.toUpperCase(ch); wordNext = false; } else { ch = Character.toLowerCase(ch); } buf.append(ch); } } return buf.toString(); }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
/** * <p>/* ww w .j a va2 s. c o m*/ * Percent-encode/escape an URL path part according to the allowed characters * specified in RFC3986 (formerly RFC1738 and RFC2396). Uses UTF-8 character * codes for non-ASCII. * </p> * <p> * When isPattern is true, the string is processed as a regular expression, and * therefore meta-characters used by the {@link Pattern} class are not * percent-encoded. * </p> * * @param pathToEscape the path part to escape. * @param isPattern when true, regular meta-characters are not escaped * @return an escaped path regular expression with only allowed ASCII * characters, or null when pathPattern is null. * @see <a href="https://tools.ietf.org/html/rfc3986#section-2.1">RFC3986 * percent-encoding section</a> * @see <z href="https://tools.ietf.org/html/rfc3986#appendix-A">RFC3986 path * definition</a> */ private static String escapePath(final String pathToEscape, final boolean isPattern) { if (pathToEscape == null) { return pathToEscape; } final StringBuilder ptmp = new StringBuilder(pathToEscape.length() + 10); boolean modified = false; final int len = pathToEscape.length(); int i = 0; while (i < len) { int ch = pathToEscape.charAt(i); if (ch == '%' && (i + 2) < len) { final char digit1 = pathToEscape.charAt(i + 1); final char digit2 = pathToEscape.charAt(i + 2); if (isHexDigit(digit1) && isHexDigit(digit2)) { /* Already percent-encoded character */ ptmp.append((char) ch); /* Normalize hexadecimal digits to upper case */ if (Character.isLowerCase(digit1) || Character.isLowerCase(digit2)) { modified = true; } ptmp.append(Character.toUpperCase(digit1)); ptmp.append(Character.toUpperCase(digit2)); i += 2; } else { /* Not a valid percent-encoded character : we encode it now */ ptmp.append(hex[ch]); modified = true; } } else if (isPattern && PATTERN_METACHARACTERS.get(ch)) { ptmp.append((char) ch); } else if (ch <= 0x7F) { if (UNRESERVED_PATH.get(ch)) { ptmp.append((char) ch); } else { ptmp.append(hex[ch]); modified = true; } } else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF ptmp.append(hex[0xc0 | (ch >> 6)]); ptmp.append(hex[0x80 | (ch & 0x3F)]); modified = true; } else { // 0x7FF < ch <= 0xFFFF ptmp.append(hex[0xe0 | (ch >> 12)]); ptmp.append(hex[0x80 | ((ch >> 6) & 0x3F)]); ptmp.append(hex[0x80 | (ch & 0x3F)]); modified = true; } i++; } if (modified) { return ptmp.toString(); } return pathToEscape; }