code: public static String substring(String input, int beginIndex, int endIndex) {
          if (beginIndex < 0) {
              beginIndex = 0;
          }
          if (endIndex < 0 || endIndex > input.length()) {
              endIndex = input.length();
          }
          if (endIndex < beginIndex) {
              return "";
          }
          return input.substring(beginIndex, endIndex);
      }
docs: Returns a subset of a string according to the semantics of <code>String#substring()</code>
  with additional semantics as follows:
  <ul>
  <li>if <code>beginIndex < 0</code> its value is adjusted to 0</li>
  <li>if <code>endIndex < 0 or greater than the string length</code>,
  its value is adjusted to the length of the string</li>
  <li>if <code>endIndex < beginIndex</code>, an empty string is returned</li>
  </ul>
  
  @param input      the input string on which the substring function is applied
  @param beginIndex the beginning index (0-based), inclusive
  @param endIndex   the end index (0-based), exclusive
  @return a subset of string