List of usage examples for org.apache.commons.lang3 StringUtils splitByWholeSeparatorPreserveAllTokens
public static String[] splitByWholeSeparatorPreserveAllTokens(final String str, final String separator)
Splits the provided text into an array, separator string specified.
From source file:de.jcup.egradle.sdk.builder.action.javadoc.ReplaceJavaDocPartsAction.java
License:asdf
private String replaceDoubleSlashToEndWithCommentTag(String text) { if (text.indexOf("//") == -1) { return text; }/* www . j a va2 s . c o m*/ String[] splitted = StringUtils.splitByWholeSeparatorPreserveAllTokens(text, "\n"); StringBuilder sb = new StringBuilder(); int pos = 0; for (String stext : splitted) { String replaced = replaceCommentInLine(stext); sb.append(replaced); pos++; if (pos < splitted.length) { sb.append("\n"); } } return sb.toString(); }
From source file:com.google.dart.engine.services.internal.correction.CorrectionUtils.java
/** * Indents given source left or right./*from ww w . j a v a 2 s .co m*/ * * @return the source with changed indentation. */ public String getIndentSource(String source, boolean right) { StringBuilder sb = new StringBuilder(); String indent = getIndent(1); String eol = getEndOfLine(); String[] lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(source, eol); for (int i = 0; i < lines.length; i++) { String line = lines[i]; // last line, stop if empty if (i == lines.length - 1 && StringUtils.isEmpty(line)) { break; } // update line if (right) { line = indent + line; } else { line = StringUtils.removeStart(line, indent); } // append line sb.append(line); sb.append(eol); } return sb.toString(); }
From source file:com.google.dart.engine.services.internal.correction.CorrectionUtils.java
/** * @return the source with indentation changed from "oldIndent" to "newIndent", keeping * indentation of the lines relative to each other. *///from w w w . j a v a 2 s. c om public String getIndentSource(String source, String oldIndent, String newIndent) { StringBuilder sb = new StringBuilder(); String eol = getEndOfLine(); String[] lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(source, eol); for (int i = 0; i < lines.length; i++) { String line = lines[i]; // last line, stop if empty if (i == lines.length - 1 && StringUtils.isEmpty(line)) { break; } // line should have new indent line = newIndent + StringUtils.removeStart(line, oldIndent); // append line sb.append(line); sb.append(eol); } return sb.toString(); }
From source file:nl.sidn.dnslib.util.IPUtil.java
public static String expandIPv6(String ip) { String[] sections = StringUtils.splitByWholeSeparatorPreserveAllTokens(ip, ":"); StringBuilder sb = new StringBuilder(); for (String section : sections) { if (section.length() == 0) { int missing = (8 - sections.length) + 1; for (int i = 0; i < missing; i++) { sb.append("0000:"); }// w w w. j av a 2s. c om } else if (section.length() < 4) { String paddedSection = StringUtils.leftPad(section, 4, "0"); sb.append(paddedSection + ":"); } else { sb.append(section + ":"); } } String expanded = sb.toString(); return StringUtils.removeEnd(expanded, ":"); }
From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java
/** * Split target string with custom separator and pick the index-th(start with 0) result. * * @param str target string.//from w w w . j a v a 2 s .com * @param separator custom separator. * @param index index of the result which you want. * @return the string at the index of split results. */ public static String splitIndex(String str, String separator, int index) { if (index < 0) { return null; } String[] values = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separator); if (index >= values.length) { return null; } else { return values[index]; } }
From source file:org.apache.mahout.cf.taste.example.email.MailToRecMapper.java
@Override protected void map(Text key, Text value, Context context) throws IOException, InterruptedException { int msgIdKey = Integer.MIN_VALUE; int fromKey = Integer.MIN_VALUE; String valStr = value.toString(); String[] splits = StringUtils.splitByWholeSeparatorPreserveAllTokens(valStr, separator); if (splits != null && splits.length > 0) { if (splits.length > refsIdx) { String from = EmailUtility.cleanUpEmailAddress(splits[fromIdx]); fromKey = fromDictionary.get(from); }/*from ww w .ja v a 2s .c o m*/ //get the references if (splits.length > refsIdx) { String[] theRefs = EmailUtility.parseReferences(splits[refsIdx]); if (theRefs != null && theRefs.length > 0) { //we have a reference, the first one is the original message id, so map to that one if it exists msgIdKey = msgIdDictionary.get(theRefs[0]); context.getCounter(Counters.REFERENCE).increment(1); } } } //we don't have any references, so use the msg id if (msgIdKey == Integer.MIN_VALUE) { //get the msg id and the from and output the associated ids String keyStr = key.toString(); int idx = keyStr.lastIndexOf('/'); if (idx != -1) { String msgId = keyStr.substring(idx + 1); msgIdKey = msgIdDictionary.get(msgId); context.getCounter(Counters.ORIGINAL).increment(1); } } if (msgIdKey != Integer.MIN_VALUE && fromKey != Integer.MIN_VALUE) { context.write(new Text(fromKey + "," + msgIdKey), new LongWritable(1)); } }
From source file:org.apache.nifi.registry.security.util.ProxiedEntitiesUtils.java
/** * Tokenizes the specified proxy chain.// ww w. ja va 2 s. co m * * @param rawProxyChain raw chain * @return tokenized proxy chain */ public static List<String> tokenizeProxiedEntitiesChain(String rawProxyChain) { final List<String> proxyChain = new ArrayList<>(); if (!StringUtils.isEmpty(rawProxyChain)) { // Split the String on the >< token List<String> elements = Arrays .asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(rawProxyChain, "><")); // Unsanitize each DN and collect back elements = elements.stream().map(ProxiedEntitiesUtils::unsanitizeDn).collect(Collectors.toList()); // Remove the leading < from the first element elements.set(0, elements.get(0).replaceFirst(LT, "")); // Remove the trailing > from the last element int last = elements.size() - 1; String lastElement = elements.get(last); if (lastElement.endsWith(GT)) { elements.set(last, lastElement.substring(0, lastElement.length() - 1)); } proxyChain.addAll(elements); } return proxyChain; }
From source file:org.omnaest.utils.structure.container.ByteArrayContainer.java
/** * Returns the content as a list of strings, separated by an arbitrary regular expression. * /*from w w w . ja v a 2s. c o m*/ * @param encoding * : for example = "utf-8" * @see #ENCODING_UTF8 * @return */ public List<String> toStringList(String encoding, String regExDelimiter) { // List<String> retlist = new ArrayList<String>(); // String content = this.toString(encoding); // final String tokenDelimiter = "}>|<{"; content = content.replaceAll(regExDelimiter, tokenDelimiter); String[] lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(content, tokenDelimiter); CollectionUtils.addAll(retlist, lines); // return retlist; }
From source file:org.xwiki.rendering.internal.parser.xhtml.wikimodel.XHTMLMarkerResourceReferenceParser.java
@Override public ResourceReference parse(String rawReference) { String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(rawReference, COMMENT_SEPARATOR); boolean isTyped = tokens[0].equalsIgnoreCase("true") ? true : false; ResourceType type = new ResourceType(tokens[1]); String reference = tokens[2]; ResourceReference resourceReference = new ResourceReference(reference, type); resourceReference.setTyped(isTyped); if (tokens.length == 4) { for (WikiParameter parameter : WikiParameters.newWikiParameters(tokens[3])) { resourceReference.setParameter(parameter.getKey(), parameter.getValue()); }//from w w w . ja v a2s . co m } return resourceReference; }