/** returns true iff the target matches the given pattern, * under simplified bash rules -- viz permitting * and ? and comma delimited patterns inside curly braces, * as well as things like {1,2,5-10} (and also {01,02,05-10} to keep leading 0) * @throws InvalidPatternException */ public boolean isGlobMatchedNumeric(String globPattern, String targetText) throws InvalidPatternException { List<String> patterns = expand(globPattern); for (String p : patterns) { if (isNoBraceGlobMatched(p, targetText)) return true; } return false; }
public static String unwrapJavaStringIfWrapped(String s) { if (!StringEscapes.isWrappedInDoubleQuotes(s)) return s; return unwrapJavaString(s); }
public String getMimeType() { assertParsed(); if (mimeType!=null) return mimeType; return DEFAULT_MIME_TYPE; }
public String getSocketUid() { String result = getAttribute(MySqlNode.SOCKET_UID); if (Strings.isBlank(result)) { result = Identifiers.makeRandomId(6); setAttribute(MySqlNode.SOCKET_UID, result); } return result; }
/** cats the given text to the given command, using bash << multi-line input syntax */ public static String pipeTextTo(String text, String command) { String id = Identifiers.makeRandomId(8); return "cat << EOF_"+id+" | "+command+"\n" +text +"\n"+"EOF_"+id+"\n"; }
/** * Returns a sequence of chained commands that runs until one of them fails (i.e. joined by '&&') * This currently runs as a subshell (so exits are swallowed) but behaviour may be changed imminently. * (Use {@link #chainGroup(Collection)} or {@link #chainSubshell(Collection)} to be clear.) */ public static String chain(Collection<String> commands) { return "( " + Strings.join(commands, " && ") + " )"; }
/** returns true iff the target matches the given pattern, * under simplified bash rules -- viz permitting * and ? and comma delimited patterns inside curly braces * @throws InvalidPatternException */ public static boolean isGlobMatched(String globPattern, String targetText) throws InvalidPatternException { List<String> patterns = getGlobsAfterBraceExpansion(globPattern); for (String p : patterns) { if (isNoBraceGlobMatched(p, targetText)) return true; } return false; }
/** * Splits a comma-separated list of locations (names or specs) into an explicit list. * The splitting is very careful to handle commas embedded within specs, to split correctly. */ public static List<String> expandCommaSeparateLocations(String locations) { return WildcardGlobs.getGlobsAfterBraceExpansion("{"+locations+"}", false, PhraseTreatment.INTERIOR_NOT_EXPANDABLE, PhraseTreatment.INTERIOR_NOT_EXPANDABLE); // don't do this, it tries to expand commas inside parentheses which is not good! // QuotedStringTokenizer.builder().addDelimiterChars(",").buildList((String)id); }
/** e.g. editRecord("foo", "A", "1.2.3.4"), which assuming this domain is "bar.com", will create A record for foo.bar.com. * <p> * or editRecord("*.foo", "CNAME", "foo.bar.com") to map everything at *.foo.bar.com to foo.bar.com */ public void editRecord(String subdomainPart, String type, String content) { subdomainPart = Strings.removeFromEnd(subdomainPart, "."+name); editSubdomainRecord(id, subdomainPart, type, content); }
private static String escape(String txt) { txt = Strings.replaceAllNonRegex(txt, "\\", "\\\\"); txt = Strings.replaceAllNonRegex(txt, "'", "\\'"); txt = Strings.replaceAllNonRegex(txt, "\"", "\\\"'"); return txt; }
/** creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); * switches to E notation if needed to fit within maxlen; can be padded left up too (not useful) * @param x number to use * @param maxlen maximum length for the numeric string, if possible (-1 to suppress) * @param prec number of digits accuracy desired (more kept for integers) * @param leftPadLen will add spaces at left if necessary to make string this long (-1 to suppress) [probably not usef] * @return such a string */ public static String makeRealString(double x, int maxlen, int prec, int leftPadLen) { return makeRealString(x, maxlen, prec, leftPadLen, 0.00000000001, true); } /** creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part);
/** wraps a call to {@link String#format(String, Object...)} in a toString, i.e. using %s syntax, * useful for places where we want deferred evaluation * (e.g. as message to {@link Preconditions} to skip concatenation when not needed) */ public static FormattedString format(String pattern, Object... args) { return new FormattedString(pattern, args); }
public synchronized DataUriSchemeParser allowSlashesAfterColon(boolean allowSlashesAfterColon) { assertNotParsed(); this.allowSlashesAfterColon = allowSlashesAfterColon; return this; }
public boolean isGreaterThanAndNotEqualTo(String target) { return compareTo(target) > 0; } public boolean isLessThanOrEqualTo(String target) {
public String getSocketUid() { String result = getAttribute(MariaDbNode.SOCKET_UID); if (Strings.isBlank(result)) setAttribute(MariaDbNode.SOCKET_UID, (result = Identifiers.makeRandomId(6))); return result; }
/** As {@link #chain(Collection)}, but explicitly using { } grouping characters * to ensure exits are propagated. */ public static String chainGroup(Collection<String> commands) { // spaces required around curly braces return "{ " + Strings.join(commands, " && ") + " ; }"; }
/** returns a list with no curly braces in any entries, * and guaranteeing order such that any {..,X,..,Y,..} will result in X being before Y in the resulting list; * e.g. given a{,b,c} gives a ab and ac; no special treatment of numeric ranges, quotes, or parentheses * (see SpecialistGlobExpander for that) */ public static List<String> getGlobsAfterBraceExpansion(String pattern) throws InvalidPatternException { return getGlobsAfterBraceExpansion(pattern, false, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); }
public String getPassword() { String result = getAttribute(MySqlNode.PASSWORD); if (Strings.isBlank(result)) { result = Identifiers.makeRandomId(6); setAttribute(MySqlNode.PASSWORD, result); } return result; }
/** As {@link #alternatives(Collection)}, but explicitly using ( ) grouping characters * to ensure exits are caught. */ public static String alternativesSubshell(Collection<String> commands) { // the spaces are not required, but it might be possible that a (( expr )) is interpreted differently // (won't hurt to have the spaces in any case!) return "( " + Strings.join(commands, " || ") + " )"; }
public String getSummary() { if (summary!=null) return summary; return Strings.join(commands, " ; "); }