Class NameUtils

java.lang.Object
net.mtrop.doom.util.NameUtils

public final class NameUtils extends Object
Name utility methods.
Author:
Matthew Tropiano
  • Field Details

    • ENTRY_NAME

      public static final Pattern ENTRY_NAME
      A regex pattern that matches valid entry names.
    • TEXTURE_NAME

      public static final Pattern TEXTURE_NAME
      A regex pattern that matches valid texture names.
    • EMPTY_TEXTURE_NAME

      public static final String EMPTY_TEXTURE_NAME
      The name of the "blank" texture.
      See Also:
  • Method Details

    • nullTrim

      public static String nullTrim(String s)
      Cuts a string at the first null character.
      Parameters:
      s - the input string.
      Returns:
      the resultant string, after the trim.
    • toASCIIBytes

      public static byte[] toASCIIBytes(String s, int bytelen)
      Converts a String to an ASCII-encoded, byte-length-aligned vector. If the string length is less than bytelen it is null-byte padded to the length.
      Parameters:
      s - the input string.
      bytelen - the output byte array length.
      Returns:
      the resultant byte array.
    • isValidEntryName

      public static boolean isValidEntryName(String name)
      Tests if an input string is a valid entry name.

      A WadEntry must have a name that is up to 8 characters long, and can only contain A-Z (uppercase only), 0-9, and most symbols plus the backslash ("\").

      Parameters:
      name - the input name to test.
      Returns:
      true if so, false if not.
    • toValidEntryName

      public static String toValidEntryName(String name)
      Tests if an input string is a valid entry name, and if not, converts it into a valid one.

      In a valid entry, all characters must be A-Z (uppercase only), 0-9, and most symbols plus the backslash ("\").

      Lowercase letters are made uppercase and unknown characters are converted to dashes. Latin characters with diacritical marks are converted to their normalized forms. Names are truncated to 8 characters. The entry will also be cut at the first null character, if any.

      An empty string (see isStringEmpty(Object) is converted to "-".

      Parameters:
      name - the input name to test.
      Returns:
      true if so, false if not.
    • checkValidEntryName

      public static void checkValidEntryName(String name)
      Tests if an input string is a valid entry name, and if not, throws an exception.
      Parameters:
      name - the input name to test.
      Throws:
      IllegalArgumentException - if the entry name is invalid.
      See Also:
    • isValidTextureName

      public static boolean isValidTextureName(String name)
      Tests if an input string is a valid texture name.

      A Texture must have an alphanumeric name that is up to 8 characters long, and can only contain A-Z (uppercase only), 0-9, and most symbols plus the backslash ("\") or just "-".

      Parameters:
      name - the input name to test.
      Returns:
      true if so, false if not.
    • toValidTextureName

      public static String toValidTextureName(String name)
      Tests if an input string is a valid entry name, and if not, converts it into a valid one.

      In a valid texture, all characters must be A-Z (uppercase only), 0-9, and most symbols plus the backslash ("\").

      Blank/null names are changed to "-".

      Lowercase letters are made uppercase and unknown characters are converted to dashes. Latin characters with diacritical marks are converted to their normalized forms. Names are truncated to 8 characters. The entry will also be cut at the first null character, if any.

      Parameters:
      name - the input name to test.
      Returns:
      true if so, false if not.
    • checkValidTextureName

      public static void checkValidTextureName(String name)
      Tests if an input string is a valid entry name, and if not, throws an exception.
      Parameters:
      name - the input name to test.
      Throws:
      IllegalArgumentException - if the entry name is invalid.
      See Also:
    • isStringEmpty

      public static boolean isStringEmpty(Object obj)
      Checks if a string is "empty." A string is considered "empty" if the string the empty string, or are String.trim()'ed down to the empty string.
      Parameters:
      obj - the object to check.
      Returns:
      true if the provided object is considered "empty", false otherwise.