Package squidpony

Class StringKit

java.lang.Object
squidpony.StringKit

public class StringKit
extends Object
Various utility functions for dealing with Strings, CharSequences, and char[]s; this has lots of methods to convert to and from Strings and numbers, but also has tools to wrap long CharSequences to fit in a maximum width, join arrays of various items into long Strings, split/search/count occurrences of literal char arrays or CharSequences without using any regex, and generally tidy up generated text. This last step includes padding left and right (including a "strict" option that truncates Strings that are longer than the padded size), Capitalizing Each Word, Capitalizing the first word in a sentence, replacing "a improper usage of a" with "an improved replacement using an," etc. This also has a lot of predefined categories of chars that are considered widely enough supported in fonts, like COMMON_PUNCTUATION and LATIN_LETTERS_UPPER.
Created by Tommy Ettinger on 3/21/2016.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static String BOX_DRAWING  
    static String BOX_DRAWING_DOUBLE  
    static String BOX_DRAWING_SINGLE  
    static String COMMON_PUNCTUATION  
    static String CURRENCY  
    static String CYRILLIC_LETTERS  
    static String CYRILLIC_LETTERS_LOWER  
    static String CYRILLIC_LETTERS_UPPER  
    static String DIGITS  
    static String ENGLISH_LETTERS  
    static String ENGLISH_LETTERS_LOWER  
    static String ENGLISH_LETTERS_UPPER  
    static String GREEK_LETTERS  
    static String GREEK_LETTERS_LOWER
    Includes both lower-case forms for Sigma, 'ς' and 'σ', but this matches the two upper-case Sigma in GREEK_LETTERS_UPPER.
    static String GREEK_LETTERS_UPPER
    Includes the letter Sigma, 'Σ', twice because it has two lower-case forms in GREEK_LETTERS_LOWER.
    static String GROUPING_SIGNS_CLOSE
    An index in GROUPING_SIGNS_OPEN can be used here to find the closing char for that opening one.
    static String GROUPING_SIGNS_OPEN
    Can be used to match an index with one in GROUPING_SIGNS_CLOSE to find the closing char (this way only).
    static char[] hexDigits
    Constant storing the 16 hexadecimal digits, as char values, in order.
    static String LATIN_EXTENDED_LETTERS  
    static String LATIN_EXTENDED_LETTERS_LOWER  
    static String LATIN_EXTENDED_LETTERS_UPPER  
    static String LATIN_LETTERS  
    static String LATIN_LETTERS_LOWER  
    static String LATIN_LETTERS_UPPER  
    static String LETTERS  
    static String LETTERS_AND_NUMBERS  
    static String LETTERS_LOWER  
    static String LETTERS_UPPER  
    static String MARKS  
    static String mask16  
    static String mask32  
    static String mask64  
    static String mask8  
    static String MODERN_PUNCTUATION  
    static regexodus.Pattern nonSpacePattern  
    static String PERMISSIBLE_CHARS
    A constant containing only chars that are reasonably likely to be supported by broad fonts and thus display-able.
    static String PUNCTUATION  
    static String SPACING  
    static String TECHNICAL_PUNCTUATION  
    static String UNCOMMON_PUNCTUATION  
    static String VISUAL_SYMBOLS  
    static regexodus.Pattern whitespacePattern  
  • Constructor Summary

    Constructors 
    Constructor Description
    StringKit()  
  • Method Summary

    Modifier and Type Method Description
    static StringBuilder appendHex​(StringBuilder builder, byte number)  
    static StringBuilder appendHex​(StringBuilder builder, char number)  
    static StringBuilder appendHex​(StringBuilder builder, double number)  
    static StringBuilder appendHex​(StringBuilder builder, float number)  
    static StringBuilder appendHex​(StringBuilder builder, int number)  
    static StringBuilder appendHex​(StringBuilder builder, long number)  
    static StringBuilder appendHex​(StringBuilder builder, short number)  
    static byte b64DecodeByte​(char[] data, int offset)
    Decodes 2 characters from data starting from offset to get a byte encoded as base-64.
    static char b64DecodeChar​(char[] data, int offset)
    Decodes 3 characters from data starting from offset to get a char encoded as base-64.
    static double b64DecodeDouble​(char[] data, int offset)
    Decodes 11 characters from data starting from offset to get a double encoded as base-64.
    static float b64DecodeFloat​(char[] data, int offset)
    Decodes 6 characters from data starting from offset to get a float encoded as base-64.
    static int b64DecodeInt​(char[] data, int offset)
    Decodes 6 characters from data starting from offset to get an int encoded as base-64.
    static long b64DecodeLong​(char[] data, int offset)
    Decodes 11 characters from data starting from offset to get a long encoded as base-64.
    static short b64DecodeShort​(char[] data, int offset)
    Decodes 3 characters from data starting from offset to get a short encoded as base-64.
    static char[] b64Encode​(byte number, int offset, char[] buf)
    Base-64 encodes number and stores that string representation in buf starting at offset; uses 2 chars.
    static char[] b64Encode​(char glyph, int offset, char[] buf)
    Base-64 encodes glyph and stores that string representation in buf starting at offset; uses 3 chars.
    static char[] b64Encode​(double number, int offset, char[] buf)
    Base-64 encodes number and stores that string representation in buf starting at offset; uses 11 chars.
    static char[] b64Encode​(float number, int offset, char[] buf)
    Base-64 encodes number and stores that string representation in buf starting at offset; uses 6 chars.
    static char[] b64Encode​(int number, int offset, char[] buf)
    Base-64 encodes number and stores that string representation in buf starting at offset; uses 6 chars.
    static char[] b64Encode​(long number, int offset, char[] buf)
    Base-64 encodes number and stores that string representation in buf starting at offset; uses 11 chars.
    static char[] b64Encode​(short number, int offset, char[] buf)
    Base-64 encodes number and stores that string representation in buf starting at offset; uses 3 chars.
    static String bin​(byte number)  
    static String bin​(char number)  
    static String bin​(int number)  
    static String bin​(long number)  
    static String bin​(short number)  
    static String capitalize​(CharSequence original)
    Capitalizes Each Word In The Parameter original, Returning A New String.
    static boolean contains​(CharSequence text, char[] search)
    Searches text for the exact contents of the char array search; returns true if text contains search.
    static int containsPart​(CharSequence text, char[] search)
    Tries to find as much of the char array search in the CharSequence text, always starting from the beginning of search (if the beginning isn't found, then it finds nothing), and returns the length of the found part of search (0 if not found).
    static int containsPart​(CharSequence text, char[] search, CharSequence prefix, CharSequence suffix)
    Tries to find as much of the sequence prefix search suffix as it can in text, where prefix and suffix are CharSequences for some reason and search is a char array.
    static String correctABeforeVowel​(CharSequence text)
    A simple method that looks for any occurrences of the word 'a' followed by some non-zero amount of whitespace and then any vowel starting the following word (such as 'a item'), then replaces each such improper 'a' with 'an' (such as 'an item').
    static int count​(String source, int search)
    Scans repeatedly in source for the codepoint search (which is usually a char literal), not scanning the same section twice, and returns the number of instances of search that were found, or 0 if source is null.
    static int count​(String source, int search, int startIndex, int endIndex)
    Scans repeatedly in source (only using the area from startIndex, inclusive, to endIndex, exclusive) for the codepoint search (which is usually a char literal), not scanning the same section twice, and returns the number of instances of search that were found, or 0 if source is null or if the searched area is empty.
    static int count​(String source, String search)
    Scans repeatedly in source for the String search, not scanning the same char twice except as part of a larger String, and returns the number of instances of search that were found, or 0 if source is null or if search is null or empty.
    static int count​(String source, String search, int startIndex, int endIndex)
    Scans repeatedly in source (only using the area from startIndex, inclusive, to endIndex, exclusive) for the String search, not scanning the same char twice except as part of a larger String, and returns the number of instances of search that were found, or 0 if source or search is null or if the searched area is empty.
    static String hex​(byte number)  
    static String hex​(byte[] numbers)  
    static String hex​(char number)  
    static String hex​(char[] numbers)  
    static String hex​(double number)  
    static String hex​(double[] numbers)  
    static String hex​(float number)  
    static String hex​(float[] numbers)  
    static String hex​(int number)  
    static String hex​(int[] numbers)  
    static String hex​(long number)  
    static String hex​(long[] numbers)  
    static String hex​(short number)  
    static String hex​(short[] numbers)  
    static String hexHash​(boolean... array)  
    static String hexHash​(byte... array)  
    static String hexHash​(char... array)  
    static String hexHash​(int... array)  
    static String hexHash​(long... array)  
    static String hexHash​(short... array)  
    static int indexOf​(CharSequence text, String regex)  
    static int indexOf​(CharSequence text, String regex, int beginIndex)  
    static int indexOf​(CharSequence text, regexodus.Pattern regex)  
    static int indexOf​(CharSequence text, regexodus.Pattern regex, int beginIndex)  
    static int intFromBin​(CharSequence cs)
    Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise.
    static int intFromBin​(CharSequence cs, int start, int end)
    Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise.
    static int intFromDec​(CharSequence cs)
    Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static int intFromDec​(CharSequence cs, int start, int end)
    Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static int intFromHex​(char[] cs, int start, int end)
    Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static int intFromHex​(CharSequence cs)
    Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static int intFromHex​(CharSequence cs, int start, int end)
    Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static String join​(CharSequence delimiter, boolean... elements)  
    static String join​(CharSequence delimiter, byte... elements)  
    static String join​(CharSequence delimiter, char... elements)  
    static String join​(CharSequence delimiter, double... elements)  
    static String join​(CharSequence delimiter, float... elements)  
    static String join​(CharSequence delimiter, int... elements)  
    static String join​(CharSequence delimiter, long... elements)  
    static String join​(CharSequence delimiter, short... elements)  
    static String join​(CharSequence delimiter, CharSequence... elements)  
    static String join​(CharSequence delimiter, Iterable<?> elements)
    Joins the items in elements by calling their toString method on them (or just using the String "null" for null items), and separating each item with delimiter.
    static String join​(CharSequence delimiter, Object[] elements)
    Joins the items in elements by calling their toString method on them (or just using the String "null" for null items), and separating each item with delimiter.
    static String join​(CharSequence delimiter, Collection<? extends CharSequence> elements)  
    static String joinAlt​(boolean... elements)
    Joins the boolean array elements without delimiters into a String, using "1" for true and "0" for false.
    static String joinAlt​(CharSequence delimiter, long... elements)
    Like join(CharSequence, long...), but this appends an 'L' to each number so they can be read in by Java.
    static String joinArrays​(CharSequence delimiter, char[]... elements)  
    static long longFromBin​(CharSequence cs)
    Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise.
    static long longFromBin​(CharSequence cs, int start, int end)
    Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise.
    static long longFromDec​(CharSequence cs)
    Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent, reading at most 19 characters (20 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static long longFromDec​(CharSequence cs, int start, int end)
    Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent between the given positions start and end, reading at most 19 characters (20 if there is a sign) or until end is reached and returning the result if valid, or 0 if nothing could be read.
    static long longFromHex​(char[] cs, int start, int end)
    Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static long longFromHex​(CharSequence cs)
    Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static long longFromHex​(CharSequence cs, int start, int end)
    Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static String padLeft​(String text, char padChar, int minimumLength)
    If text is shorter than the given minimumLength, returns a String with text padded on the left with padChar until it reaches that length; otherwise it simply returns text.
    static String padLeft​(String text, int minimumLength)
    If text is shorter than the given minimumLength, returns a String with text padded on the left with spaces until it reaches that length; otherwise it simply returns text.
    static String padLeftStrict​(String text, char padChar, int totalLength)
    Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its left side with padChar until totalLength is reached.
    static String padLeftStrict​(String text, int totalLength)
    Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its left side with spaces until totalLength is reached.
    static String padRight​(String text, char padChar, int minimumLength)
    If text is shorter than the given minimumLength, returns a String with text padded on the right with padChar until it reaches that length; otherwise it simply returns text.
    static String padRight​(String text, int minimumLength)
    If text is shorter than the given minimumLength, returns a String with text padded on the right with spaces until it reaches that length; otherwise it simply returns text.
    static String padRightStrict​(String text, char padChar, int totalLength)
    Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its right side with padChar until totalLength is reached.
    static String padRightStrict​(String text, int totalLength)
    Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its right side with spaces until totalLength is reached.
    static String replace​(CharSequence text, String before, String after)  
    static String safeSubstring​(String source, int beginIndex, int endIndex)
    Like String.substring(int, int) but returns "" instead of throwing any sort of Exception.
    static String sentenceCase​(CharSequence original)
    Attempts to scan for sentences in original, capitalizes the first letter of each sentence, and otherwise leaves the CharSequence untouched as it returns it as a String.
    static String[] split​(String source, String delimiter)
    Like String.split(String) but doesn't use any regex for splitting (delimiter is a literal String).
    static List<String> wrap​(CharSequence longText, int width)
    Word-wraps the given String (or other CharSequence, such as a StringBuilder) so it is split into zero or more Strings as lines of text, with the given width as the maximum width for a line.
    static List<String> wrap​(List<String> receiving, CharSequence longText, int width)
    Word-wraps the given String (or other CharSequence, such as a StringBuilder) so it is split into zero or more Strings as lines of text, with the given width as the maximum width for a line; appends the word-wrapped lines to the given List of Strings and does not create a new List.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • contains

      public static boolean contains​(CharSequence text, char[] search)
      Searches text for the exact contents of the char array search; returns true if text contains search.
      Parameters:
      text - a CharSequence, such as a String or StringBuilder, that might contain search
      search - a char array to try to find in text
      Returns:
      true if search was found
    • containsPart

      public static int containsPart​(CharSequence text, char[] search)
      Tries to find as much of the char array search in the CharSequence text, always starting from the beginning of search (if the beginning isn't found, then it finds nothing), and returns the length of the found part of search (0 if not found).
      Parameters:
      text - a CharSequence to search in
      search - a char array to look for
      Returns:
      the length of the searched-for char array that was found
    • containsPart

      public static int containsPart​(CharSequence text, char[] search, CharSequence prefix, CharSequence suffix)
      Tries to find as much of the sequence prefix search suffix as it can in text, where prefix and suffix are CharSequences for some reason and search is a char array. Returns the length of the sequence it was able to match, up to prefix.length() + search.length + suffix.length(), or 0 if no part of the looked-for sequence could be found.
      This is almost certainly too specific to be useful outside of a handful of cases.
      Parameters:
      text - a CharSequence to search in
      search - a char array to look for, surrounded by prefix and suffix
      prefix - a mandatory prefix before search, separated for some weird optimization reason
      suffix - a mandatory suffix after search, separated for some weird optimization reason
      Returns:
      the length of the searched-for prefix+search+suffix that was found
    • join

      public static String join​(CharSequence delimiter, CharSequence... elements)
    • join

      public static String join​(CharSequence delimiter, Collection<? extends CharSequence> elements)
    • joinArrays

      public static String joinArrays​(CharSequence delimiter, char[]... elements)
    • join

      public static String join​(CharSequence delimiter, long... elements)
    • join

      public static String join​(CharSequence delimiter, double... elements)
    • join

      public static String join​(CharSequence delimiter, int... elements)
    • join

      public static String join​(CharSequence delimiter, float... elements)
    • join

      public static String join​(CharSequence delimiter, short... elements)
    • join

      public static String join​(CharSequence delimiter, char... elements)
    • join

      public static String join​(CharSequence delimiter, byte... elements)
    • join

      public static String join​(CharSequence delimiter, boolean... elements)
    • join

      public static String join​(CharSequence delimiter, Object[] elements)
      Joins the items in elements by calling their toString method on them (or just using the String "null" for null items), and separating each item with delimiter. Unlike other join methods in this class, this does not take a vararg of Object items, since that would cause confusion with the overloads that take one object, such as join(CharSequence, Iterable); it takes a non-vararg Object array instead.
      Parameters:
      delimiter - the String or other CharSequence to separate items in elements with
      elements - the Object items to stringify and join into one String; if the array is null or empty, this returns an empty String, and if items are null, they are shown as "null"
      Returns:
      the String representations of the items in elements, separated by delimiter and put in one String
    • join

      public static String join​(CharSequence delimiter, Iterable<?> elements)
      Joins the items in elements by calling their toString method on them (or just using the String "null" for null items), and separating each item with delimiter. This can take any Iterable of any type for its elements parameter.
      Parameters:
      delimiter - the String or other CharSequence to separate items in elements with
      elements - the Object items to stringify and join into one String; if Iterable is null or empty, this returns an empty String, and if items are null, they are shown as "null"
      Returns:
      the String representations of the items in elements, separated by delimiter and put in one String
    • joinAlt

      public static String joinAlt​(boolean... elements)
      Joins the boolean array elements without delimiters into a String, using "1" for true and "0" for false.
      Parameters:
      elements - an array or vararg of booleans
      Returns:
      a String using 1 for true elements and 0 for false, or "N" if elements is null
    • joinAlt

      public static String joinAlt​(CharSequence delimiter, long... elements)
      Like join(CharSequence, long...), but this appends an 'L' to each number so they can be read in by Java.
      Parameters:
      delimiter -
      elements -
      Returns:
    • count

      public static int count​(String source, String search)
      Scans repeatedly in source for the String search, not scanning the same char twice except as part of a larger String, and returns the number of instances of search that were found, or 0 if source is null or if search is null or empty.
      Parameters:
      source - a String to look through
      search - a String to look for
      Returns:
      the number of times search was found in source
    • count

      public static int count​(String source, int search)
      Scans repeatedly in source for the codepoint search (which is usually a char literal), not scanning the same section twice, and returns the number of instances of search that were found, or 0 if source is null.
      Parameters:
      source - a String to look through
      search - a codepoint or char to look for
      Returns:
      the number of times search was found in source
    • count

      public static int count​(String source, String search, int startIndex, int endIndex)
      Scans repeatedly in source (only using the area from startIndex, inclusive, to endIndex, exclusive) for the String search, not scanning the same char twice except as part of a larger String, and returns the number of instances of search that were found, or 0 if source or search is null or if the searched area is empty. If endIndex is negative, this will search from startIndex until the end of the source.
      Parameters:
      source - a String to look through
      search - a String to look for
      startIndex - the first index to search through, inclusive
      endIndex - the last index to search through, exclusive; if negative this will search the rest of source
      Returns:
      the number of times search was found in source
    • count

      public static int count​(String source, int search, int startIndex, int endIndex)
      Scans repeatedly in source (only using the area from startIndex, inclusive, to endIndex, exclusive) for the codepoint search (which is usually a char literal), not scanning the same section twice, and returns the number of instances of search that were found, or 0 if source is null or if the searched area is empty. If endIndex is negative, this will search from startIndex until the end of the source.
      Parameters:
      source - a String to look through
      search - a codepoint or char to look for
      startIndex - the first index to search through, inclusive
      endIndex - the last index to search through, exclusive; if negative this will search the rest of source
      Returns:
      the number of times search was found in source
    • safeSubstring

      public static String safeSubstring​(String source, int beginIndex, int endIndex)
      Like String.substring(int, int) but returns "" instead of throwing any sort of Exception.
      Parameters:
      source - the String to get a substring from
      beginIndex - the first index, inclusive; will be treated as 0 if negative
      endIndex - the index after the last character (exclusive); if negative this will be source.length()
      Returns:
      the substring of source between beginIndex and endIndex, or "" if any parameters are null/invalid
    • split

      public static String[] split​(String source, String delimiter)
      Like String.split(String) but doesn't use any regex for splitting (delimiter is a literal String).
      Parameters:
      source - the String to get split-up substrings from
      delimiter - the literal String to split on (not a regex); will not be included in the returned String array
      Returns:
      a String array consisting of at least one String (all of Source if nothing was split)
    • hex

      public static String hex​(long number)
    • hex

      public static String hex​(double number)
    • hex

      public static String hex​(int number)
    • hex

      public static String hex​(float number)
    • hex

      public static String hex​(short number)
    • hex

      public static String hex​(char number)
    • hex

      public static String hex​(byte number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, long number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, double number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, int number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, float number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, short number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, char number)
    • appendHex

      public static StringBuilder appendHex​(StringBuilder builder, byte number)
    • hex

      public static String hex​(long[] numbers)
    • hex

      public static String hex​(double[] numbers)
    • hex

      public static String hex​(int[] numbers)
    • hex

      public static String hex​(float[] numbers)
    • hex

      public static String hex​(short[] numbers)
    • hex

      public static String hex​(char[] numbers)
    • hex

      public static String hex​(byte[] numbers)
    • bin

      public static String bin​(long number)
    • bin

      public static String bin​(int number)
    • bin

      public static String bin​(short number)
    • bin

      public static String bin​(char number)
    • bin

      public static String bin​(byte number)
    • longFromHex

      public static long longFromHex​(CharSequence cs)
      Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class' hex(long) method; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ".
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)
      Returns:
      the long that cs represents
    • longFromHex

      public static long longFromHex​(CharSequence cs, int start, int end)
      Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class' hex(long) method; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)
      Returns:
      the long that cs represents
    • longFromHex

      public static long longFromHex​(char[] cs, int start, int end)
      Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class' hex(long) method; that is, if the first digit of a 16-char (or longer) char[] is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1L when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a char array containing only hex digits with an optional sign (no 0x at the start)
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)
      Returns:
      the long that cs represents
    • intFromHex

      public static int intFromHex​(CharSequence cs)
      Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class' hex(int) method; that is, if the first digit of an 8-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)
      Returns:
      the int that cs represents
    • intFromHex

      public static int intFromHex​(CharSequence cs, int start, int end)
      Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class' hex(int) method; that is, if the first digit of an 8-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)
      Returns:
      the int that cs represents
    • intFromHex

      public static int intFromHex​(char[] cs, int start, int end)
      Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class' hex(int) method; that is, if the first digit of an 8-char (or longer) char[] is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a char array containing only hex digits with an optional sign (no 0x at the start)
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)
      Returns:
      the int that cs represents
    • longFromDec

      public static long longFromDec​(CharSequence cs)
      Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent, reading at most 19 characters (20 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. Unlike intFromDec(CharSequence), this can't effectively be used to read unsigned longs as decimal literals, since anything larger than the highest signed long would be larger than the normal limit for longs as text (it would be 20 characters without a sign, where we limit it to 19 without a sign to match normal behavior).
      Should be fairly close to the JDK's Long.parseLong method, but this also supports CharSequence data instead of just String data, and ignores chars after the number. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only digits 0-9 with an optional sign
      Returns:
      the long that cs represents
    • longFromDec

      public static long longFromDec​(CharSequence cs, int start, int end)
      Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent between the given positions start and end, reading at most 19 characters (20 if there is a sign) or until end is reached and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. Unlike intFromDec(CharSequence, int, int), this can't effectively be used to read unsigned longs as decimal literals, since anything larger than the highest signed long would be larger than the normal limit for longs as text (it would be 20 characters without a sign, where we limit it to 19 without a sign to match normal behavior).
      Should be fairly close to the JDK's Long.parseLong method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only digits 0-9 with an optional sign
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 19 or 20 characters if end is too large, depending on sign)
      Returns:
      the long that cs represents
    • intFromDec

      public static int intFromDec​(CharSequence cs)
      Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can technically be used to handle unsigned integers in decimal format, but it isn't the intended purpose. If you do use it for handling unsigned ints, 2147483647 is normally the highest positive int and -2147483648 the lowest negative one, but if you give this a number between 2147483647 and 2147483647 + 2147483648, it will interpret it as a negative number that fits in bounds using the normal rules for converting between signed and unsigned numbers.
      Should be fairly close to the JDK's Integer.parseInt method, but this also supports CharSequence data instead of just String data, and ignores chars after the number. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only digits 0-9 with an optional sign
      Returns:
      the int that cs represents
    • intFromDec

      public static int intFromDec​(CharSequence cs, int start, int end)
      Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can technically be used to handle unsigned integers in decimal format, but it isn't the intended purpose. If you do use it for handling unsigned ints, 2147483647 is normally the highest positive int and -2147483648 the lowest negative one, but if you give this a number between 2147483647 and 2147483647 + 2147483648, it will interpret it as a negative number that fits in bounds using the normal rules for converting between signed and unsigned numbers.
      Should be fairly close to the JDK's Integer.parseInt method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only digits 0-9 with an optional sign
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 10 or 11 characters if end is too large, depending on sign)
      Returns:
      the int that cs represents
    • longFromBin

      public static long longFromBin​(CharSequence cs)
      Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 64 chars long.
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.
      Parameters:
      cs - a CharSequence, such as a String, containing only binary digits (nothing at the start)
      Returns:
      the long that cs represents
    • longFromBin

      public static long longFromBin​(CharSequence cs, int start, int end)
      Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 64 chars long.
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.
      Parameters:
      cs - a CharSequence, such as a String, containing only binary digits (nothing at the start)
      start - the first character position in cs to read from
      end - the last character position in cs to read from (this stops after 64 characters if end is too large)
      Returns:
      the long that cs represents
    • intFromBin

      public static int intFromBin​(CharSequence cs)
      Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 32 chars long.
      Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.
      Parameters:
      cs - a CharSequence, such as a String, containing only binary digits (nothing at the start)
      Returns:
      the int that cs represents
    • intFromBin

      public static int intFromBin​(CharSequence cs, int start, int end)
      Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 32 chars long.
      Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.
      Parameters:
      cs - a CharSequence, such as a String, containing only binary digits (nothing at the start)
      start - the first character position in cs to read from
      end - the last character position in cs to read from (this stops after 32 characters if end is too large)
      Returns:
      the int that cs represents
    • b64Encode

      public static char[] b64Encode​(long number, int offset, char[] buf)
      Base-64 encodes number and stores that string representation in buf starting at offset; uses 11 chars.
      Parameters:
      number - the long to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 11
      Returns:
      buf, after modifying it in-place
    • b64Encode

      public static char[] b64Encode​(double number, int offset, char[] buf)
      Base-64 encodes number and stores that string representation in buf starting at offset; uses 11 chars.
      Parameters:
      number - the double to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 11
      Returns:
      buf, after modifying it in-place
    • b64Encode

      public static char[] b64Encode​(int number, int offset, char[] buf)
      Base-64 encodes number and stores that string representation in buf starting at offset; uses 6 chars.
      Parameters:
      number - the int to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 6
      Returns:
      buf, after modifying it in-place
    • b64Encode

      public static char[] b64Encode​(float number, int offset, char[] buf)
      Base-64 encodes number and stores that string representation in buf starting at offset; uses 6 chars.
      Parameters:
      number - the float to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 6
      Returns:
      buf, after modifying it in-place
    • b64Encode

      public static char[] b64Encode​(short number, int offset, char[] buf)
      Base-64 encodes number and stores that string representation in buf starting at offset; uses 3 chars.
      Parameters:
      number - the int to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 3
      Returns:
      buf, after modifying it in-place
    • b64Encode

      public static char[] b64Encode​(char glyph, int offset, char[] buf)
      Base-64 encodes glyph and stores that string representation in buf starting at offset; uses 3 chars.
      Parameters:
      glyph - the char to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 3
      Returns:
      buf, after modifying it in-place
    • b64Encode

      public static char[] b64Encode​(byte number, int offset, char[] buf)
      Base-64 encodes number and stores that string representation in buf starting at offset; uses 2 chars.
      Parameters:
      number - the byte to encode
      offset - the first position to set in buf
      buf - a char array that should be non-null and have length of at least offset + 2
      Returns:
      buf, after modifying it in-place
    • b64DecodeLong

      public static long b64DecodeLong​(char[] data, int offset)
      Decodes 11 characters from data starting from offset to get a long encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 11
      offset - where in data to start reading from
      Returns:
      the decoded long
    • b64DecodeDouble

      public static double b64DecodeDouble​(char[] data, int offset)
      Decodes 11 characters from data starting from offset to get a double encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 11
      offset - where in data to start reading from
      Returns:
      the decoded double
    • b64DecodeInt

      public static int b64DecodeInt​(char[] data, int offset)
      Decodes 6 characters from data starting from offset to get an int encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 6
      offset - where in data to start reading from
      Returns:
      the decoded int
    • b64DecodeFloat

      public static float b64DecodeFloat​(char[] data, int offset)
      Decodes 6 characters from data starting from offset to get a float encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 6
      offset - where in data to start reading from
      Returns:
      the decoded float
    • b64DecodeShort

      public static short b64DecodeShort​(char[] data, int offset)
      Decodes 3 characters from data starting from offset to get a short encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 3
      offset - where in data to start reading from
      Returns:
      the decoded short
    • b64DecodeChar

      public static char b64DecodeChar​(char[] data, int offset)
      Decodes 3 characters from data starting from offset to get a char encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 3
      offset - where in data to start reading from
      Returns:
      the decoded char
    • b64DecodeByte

      public static byte b64DecodeByte​(char[] data, int offset)
      Decodes 2 characters from data starting from offset to get a byte encoded as base-64.
      Parameters:
      data - a char array that should be have length of at least offset + 2
      offset - where in data to start reading from
      Returns:
      the decoded byte
    • hexHash

      public static String hexHash​(boolean... array)
    • hexHash

      public static String hexHash​(byte... array)
    • hexHash

      public static String hexHash​(short... array)
    • hexHash

      public static String hexHash​(char... array)
    • hexHash

      public static String hexHash​(int... array)
    • hexHash

      public static String hexHash​(long... array)
    • padRight

      public static String padRight​(String text, int minimumLength)
      If text is shorter than the given minimumLength, returns a String with text padded on the right with spaces until it reaches that length; otherwise it simply returns text.
      Parameters:
      text - the text to pad if necessary
      minimumLength - the minimum length of String to return
      Returns:
      text, potentially padded with spaces to reach the given minimum length
    • padRight

      public static String padRight​(String text, char padChar, int minimumLength)
      If text is shorter than the given minimumLength, returns a String with text padded on the right with padChar until it reaches that length; otherwise it simply returns text.
      Parameters:
      text - the text to pad if necessary
      padChar - the char to use to pad text, if necessary
      minimumLength - the minimum length of String to return
      Returns:
      text, potentially padded with padChar to reach the given minimum length
    • padRightStrict

      public static String padRightStrict​(String text, int totalLength)
      Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its right side with spaces until totalLength is reached. If text is longer than totalLength, this only uses the portion of text needed to fill totalLength, and no more.
      Parameters:
      text - the String to pad if necessary, or truncate if too long
      totalLength - the exact length of String to return
      Returns:
      a String with exactly totalLength for its length, made from text and possibly extra spaces
    • padRightStrict

      public static String padRightStrict​(String text, char padChar, int totalLength)
      Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its right side with padChar until totalLength is reached. If text is longer than totalLength, this only uses the portion of text needed to fill totalLength, and no more.
      Parameters:
      text - the String to pad if necessary, or truncate if too long
      padChar - the char to use to fill any remaining length
      totalLength - the exact length of String to return
      Returns:
      a String with exactly totalLength for its length, made from text and possibly padChar
    • padLeft

      public static String padLeft​(String text, int minimumLength)
      If text is shorter than the given minimumLength, returns a String with text padded on the left with spaces until it reaches that length; otherwise it simply returns text.
      Parameters:
      text - the text to pad if necessary
      minimumLength - the minimum length of String to return
      Returns:
      text, potentially padded with spaces to reach the given minimum length
    • padLeft

      public static String padLeft​(String text, char padChar, int minimumLength)
      If text is shorter than the given minimumLength, returns a String with text padded on the left with padChar until it reaches that length; otherwise it simply returns text.
      Parameters:
      text - the text to pad if necessary
      padChar - the char to use to pad text, if necessary
      minimumLength - the minimum length of String to return
      Returns:
      text, potentially padded with padChar to reach the given minimum length
    • padLeftStrict

      public static String padLeftStrict​(String text, int totalLength)
      Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its left side with spaces until totalLength is reached. If text is longer than totalLength, this only uses the portion of text needed to fill totalLength, and no more.
      Parameters:
      text - the String to pad if necessary, or truncate if too long
      totalLength - the exact length of String to return
      Returns:
      a String with exactly totalLength for its length, made from text and possibly extra spaces
    • padLeftStrict

      public static String padLeftStrict​(String text, char padChar, int totalLength)
      Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on its left side with padChar until totalLength is reached. If text is longer than totalLength, this only uses the portion of text needed to fill totalLength, and no more.
      Parameters:
      text - the String to pad if necessary, or truncate if too long
      padChar - the char to use to fill any remaining length
      totalLength - the exact length of String to return
      Returns:
      a String with exactly totalLength for its length, made from text and possibly padChar
    • wrap

      public static List<String> wrap​(CharSequence longText, int width)
      Word-wraps the given String (or other CharSequence, such as a StringBuilder) so it is split into zero or more Strings as lines of text, with the given width as the maximum width for a line. This correctly splits most (all?) text in European languages on spaces (treating all whitespace characters matched by the regex '\\s' as breaking), and also uses the English-language rule (probably used in other languages as well) of splitting on hyphens and other dash characters (Unicode category Pd) in the middle of a word. This means for a phrase like "UN Secretary General Ban-Ki Moon", if the width was 12, then the Strings in the List returned would be
       "UN Secretary"
       "General Ban-"
       "Ki Moon"
       
      Spaces are not preserved if they were used to split something into two lines, but dashes are.
      Parameters:
      longText - a probably-large piece of text that needs to be split into multiple lines with a max width
      width - the max width to use for any line, removing trailing whitespace at the end of a line
      Returns:
      a List of Strings for the lines after word-wrapping
    • wrap

      public static List<String> wrap​(List<String> receiving, CharSequence longText, int width)
      Word-wraps the given String (or other CharSequence, such as a StringBuilder) so it is split into zero or more Strings as lines of text, with the given width as the maximum width for a line; appends the word-wrapped lines to the given List of Strings and does not create a new List. This correctly splits most (all?) text in European languages on spaces (treating all whitespace characters matched by the regex '\\s' as breaking), and also uses the English-language rule (probably used in other languages as well) of splitting on hyphens and other dash characters (Unicode category Pd) in the middle of a word. This means for a phrase like "UN Secretary General Ban-Ki Moon", if the width was 12, then the Strings in the List returned would be
       "UN Secretary"
       "General Ban-"
       "Ki Moon"
       
      Spaces are not preserved if they were used to split something into two lines, but dashes are.
      Parameters:
      receiving - the List of String to append the word-wrapped lines to
      longText - a probably-large piece of text that needs to be split into multiple lines with a max width
      width - the max width to use for any line, removing trailing whitespace at the end of a line
      Returns:
      the given receiving parameter, after appending the lines from word-wrapping
    • replace

      public static String replace​(CharSequence text, String before, String after)
    • indexOf

      public static int indexOf​(CharSequence text, regexodus.Pattern regex, int beginIndex)
    • indexOf

      public static int indexOf​(CharSequence text, String regex, int beginIndex)
    • indexOf

      public static int indexOf​(CharSequence text, regexodus.Pattern regex)
    • indexOf

      public static int indexOf​(CharSequence text, String regex)
    • capitalize

      public static String capitalize​(CharSequence original)
      Capitalizes Each Word In The Parameter original, Returning A New String.
      Parameters:
      original - a CharSequence, such as a StringBuilder or String, which could have CrAzY capitalization
      Returns:
      A String With Each Word Capitalized At The Start And The Rest In Lower Case
    • sentenceCase

      public static String sentenceCase​(CharSequence original)
      Attempts to scan for sentences in original, capitalizes the first letter of each sentence, and otherwise leaves the CharSequence untouched as it returns it as a String. Sentences are detected with a crude heuristic of "does it have periods, exclamation marks, or question marks at the end, or does it reach the end of input? If yes, it's a sentence."
      Parameters:
      original - a CharSequence that is expected to contain sentence-like data that needs capitalization; existing upper-case letters will stay upper-case.
      Returns:
      a String where the first letter of each sentence (detected as best this can) is capitalized.
    • correctABeforeVowel

      public static String correctABeforeVowel​(CharSequence text)
      A simple method that looks for any occurrences of the word 'a' followed by some non-zero amount of whitespace and then any vowel starting the following word (such as 'a item'), then replaces each such improper 'a' with 'an' (such as 'an item'). The regex used here isn't bulletproof, but it should be fairly robust, handling when you have multiple whitespace chars, different whitespace chars (like carriage return and newline), accented vowels in the following word (but not in the initial 'a', which is expected to use English spelling rules), and the case of the initial 'a' or 'A'.
      Gotta love Regexodus; this is a two-liner that uses features specific to that regular expression library.
      Parameters:
      text - the (probably generated English) multi-word text to search for 'a' in and possibly replace with 'an'
      Returns:
      a new String with every improper 'a' replaced