List of usage examples for java.text CharacterIterator DONE
char DONE
To view the source code for java.text CharacterIterator DONE.
Click Source Link
From source file:stg.utils.StringUtils.java
/** * Extracts the <i>n</i>th token from the given string after splitting by the given separator char. * Example: The String "Kedar#Raybagkar/#Test" with the separator char # and escape char as / then token 2 will return * "Raybagkar/".//from ww w .j a v a 2 s .c o m * * @param text String to be tokenized. * @param seperatorChar used as a delimiter char. * @param tokenNumber * @return String */ public static String extractTokenAt(String text, char seperatorChar, int tokenNumber) { return extractTokenAt(text, seperatorChar, CharacterIterator.DONE, tokenNumber); }
From source file:net.pms.encoders.FFmpegVideo.java
/** * Returns a list of strings representing the rescale options for this transcode i.e. the ffmpeg -vf * options used to show subtitles in SSA/ASS format and resize a video that's too wide and/or high for the specified renderer. * If the renderer has no size limits, or there's no media metadata, or the video is within the renderer's * size limits, an empty list is returned. * * @param dlna The DLNA resource representing the file being transcoded. * @param media the media metadata for the video being streamed. May contain unset/null values (e.g. for web videos). * @param params The {@link net.pms.io.OutputParams} context object used to store miscellaneous parameters for this request. * @return a {@link List} of <code>String</code>s representing the rescale options for this video, * or an empty list if the video doesn't need to be resized. *///from w w w . j a v a 2 s. c o m public List<String> getVideoFilterOptions(DLNAResource dlna, DLNAMediaInfo media, OutputParams params) throws IOException { List<String> options = new ArrayList<String>(); String subsOption = null; String padding = null; final RendererConfiguration renderer = params.mediaRenderer; DLNAMediaSubtitle tempSubs = null; if (!isDisableSubtitles(params)) { tempSubs = getSubtitles(params); } final boolean isResolutionTooHighForRenderer = renderer.isVideoRescale() // renderer defines a max width/height && (media != null && media.isMediaparsed()) && ((media.getWidth() > renderer.getMaxVideoWidth()) || (media.getHeight() > renderer.getMaxVideoHeight())); if (tempSubs != null) { StringBuilder s = new StringBuilder(); CharacterIterator it = new StringCharacterIterator( ProcessUtil.getShortFileNameIfWideChars(tempSubs.getExternalFile().getAbsolutePath())); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { switch (ch) { case ':': s.append("\\\\:"); break; case '\\': s.append("/"); break; case ']': s.append("\\]"); break; case '[': s.append("\\["); break; default: s.append(ch); } } String subsFile = s.toString(); subsFile = subsFile.replace(",", "\\,"); subsOption = "subtitles=" + subsFile; } if (renderer.isPadVideoWithBlackBordersTo169AR() && renderer.isRescaleByRenderer()) { if (media != null && media.isMediaparsed() && media.getHeight() != 0 && (media.getWidth() / (double) media.getHeight()) >= (16 / (double) 9)) { padding = "pad=iw:iw/(16/9):0:(oh-ih)/2"; } else { padding = "pad=ih*(16/9):ih:(ow-iw)/2:0"; } } String rescaleSpec = null; if (isResolutionTooHighForRenderer || (renderer.isPadVideoWithBlackBordersTo169AR() && !renderer.isRescaleByRenderer())) { rescaleSpec = String.format( // http://stackoverflow.com/a/8351875 "scale=iw*min(%1$d/iw\\,%2$d/ih):ih*min(%1$d/iw\\,%2$d/ih),pad=%1$d:%2$d:(%1$d-iw)/2:(%2$d-ih)/2", renderer.getMaxVideoWidth(), renderer.getMaxVideoHeight()); } String overrideVF = renderer.getFFmpegVideoFilterOverride(); if (rescaleSpec != null || padding != null || overrideVF != null || subsOption != null) { options.add("-vf"); StringBuilder filterParams = new StringBuilder(); if (overrideVF != null) { filterParams.append(overrideVF); if (subsOption != null) { filterParams.append(", "); } } else { if (rescaleSpec != null) { filterParams.append(rescaleSpec); if (subsOption != null || padding != null) { filterParams.append(", "); } } if (padding != null && rescaleSpec == null) { filterParams.append(padding); if (subsOption != null) { filterParams.append(", "); } } } if (subsOption != null) { filterParams.append(subsOption); } options.add(filterParams.toString()); } return options; }
From source file:org.apache.fop.svg.ACIUtils.java
/** * Dumps the contents of an ACI to System.out. Used for debugging only. * @param aci the ACI to dump/*w ww . ja v a2 s. c o m*/ */ public static void dumpAttrs(AttributedCharacterIterator aci) { aci.first(); Set<Entry<Attribute, Object>> entries = aci.getAttributes().entrySet(); for (Map.Entry<Attribute, Object> entry : entries) { if (entry.getValue() != null) { System.out.println(entry.getKey() + ": " + entry.getValue()); } } int start = aci.getBeginIndex(); System.out.print("AttrRuns: "); while (aci.current() != CharacterIterator.DONE) { int end = aci.getRunLimit(); System.out.print("" + (end - start) + ", "); aci.setIndex(end); if (start == end) { break; } start = end; } System.out.println(""); }
From source file:org.fracturedatlas.athena.web.manager.RecordManager.java
static Set<String> parseValues(String valueString) { HashSet<String> values = new HashSet<String>(); valueString = StringUtils.trimToEmpty(valueString); valueString = StringUtils.strip(valueString, "()"); valueString = StringUtils.trimToEmpty(valueString); CharacterIterator it = new StringCharacterIterator(valueString); boolean inString = false; int begin = 0; int end = 0;/*from w w w . j a v a 2 s. c om*/ int numValues = 0; StringBuilder sb = new StringBuilder(); // Iterate over the characters in the forward direction for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { if (ch == '\"') { inString = true; ch = it.next(); sb = new StringBuilder(); for (; ch != CharacterIterator.DONE; ch = it.next()) { if (ch == '\\') { // skip any " in a string sb.append(ch); ch = it.next(); } else if (ch == '\"') { break; } sb.append(ch); } inString = false; values.add(StringUtils.trimToEmpty(sb.toString())); } else if (ch == ',') { // new value } else if (" \t\n\r".indexOf(ch) > -1) { //skip whitespace } else { // not a comma, whitespace or a string start sb = new StringBuilder(); for (; ch != CharacterIterator.DONE; ch = it.next()) { if (ch == ',') { break; } sb.append(ch); } inString = false; values.add(StringUtils.trimToEmpty(sb.toString())); } } return values; }
From source file:org.architecturerules.domain.SourceDirectory.java
/** * <p>Replaces inappropriate backslash with the appropriate slash based on the operating system's requirements</p> * * <p>For example, on a Windows system, <tt>src/main/resources</tt> becomes <tt>src\\main\\resource</tt></p> * * <p>TODO: this may be able to be replaced with String.replaceAll, but I couldn't get the regex just right</p> * * <p>This todo/issue is open at <a href="http://code.google.com/p/architecturerules/issues/detail?id=29">issue * 29</a></p>//from www. j a va2s . co m * * @param path String the path to fix * @return String the fixed path */ String replaceBackslashForOS(final String path) { final StringBuffer result = new StringBuffer(); final StringCharacterIterator iterator = new StringCharacterIterator(path); char character = iterator.current(); final char goal = File.separator.toCharArray()[0]; final char target = ((goal == '\\') ? '/' : '\\'); while (character != CharacterIterator.DONE) { result.append((character == target) ? goal : character); character = iterator.next(); } return result.toString(); }
From source file:hudson.plugins.dimensionsscm.DimensionsChangeLogWriter.java
private static String escapeXML(String inTxt) { if (inTxt == null || inTxt.length() == 0) return inTxt; final StringBuilder outTxt = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(inTxt); char character = iterator.current(); // Scan through strings and escape as necessary... while (character != CharacterIterator.DONE) { if (character == '<') { outTxt.append("<"); } else if (character == '>') { outTxt.append(">"); } else if (character == '\"') { outTxt.append("""); } else if (character == '\'') { outTxt.append("'"); } else if (character == '&') { outTxt.append("&"); } else {/*from ww w. j av a 2 s. c o m*/ outTxt.append(character); } character = iterator.next(); } return outTxt.toString(); }
From source file:org.squale.welcom.outils.Util.java
public static String formatJavaScript(String st) { if (st == null) { return ""; }/* ww w.j a v a 2s .c om*/ st = st.replaceAll("\r\n", "\\n"); final StringBuffer sb = new StringBuffer(); final StringCharacterIterator iter = new StringCharacterIterator(st); for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { switch (c) { case '\t': sb.append("\\t"); break; case '\n': sb.append("\\n"); break; case '\'': sb.append("\\'"); break; case '\"': sb.append("\\""); break; case '&': sb.append("&"); break; case '>': sb.append(">"); break; case '<': sb.append("<"); break; default: sb.append(c); break; } } return sb.toString(); }
From source file:org.fracturedatlas.athena.search.AthenaSearch.java
public static Set<String> parseValues(String valueString) { HashSet<String> values = new HashSet<String>(); valueString = StringUtils.trimToEmpty(valueString); valueString = StringUtils.strip(valueString, "()"); valueString = StringUtils.trimToEmpty(valueString); CharacterIterator it = new StringCharacterIterator(valueString); boolean inString = false; int begin = 0; int end = 0;//from w ww . jav a2 s .c om int numValues = 0; StringBuilder sb = new StringBuilder(); // Iterate over the characters in the forward direction for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { if (ch == '\"') { inString = true; ch = it.next(); sb = new StringBuilder(); for (; ch != CharacterIterator.DONE; ch = it.next()) { if (ch == '\\') { // skip any " in a string sb.append(ch); ch = it.next(); } else if (ch == '\"') { break; } sb.append(ch); } inString = false; values.add(StringUtils.trimToEmpty(sb.toString())); } else if (ch == ',') { // new value } else if (" \t\n\r".indexOf(ch) > -1) { //skip whitespace } else { // not a comma, whitespace or a string start sb = new StringBuilder(); for (; ch != CharacterIterator.DONE; ch = it.next()) { if (ch == ',') { break; } sb.append(ch); } inString = false; values.add(StringUtils.trimToEmpty(sb.toString())); } } return values; }
From source file:Base64.java
public static byte[] decodeUU(String s) { s = s.replaceAll("\r\n|\r|\n|\u2028|\u2029", "\n").trim(); if (s.startsWith("begin ") && s.endsWith("\nend")) { int o = s.indexOf('\n'); int e = s.length() - 4; s = s.substring(o, e).trim();//from w ww . j ava2 s . com } CharacterIterator it = new StringCharacterIterator(s); ByteArrayOutputStream out = new ByteArrayOutputStream(); int i = 0, j = 0; for (char ch = it.first(); ch != CharacterIterator.DONE && ch != '`'; ch = it.next()) { if (ch <= ' ' || ch >= '`') continue; while (true) { int v = (int) (it.next() - ' '); if (v >= 0 && v < 64) { i = (i << 6) | v; j++; if (j >= 4) { out.write(i >> 16); out.write(i >> 8); out.write(i); i = 0; j = 0; } } else { break; } } } switch (j) { case 3: out.write(i >> 10); out.write(i >> 2); break; case 2: out.write(i >> 4); break; } return out.toByteArray(); }
From source file:hudson.plugins.dimensionsscm.DimensionsChangeLogWriter.java
private static String escapeHTML(String inTxt) { if (inTxt == null || inTxt.length() == 0) return inTxt; final StringBuilder outTxt = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(inTxt); char character = iterator.current(); // Scan through strings and escape as necessary... while (character != CharacterIterator.DONE) { if (character == '<') { outTxt.append("<"); } else if (character == '>') { outTxt.append(">"); } else if (character == '\"') { outTxt.append("""); } else if (character == '\'') { outTxt.append("'"); } else if (character == '&') { outTxt.append("&"); } else if (character == ' ') { outTxt.append(" "); } else {//from w w w .ja v a 2s. c om outTxt.append(character); } character = iterator.next(); } return outTxt.toString(); }