Simple formatter. Replaces strings of the form "{0}", "{1}" etc. with the
corresponding parameters.

@param format String with "{0}", "{1}" placeholders.
@param params First parameter will be placed in "{0}" placeholder.

@return Formatted string
485094
public static final String format(final String format, final Object... params)
    {
        final StringBuilder b = new StringBuilder();

        int p = 0;

        while (true)
        {
            final int i = format.indexOf('{', p);

            if (i == -1)
            {
                break;// done
            }
            final int i2 = format.indexOf('}', i + 1);

            if (i2 == -1)
            {
                break;// done
            }
            if (p != i)
            {
                b.append(format.substring(p, i));
            }
            final String nstr = format.substring(i + 1, i2);

            try
            {
                final int n = Integer.parseInt(nstr);

                if ((n >= 0) && (n < params.length))
                {
                    b.append(params[n]);
                }
                else
                {
                    b.append('{').append(nstr).append('}');
                }
            }
            catch (final NumberFormatException e)
            {
                b.append('{').append(nstr).append('}');
            }
            p = i2 + 1;
        }
        b.append(format.substring(p));

        return b.toString();
    }
1149927
public static String format(final Date date, final String format) {
		return format(date.getTime(), format);
	}
685950
private StringBuilder format(final MapFormat format, final StringBuilder sb) {
        if (format == null) {
            appendMap(sb);
        } else {
            switch (format) {
                case XML : {
                    asXml(sb);
                    break;
                }
                case JSON : {
                    asJson(sb);
                    break;
                }
                case JAVA : {
                    asJava(sb);
                    break;
                }
                default : {
                    appendMap(sb);
                }
            }
        }
        return sb;
    }
1025427
public static String replace(final String str, final Map<String, String> params) {
        final StringBuilder sb = new StringBuilder(str.length());
        final char[] strArray = str.toCharArray();
        int i = 0;
        while (i < strArray.length - 1) {
            if (strArray[i] == VAR_START && strArray[i + 1] == VAR_LEFT_BOUND) {
                i = i + 2;
                final int begin = i;
                while (strArray[i] != VAR_RIGHT_BOUND) {
                    ++i;
                }
                final String var = str.substring(begin, i++);
                Preconditions.checkState(params.containsKey(var), "No value provided for variable '%s' "
                        + "in string '%s'", var, str);
                final String value = params.get(var).trim();
                sb.append(value);
            } else {
                sb.append(strArray[i]);
                ++i;
            }
        }
        if (i < strArray.length) {
            sb.append(strArray[i]);
        }
        return sb.toString();
    }
440301
private String convertString(String str, String format, String expr)
    {
        String ret = str;

        String[] params = null;
        if(format.length() > 0)
        {
            ret = "";
            if(expr.length() > 0) // Indicates a format using regex
            {

                Pattern pattern = getPattern(expr);
                Matcher m = pattern.matcher(str);
                if(m.find())
                {
                    params = new String[m.groupCount()];
                    for(int i = 0; i < m.groupCount(); i++)
                        params[i] = m.group(i+1);
                }
            }
            else if(str != null)
            {
                params = new String[]{str};
            }

            if(params != null)
                ret = String.format(format, params);
        }

        return ret;
    }
169710
protected String format(String key, String defaultPattern, Object... args) {
        String escape = escape(defaultPattern);
        String s = lookupPattern(key, escape);
        Object[] objects = escapeAll(args);
        return MessageFormat.format(s, objects);
    }
1013127
private Format getFormat(String desc)
    {

        if (registry != null)
        {
            String name = desc;
            String args = "";
            int i = desc.indexOf(START_FMT);
            if (i > 0)
            {
                name = desc.substring(0, i).trim();
                args = desc.substring(i + 1).trim();
            }
            FormatFactory factory = registry.get(name);
            if (factory != null)
            {
                return factory.getFormat(name, args, getLocale());
            }
        }
        return null;

    }
1299179
public String format(String format)
  {
    CharBuffer cb = new CharBuffer();

    return format(cb, format).close();
  }
1199261
function(source, params) {
				var format = ($.calendarsPicker.curInst ?
					$.calendarsPicker.curInst.get('dateFormat') :
					$.calendarsPicker.defaultOptions.dateFormat);
				$.each(params, function(index, value) {
					source = source.replace(new RegExp('\\{' + index + '\\}', 'g'),
						value.formatDate(format) || 'nothing');
				});
				return source;
			}
1329368
protected String dateToString(LocalDate localDate, String format) {
        return localDate == null ? "----------" : localDate.toString(format);
    }
169999
public static String formatQuery(Map<String, String> params) {
        StringBuilder query = new StringBuilder();
        for (Entry<String, String> entry : params.entrySet()) {
            try {
                query.append(URLEncoder.encode(entry.getKey(), "UTF-8")).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8"))
                .append("&");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }
        return query.deleteCharAt(query.length() - 1).toString();
    }
1123901
function buildFormat(format) {
  return format.v.map(x=> typeof x === 'string' ? x :
               '{' + x.p + ('o' in x ? '>' + x.o : '') + '}').join('') +
        (format.o ? '>>' + Object.keys(format.o).map(x => OPTIONS[x]).join('') : '');
}
1110153
public static String formatDate(java.util.Date pDate, String format) {

        if (pDate == null) {
            pDate = new java.util.Date();
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(pDate);
    }
1225038
public String format(String key, Object ... params) {
        ResourceBundle bundle = getBundle();
        if (bundle.containsKey(key)) {
            String msg = bundle.getString(key);
            return MessageFormat.format(msg, params);
        } else {
            return MessageFormat.format("!!{0}!!", key); //$NON-NLS-1$
        }
    }
912966
private String parameterToString(Object param) {
        if (param == null) {
            return "";
        } else if (param instanceof Date) {
            return formatDate((Date) param);
        } else if (param instanceof Collection) {
            StringBuilder b = new StringBuilder();
            for (Object o : (Collection) param) {
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append(String.valueOf(o));
            }
            return b.toString();
        } else {
            return String.valueOf(param);
        }
    }
1047033
public String format() {
        String result = message;
        for (Object object : objects) {
            String s = result.replaceFirst("%%", Matcher.quoteReplacement(stringify(object)));
            if (result.equals(s)) {
                throw new IllegalStateException("Too many parameters");
            }
            result = s;
        }
        if (result.contains("%%")) {
            throw new IllegalStateException("Not enough parameters");
        }
        return result;
    }
50027
public static String format(String pattern, Object... arguments) {
        String msg = pattern;
        if (arguments != null) {
            for (int index = 0; index < arguments.length; index++) {
                msg = msg.replaceAll("\\{" + (index + 1) + "\\}", String.valueOf(arguments[index]));
            }
        }
        return msg;
    }