Skip to main content

FlixelStringUtil

View source

class

org.flixelgdx.util.FlixelStringUtil

public final class FlixelStringUtil

Handy utility class for manipulating strings more efficiently.

Methods

contentEquals(CharSequence, CharSequence)

public static boolean contentEquals(CharSequence a, CharSequence b)

Compares the content of two CharSequences for equality. This works for Strings, StringBuilders, and any CharSequences.

Parameters:

NameDescription
aThe first CharSequence to compare.
bThe second CharSequence to compare.

Returns: true if the content of the two CharSequences is equal, false otherwise.


appendFloatRounded(CharArray, float, int)

public static void appendFloatRounded(CharArray out, float value, int decimals)

Appends value rounded to decimals decimal places using only CharArray primitive appenders, avoiding Float.toString(...) and other helpers that allocate String objects.

Non-finite values fall back to CharArray.append(...).

When decimals is zero or negative, the value is rounded to the nearest integer and no decimal point is written.

Fractional digits are zero-padded on the left so the output always has exactly decimals digits after the decimal point (for example, 3.05f with decimals = 2 produces "3.05", not "3.5").

Because this method uses long arithmetic internally, meaningful precision is still limited to roughly seven significant digits (the range of a float).

Parameters:

NameDescription
outDestination buffer. For FlixelString callers, prefer FlixelString.concatFloatRounded(float, int) or FlixelString.setFloatRounded(float, int) instead of reaching for a raw CharArray.
valueValue to format.
decimalsNumber of digits after the decimal point; values of zero or less produce an integer with no decimal point.

appendFloatRoundedOneDecimal(CharArray, float)

public static void appendFloatRoundedOneDecimal(CharArray out, float value)

Appends value rounded to one decimal place (nearest tenth). Convenience wrapper for FlixelStringUtil.appendFloatRounded(...) with decimals = 1.

Non-finite values fall back to CharArray.append(...).

Parameters:

NameDescription
outDestination buffer. For FlixelString, callers prefer FlixelString.concatFloatRoundedOneDecimal(float) or FlixelString.setFloatRoundedOneDecimal(float) instead of reaching for a raw CharArray.
valueValue to format.