Module watamebot

Class StringUtils

java.lang.Object
net.foxgenesis.util.StringUtils

public final class StringUtils extends Object
Utility class for Strings
Author:
Ashley
  • Field Details

    • PATTERN_URL

      public static final Pattern PATTERN_URL
      Compiled regex checking for URL character sequences. This pattern is case insensitive.
      \b((http|https|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|])
    • PATTERN_URL_WITH_GROUPING

      public static final Pattern PATTERN_URL_WITH_GROUPING
      Compiled regex checking for URL character sequences. This pattern is case insensitive and contains named groups for protocol, domain and path.
      \b(?<protocol>http|https|ftp|file)://(?<domain>[-a-zA-Z0-9+&@#%?=~_|!:,.;]*[-a-zA-Z0-9+&@#%=~_|])(?<path>\S*)
    • CONTAINS_URL

      public static final Predicate<String> CONTAINS_URL
      Predicate that tests if a URL is found in a given input string.
    • IS_URL

      public static final Predicate<String> IS_URL
      Predicate that tests if the given input string is a URL.
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • findURLWithGroups

      @NotNull public static @NotNull Stream<MatchResult> findURLWithGroups(@NotNull @NotNull String str)
      Find all URLs within a String and split its components into groups.
      Parameters:
      str - - String to check
      Returns:
      A Stream of MatchResults containing URL groups: protocol(1), domain(2) and path(3)
    • findURLs

      @NotNull public static @NotNull Stream<URL> findURLs(@NotNull @NotNull String str)
      Find all occurrences of a URL in the given string.
      Parameters:
      str - - string to check
      Returns:
      Returns a Stream of URLs
    • findURLs

      @NotNull public static @NotNull Stream<URL> findURLs(@NotNull @NotNull String str, @Nullable @Nullable Consumer<Exception> errorHandler)
      Find all occurrences of a URL in the given string. All MalformedURLExceptions will be consumed by the errorHandler while parsing.
      Parameters:
      str - - string to check
      errorHandler - - possibly null error handler
      Returns:
      Returns a Stream of URLs
    • limit

      public static String limit(String str, int length)
      Limit the length of a string if it exceeds the provided length.
      Parameters:
      str - - string to limit
      length - - length limit
      Returns:
      Returns a String that does not exceed the given length