jodd-core/src/main/java/jodd/util/StringUtil.java
public static String substring(final String string, int fromIndex, int toIndex) {
		int len = string.length();

		if (fromIndex < 0) {
			fromIndex = len + fromIndex;

			if (toIndex == 0) {
				toIndex = len;
			}
		}

		if (toIndex < 0) {
			toIndex = len + toIndex;
		}

		// safe net

		if (fromIndex < 0) {
			fromIndex = 0;
		}
		if (toIndex > len) {
			toIndex = len;
		}
		if (fromIndex >= toIndex) {
			return StringPool.EMPTY;
		}

		return string.substring(fromIndex, toIndex);
	}
public static String substring(final String string, int fromIndex, int toIndex) {
		int len = string.length();

		if (fromIndex < 0) {
			fromIndex = len + fromIndex;

			if (toIndex == 0) {
				toIndex = len;
			}
		}

		if (toIndex < 0) {
			toIndex = len + toIndex;
		}

		// safe net

		if (fromIndex < 0) {
			fromIndex = 0;
		}
		if (toIndex > len) {
			toIndex = len;
		}
		if (fromIndex >= toIndex) {
			return StringPool.EMPTY;
		}

		return string.substring(fromIndex, toIndex);
	}
public static String substring ( final String string , int fromIndex , int toIndex ) { int len = string . length ( ) ; if ( fromIndex < 0 ) { fromIndex = len + fromIndex ; if ( toIndex == 0 ) { toIndex = len ; } } if ( toIndex < 0 ) { toIndex = len + toIndex ; } // safe net if ( fromIndex < 0 ) { fromIndex = 0 ; } if ( toIndex > len ) { toIndex = len ; } if ( fromIndex >= toIndex ) { return StringPool . EMPTY ; } return string . substring ( fromIndex , toIndex ) ; }
Returns a new string that is a substring of this string. The substring
begins at the specified <code>fromIndex</code> and extends to the character
at index <code>toIndex - 1</code>. However, index values can be negative,
and then the real index will be calculated from the strings end. This
allows to specify, e.g. <code>substring(1,-1)</code> to cut one character
from both ends of the string. If <code>fromIndex</code> is negative
and <code>toIndex</code> is 0, it will return last characters of the string.
Also, this method will never throw an exception if index is out of range.
Returns a new string that is a substring of this string . The substring begins at the specified <code > fromIndex< / code > and extends to the character at index <code > toIndex - 1< / code > . However index values can be negative and then the real index will be calculated from the strings end . This allows to specify e . g . <code > substring ( 1 - 1 ) < / code > to cut one character from both ends of the string . If <code > fromIndex< / code > is negative and <code > toIndex< / code > is 0 it will return last characters of the string . Also this method will never throw an exception if index is out of range .