Class StringHelper


  • public class StringHelper
    extends Object
    Helper methods related to Strings
    Author:
    Michel Kraemer
    • Constructor Detail

      • StringHelper

        public StringHelper()
    • Method Detail

      • sanitize

        public static String sanitize​(String s)
        Sanitizes a string so it can be used as an identifier
        Parameters:
        s - the string to sanitize
        Returns:
        the sanitized string
      • escapeJava

        public static String escapeJava​(String s)
        Escapes characters in the given string according to Java rules
        Parameters:
        s - the string to escape
        Returns:
        the escpaped string
      • overlap

        public static int overlap​(CharSequence a,
                                  CharSequence b)

        Calculates how many characters overlap between a and b, i.e. how many characters at the end of a are equal to the ones at the beginning of b.

        Examples:

         overlap("abcd", "cdef")     = 2
         overlap("abcd", "xyz")      = 0
         overlap("a", "a")           = 1
         overlap("ab", "b")          = 1
         overlap("abcd", "bcdefg")   = 3
         overlap("", "a")            = 0
         overlap("a", "")            = 0
         
        Parameters:
        a - the first string
        b - the second string
        Returns:
        the number of overlapping characters
      • toTitleCase

        public static String toTitleCase​(String str)

        Converts the words in a given string to title case (according to the CSL specification).

        The implementation of this method is based on JavaScript library to-title-case, Copyright 2008–2018 David Gouch, released under the MIT license. (https://github.com/gouch/to-title-case). It has been slightly modified for the CSL specification.

        Parameters:
        str - the string to convert
        Returns:
        the converted string