private static String escape(String txt) { txt = Strings.replaceAllNonRegex(txt, "\\", "\\\\"); txt = Strings.replaceAllNonRegex(txt, "'", "\\'"); txt = Strings.replaceAllNonRegex(txt, "\"", "\\\"'"); return txt; }
/** NON-REGEX replaceAll - see the better, explicitly named {@link #replaceAllNonRegex(String, String, String)}. */ public static String replaceAll(String source, String pattern, String replacement) { return replaceAllNonRegex(source, pattern, replacement); }
/** NON-REGEX - replaces all key->value entries from the replacement map in source (non-regex) */ @SuppressWarnings("rawtypes") public static String replaceAll(String source, Map replacements) { for (Object rr: replacements.entrySet()) { Map.Entry r = (Map.Entry)rr; source = replaceAllNonRegex(source, ""+r.getKey(), ""+r.getValue()); } return source; }
@Override public String apply(MavenArtifact artifact) { return System.getProperty("user.home")+"/.m2/repository/"+ Strings.replaceAllNonRegex(artifact.groupId, ".", "/")+"/"+ artifact.artifactId+"/"+artifact.version+"/"+ artifact.getFilename(); } };
public void testReplaceAllNonRegex() { assertEquals(Strings.replaceAllNonRegex("xyz", "x", ""), "yz"); assertEquals(Strings.replaceAllNonRegex("xyz", ".", ""), "xyz"); assertEquals(Strings.replaceAllNonRegex("http://foo.com/", "/", ""), "http:foo.com"); assertEquals(Strings.replaceAllNonRegex("http://foo.com/", "http:", "https:"), "https://foo.com/"); }
@Override public String apply(MavenArtifact artifact) { return "http://search.maven.org/remotecontent?filepath="+ Urls.encode(Strings.replaceAllNonRegex(artifact.groupId, ".", "/")+"/"+ artifact.artifactId+"/"+artifact.version+"/"+ artifact.getFilename()); } };
@Test(groups="Integration") public void testRemoveRequireTtyFromSudoersFile() throws Exception { String cmds = BashCommands.dontRequireTtyForSudo(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ByteArrayOutputStream errStream = new ByteArrayOutputStream(); String cmdsWithReplacedSudoersName = Strings.replaceAllNonRegex(cmds, "/etc/sudoers", tmpSudoersFile.getAbsolutePath()); int exitcode = loc.execCommands(ImmutableMap.of("out", outStream, "err", errStream), "removeRequireTtyFromSudoersFile", ImmutableList.of(cmdsWithReplacedSudoersName)); String outstr = new String(outStream.toByteArray()); String errstr = new String(errStream.toByteArray()); assertEquals(0, exitcode); // visudo returns "parsed OK" assertTrue(outstr.contains("parsed OK"), "out="+outstr+"; err="+errstr); assertTrue(errstr.isEmpty(), "out="+outstr+"; err="+errstr); }
@Test public void testReadConfigInheritance_2016_11() throws Exception { doReadConfigInheritance("basic-2016-11", "kmpez5fznt"); checkNewAppNonInheritingKey1(rebindedApp); String origMementoTidied = origMemento.substring(origMemento.indexOf("<entity>")); origMementoTidied = Strings.replaceAllNonRegex(origMementoTidied, "VERSION", BrooklynVersion.get()); Asserts.assertEquals(origMementoTidied, newMemento.replaceAll("\n.*searchPath.*\n", "\n")); }
if (match!=null) { if (rootItemYaml.startsWith(match)) rootItemYaml = Strings.removeFromStart(rootItemYaml, match); else rootItemYaml = Strings.replaceAllNonRegex(rootItemYaml, "\n"+match, "");