/** * Replaces parameters in the string with values specified. * * <p> * * <p>For example a string like 'My name is <name>' and you provide {@code Param.P("name", * "rojoss")} it would return 'My name is rojoss' <b>Notice how there is no < and > sign * around the parameter name for {@link Param}!</b> If the message doesn't have parameters * specified nothing will happen. * * <p> * * <p><b>No need to call this for messages from {@link Msg#get(String, Param...)} as that already * replaces the specified params using this method</b> * * <p>It does not affect JSON messages unless used before parsing to JSON. * * <p> * * <p>It supports capitalization for parameters too. For example if you put <Name> it would * be replaced with Rojoss and if you put <NAME> it would be ROJOSS. Lowercase parameter * names will use the value provided in the parameter. The parameter can be prefixed with a * underscore to force the value lowercase like <_name> * * @param params The list of parameters to replace. The <p> parameter is reserved and this * gets replaced with global prefix. * @return This msg instance. * @see Param */ public Msg params(Param... params) { if (!message.contains(Character.toString(PARAM_OPEN)) || !message.contains(Character.toString(PARAM_CLOSE))) { return this; } if (message == null) { message = original; } for (Param param : params) { message = message.replace( PARAM_OPEN + param.getParam().toLowerCase() + PARAM_CLOSE, param.toString()); message = message.replace( PARAM_OPEN + "_" + param.getParam().toLowerCase() + PARAM_CLOSE, param.toString().toLowerCase()); message = message.replace( PARAM_OPEN + param.getParam().toUpperCase() + PARAM_CLOSE, param.toString().toUpperCase()); message = message.replace( PARAM_OPEN + Str.capitalize(param.getParam().toLowerCase()) + PARAM_CLOSE, Str.capitalize(param.toString())); } message = message.replace("<p>", Msg.getRaw("prefix").message); return this; }
/** * Capitalize the first letter of the message. * * <p>Uses {@link Str#capitalize(String)} * * @return This msg instance. */ public Msg capitalize() { message = Str.capitalize(message); return this; }