List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:com.healthmarketscience.jackcess.util.ExportUtil.java
/** * Copy a table in this database into a new delimited text file. * //w w w .j a v a 2 s . c o m * @param cursor * Cursor to export * @param out * Writer to export to * @param header * If <code>true</code> the first line contains the column names * @param delim * The column delimiter, <code>null</code> for default (comma) * @param quote * The quote character * @param filter * valid export filter * * @see Builder */ public static void exportWriter(Cursor cursor, BufferedWriter out, boolean header, String delim, char quote, ExportFilter filter) throws IOException { String delimiter = (delim == null) ? DEFAULT_DELIMITER : delim; // create pattern which will indicate whether or not a value needs to be // quoted or not (contains delimiter, separator, or newline) Pattern needsQuotePattern = Pattern .compile("(?:" + Pattern.quote(delimiter) + ")|(?:" + Pattern.quote("" + quote) + ")|(?:[\n\r])"); List<? extends Column> origCols = cursor.getTable().getColumns(); List<Column> columns = new ArrayList<Column>(origCols); columns = filter.filterColumns(columns); Collection<String> columnNames = null; if (!origCols.equals(columns)) { // columns have been filtered columnNames = new HashSet<String>(); for (Column c : columns) { columnNames.add(c.getName()); } } // print the header row (if desired) if (header) { for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { writeValue(out, iter.next().getName(), quote, needsQuotePattern); if (iter.hasNext()) { out.write(delimiter); } } out.newLine(); } // print the data rows Object[] unfilteredRowData = new Object[columns.size()]; Row row; while ((row = cursor.getNextRow(columnNames)) != null) { // fill raw row data in array for (int i = 0; i < columns.size(); i++) { unfilteredRowData[i] = columns.get(i).getRowValue(row); } // apply filter Object[] rowData = filter.filterRow(unfilteredRowData); if (rowData == null) { continue; } // print row for (int i = 0; i < columns.size(); i++) { Object obj = rowData[i]; if (obj != null) { String value = null; if (obj instanceof byte[]) { value = ByteUtil.toHexString((byte[]) obj); } else { value = String.valueOf(rowData[i]); } writeValue(out, value, quote, needsQuotePattern); } if (i < columns.size() - 1) { out.write(delimiter); } } out.newLine(); } out.flush(); }
From source file:feedsplugin.FeedsPlugin.java
private String quoteTitle(final String programTitle) { return ".*\\b" + Pattern.quote(programTitle) + "\\b.*"; }
From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java
private static ArrayList<Double> getFailureProbs() { ArrayList<Double> pfs = new ArrayList<>(); String sDirectorio = experimentsDir; System.out.println("experiments dir" + sDirectorio); File f = new File(sDirectorio); String extension;//from w w w .jav a 2 s .c om File[] files = f.listFiles(); for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("experiment") && file.getName().contains(mazeMode)) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[2]); double pf = Double.valueOf(filenamep[4]); String mode = filenamep[6]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[8]); //} System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); System.out.println("pf:" + pf); if (!pfs.contains(pf)) { pfs.add(pf); } } } System.out.println("pfs" + pfs); return pfs; }
From source file:com.adobe.ags.curly.controller.ActionRunner.java
private String tokenizeParameters(String str) { Set<String> variableTokens = ActionUtils.getVariableNames(action); int tokenCounter = 0; for (String var : variableTokens) { String varPattern = Pattern.quote("${") + var + "(\\|.*?)?" + Pattern.quote("}"); str = str.replaceAll(varPattern, Matcher.quoteReplacement("${" + (tokenCounter++) + "}")); }/* w ww. j ava 2 s. c o m*/ return str; }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.JSONTypesExtractorImpl.java
/** * This method undoes what addPrefixToJSONKeysEndingsRecursive method did at the original JSON: It looks * for elements whose name ends at a desired key ending preceeded by a prefix to remove and removes it. * @param rootElement the root element./*ww w . j a v a2 s .c o m*/ * @param desiredKeyEnding the desired ending. * @param prefixToRemove the prefix to remove. */ private void removePrefixToElementNameEndings(Element rootElement, String desiredKeyEnding, String prefixToRemove) { String keyToSearch = prefixToRemove + desiredKeyEnding; for (Element element : rootElement.getDescendants(Filters.element())) { if (!(element.getName().endsWith(keyToSearch) && element.getNamespace().equals(Namespace.NO_NAMESPACE))) { continue; } String name = element.getName(); String newName = name.replaceAll(Pattern.quote(keyToSearch) + "$", desiredKeyEnding); element.setName(newName); } }
From source file:de.tbuchloh.kiskis.persistence.PersistenceManager.java
/** * @param docFile/*www. jav a2s . c om*/ * the document file * @return the pattern which attachment files need to fulfill */ private static String createAttachmentNamePattern(File docFile) { return Pattern.quote(docFile.getName()) + "\\.attachment\\.[0-9]+"; }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProvider.java
private static File findHadoopCommandFromPath(Map<String, String> envp) { String path = envp.get(ENV_PATH); if (path != null && path.trim().isEmpty() == false) { String[] pathPrefixArray = path.split(Pattern.quote(File.pathSeparator)); for (String prefix : pathPrefixArray) { String p = prefix.trim(); if (p.isEmpty()) { continue; }/* w w w . j av a2s.c o m*/ File bin = new File(p); if (bin.isDirectory() == false) { continue; } File command = new File(bin, PATH_HADOOP_COMMAND_FILE); if (command.canExecute()) { return command; } } } return null; }
From source file:uk.ac.kcl.at.ElasticGazetteerAcceptanceTest.java
private int getFalsePositiveTokenCount(Mutant mutant) { int count = 0; Pattern mask = Pattern.compile("X+"); List<MatchResult> results = new ArrayList<>(); Matcher matcher = mask.matcher(mutant.getDeidentifiedString()); while (matcher.find()) { results.add(matcher.toMatchResult()); }//w ww . j a va 2s. c om for (MatchResult result : results) { StringTokenizer tokenizer = new StringTokenizer( mutant.getFinalText().substring(result.start(), result.end())); ArrayList<String> arHits = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { arHits.add(tokenizer.nextToken()); } for (String hit : arHits) { boolean isAnIdentifier = false; for (String token : mutant.getOutputTokens()) { if (hit.matches(Pattern.quote(token))) { isAnIdentifier = true; } } if (!isAnIdentifier && !hit.equalsIgnoreCase("") && !hit.equalsIgnoreCase("-")) { count++; } } } return count; }
From source file:com.mirth.connect.model.converters.ER7Serializer.java
public Map<String, String> getMetadataFromEncoded(String source) throws SerializerException { Map<String, String> metadata = new HashMap<String, String>(); if (useStrictParser) { try {//from ww w. j a v a 2 s. c om // XXX: This had a replaceAll("\n", "\r") before 1.7 Message message = pipeParser.parse(source.trim()); Terser terser = new Terser(message); metadata.put("version", message.getVersion()); metadata.put("type", terser.get("/MSH-9-1") + "-" + terser.get("/MSH-9-2")); metadata.put("source", terser.get("/MSH-4-1")); } catch (Exception e) { new SerializerException(e); } return metadata; } else { // XXX: This had a replaceAll("\n", "\r") before 1.7 source = source.trim(); if ((source == null) || (source.length() < 3)) { logger.error("Unable to parse, message is null or too short: " + source); throw new SerializerException("Unable to parse, message is null or too short: " + source); } else if (source.substring(0, 3).equalsIgnoreCase("MSH")) { String segmentDelimeter = "\r"; String fieldDelimeter = String.valueOf(source.charAt(3)); String elementDelimeter = String.valueOf(source.charAt(4)); String mshFields[] = source.split(segmentDelimeter)[0].split(Pattern.quote(fieldDelimeter)); Pattern elementPattern = Pattern.compile(Pattern.quote(elementDelimeter)); if (mshFields.length > 8) { // MSH.9 String[] msh9 = elementPattern.split(mshFields[8]); // MSH.9.1 String type = msh9[0]; if (msh9.length > 1) { // MSH.9.2 type += "-" + msh9[1]; } metadata.put("type", type); } else { metadata.put("type", "Unknown"); } if (mshFields.length > 3) { // MSH.4.1 metadata.put("source", elementPattern.split(mshFields[3])[0]); } else { metadata.put("source", ""); } if (mshFields.length > 11) { // MSH.12.1 metadata.put("version", elementPattern.split(mshFields[11])[0]); } else { metadata.put("version", ""); } } else { metadata.put("type", "Unknown"); metadata.put("source", "Unknown"); metadata.put("version", "Unknown"); } return metadata; } }
From source file:com.qmetry.qaf.automation.step.StringTestStep.java
private void absractArgsAandSetDesciption() { String prefix = BDDKeyword.getKeywordFrom(name); if (actualArgs == null || actualArgs.length == 0) { final String REGEX = ParamType.getParamValueRegx(); List<String> arguments = new ArrayList<String>(); description = removePrefix(prefix, name); Pattern p = Pattern.compile(REGEX); Matcher m = p.matcher(description); // get a matcher object int count = 0; while (m.find()) { String arg = description.substring(m.start(), m.end()); arguments.add(arg);//w w w .j av a 2 s . c o m count++; } for (int i = 0; i < count; i++) { description = description.replaceFirst(Pattern.quote(arguments.get(i)), Matcher.quoteReplacement("{" + i + "}")); } actualArgs = arguments.toArray(new String[] {}); } name = StringUtil.toCamelCaseIdentifier(description.length() > 0 ? description : name); }