Class DefaultSlugGenerator

  • All Implemented Interfaces:
    com.mewebstudio.springboot.jpa.slug.kotlin.ISlugGenerator

    
    public final class DefaultSlugGenerator
     implements ISlugGenerator
                        

    Default implementation of the ISlugGenerator interface that generates slugs by transforming the input string to a standardized format.

    This implementation converts the input string to lowercase, removes any non-alphanumeric characters (except for spaces and hyphens), replaces consecutive spaces or hyphens with a single hyphen, and ensures the final slug has no extra hyphens.

    Example:

    val generator = DefaultSlugGenerator()
    val slug = generator.generate("Hello World! This is a test.")
    println(slug) // Output: "hello-world-this-is-a-test"
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      String generate(String input) Generates a slug from the given input string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultSlugGenerator

        DefaultSlugGenerator()
    • Method Detail

      • generate

         String generate(String input)

        Generates a slug from the given input string.

        This method processes the input string by:

        • Converting the string to lowercase

        • Removing any characters that are not alphanumeric, spaces, or hyphens

        • Replacing one or more spaces with a single hyphen

        • Ensuring that multiple hyphens are replaced by a single hyphen

        Parameters:
        input - the input string to generate a slug from.
        Returns:

        the generated slug, or null if the input is null.