Skip to content

StringUtils

Fulminazzo edited this page Oct 2, 2023 · 1 revision

StringUtils are a series of general functions thought to be used to manipulate strings. While some use HexUtils, the majority of these methods are not correlated to anything in particular.

public class StringUtils {

    /**
     * Uses HexUtils.parseString() and ChatColor.translateAlternateColorCodes() to color a message.
     * @param message: the message.
     * @return the colored message.
     */
    public static String parseMessage(String message);

    /**
     * Replaces the content of string from one string into another, while keeping
     * in count the previous color. This way, the replacement will not alter
     * the coloring of the string. For example:
     * replaceChatColors("&dHello %replace-this%, how are you?", 
     *                          "%replace-this%", "&aWorld");
     * will return:
     * "&dHello &aWorld&d, how are you?"
     * @param string: the string to replace the content from;
     * @param from: the content to be replaced;
     * @param to: the replacement;
     * @return the replacement string.
     */
    public static String replaceChatColors(String string, String from, String to);

    /**
     * Replaces the content of string from one string into another, while keeping
     * in count the previous color. This way, the replacement will not alter
     * the coloring of the string. For example:
     * replaceChatColors("&dHello %replace-this%, how are you?", 
     *                          "%replace-this%", "&aWorld", true);
     * will return:
     * "&dHello &aWorld&d, how are you?"
     * @param string: the string to replace the content from;
     * @param from: the content to be replaced;
     * @param to: the replacement;
     * @param checkHex: if false, ignores HEX codes.
     * @return the replacement string.
     */
    public static String replaceChatColors(String string, String from, String to, boolean checkHex);

    /**
     * @return the current Character used as color identifier.
     */
    public static String getColorCode();

    /**
     * Converts the name into its corresponding char color code.
     * @param name: the name to be converted.
     * @return a ReflObject containing the corresponding color code.
     */
    public static String getCharCode(String name);

    /**
     * Converts a string into a "YAML" format.
     * For example, if the string is "CamelCase", it will be
     * converted into "camel-case".
     * @param string: the string to convert.
     * @return the converted string.
     */
    public static String formatStringToYaml(String string);

    /**
     * Repeats a string for a specified number of times.
     * @param c: the string to repeat;
     * @param times: the number of times.
     * @return the resulting string.
     */
    public static String repeatChar(String c, int times);

    /**
     * Prints the object class and fields in a nice format.
     * @param object: the object.
     * @return the string containing the information.
     */
    public static String printObject(Object object);

    /**
     * Replacement for WordUtils.capitalizeFully(string.replace("_", " ")):
     * converts a string by replacing its "_" characters with spaces and capitalizing
     * every first char of any word. For example: "this_string" will be formatted
     * as "This String".
     * @param string: the string to convert.
     * @return the converted string.
     */
    public static String capitalize(String string);
}

Clone this wiki locally