Package org.jf.util

Class StringWrapper

java.lang.Object
org.jf.util.StringWrapper

public class StringWrapper extends Object
  • Constructor Details

    • StringWrapper

      public StringWrapper()
  • Method Details

    • wrapStringOnBreaks

      public static Iterable<String> wrapStringOnBreaks(@Nonnull String string, int maxWidth)
      Splits the given string into lines of maximum width maxWidth. The splitting is done using the current locale's rules for splitting lines.
      Parameters:
      string - The string to split
      maxWidth - The maximum length of any line
      Returns:
      An iterable of Strings containing the wrapped lines
    • wrapString

      public static String[] wrapString(@Nonnull String str, int maxWidth, @Nullable String[] output)
      Splits the given string into lines using on any embedded newlines, and wrapping the text as needed to conform to the given maximum line width. This uses and assumes unix-style newlines
      Parameters:
      str - The string to split
      maxWidth - The maximum length of any line
      output - If given, try to use this array as the return value. If there are more values than will fit into the array, a new array will be allocated and returned, while the given array will be filled with as many lines as would fit.
      Returns:
      The split lines from the original, as an array of Strings. The returned array may be larger than the number of lines. If this is the case, the end of the split lines will be denoted by a null entry in the array. If there is no null entry, then the size of the array exactly matches the number of lines. The returned lines will not contain an ending newline
    • addString

      private static String[] addString(@Nonnull String[] arr, String str, int index)
    • addString

      private static String[] addString(@Nonnull String[] arr, String str, int index, int newLength)
    • enlargeArray

      private static String[] enlargeArray(String[] arr, int newLength)
    • printWrappedString

      public static void printWrappedString(@Nonnull PrintStream stream, @Nonnull String string, int maxWidth)