AlgoBox { public static String subStr(String sInput, String pattern) { if (sInput == null || "".equals(sInput)) { return ""; } if (pattern == null) { return ""; } else { String d_pattern = "^[0-9]*[;][0-9]*"; if (pattern.matches(d_pattern)) { int beginIndex = Integer.parseInt(pattern.substring(0, pattern.indexOf(";"))); int endIndex = Integer.parseInt(pattern.substring(pattern.indexOf(";") + 1)); int sInputCPCount = sInput.codePointCount(0, sInput.length()); if (sInputCPCount < endIndex) { endIndex = sInputCPCount; } if (beginIndex <= endIndex) { return sInput.substring(sInput.offsetByCodePoints(0, beginIndex), sInput.offsetByCodePoints(0, endIndex)); } } } return ""; }  static void main(String[] args); static String pick_Char(String sInput, String pattern); static String first_N_Consonants(String sInput, int nb); static String first_N_Vowels(String sInput, int nb); static String subStr(String sInput, String pattern); static String first_N_Char(String sInput, int nb); static String last_N_Char(String sInput, int nb); static String first_N_Char_EW(String sInput, int nb); static String first_Char_EW(String sInput); static String soundex(String sInput); static String doublemetaphone(String sInput); static String metaphone(String sInput); static String add_Left_Char(String sInput, String position); static String add_Right_Char(String sInput, String position); static String removeDiacriticalMarks(String sInput); static String exact(String sInput); static String useDefault(String sInput, String insteadOf); static String lowerCase(String sInput); static String upperCase(String sInput); static String removeDMAndLowerCase(String sInput); static String removeDMAndUpperCase(String sInput); static String fingerPrintKey(String sInput); static String nGramKey(String sInput); static String colognePhonetic(String sInput);  }
@Test public void testSubStr() { assertEquals(BLANK_STR, AlgoBox.subStr(TEST_STR, BLANK_STR)); assertEquals(BLANK_STR, AlgoBox.subStr(TEST_STR, null)); assertEquals(BLANK_STR, AlgoBox.subStr(BLANK_STR, TEST_STR)); assertEquals(BLANK_STR, AlgoBox.subStr(null, TEST_STR)); assertEquals(BLANK_STR, AlgoBox.subStr(TEST_STR, SPACE_STR)); assertEquals("est", AlgoBox.subStr(TEST_STR, "1;100")); assertEquals("cd", AlgoBox.subStr("abcdef", "2;4")); assertEquals("𠀐我", AlgoBox.subStr(MIXTD_SURROGATEPAIR, "1;3")); assertEquals("我𠀑a", AlgoBox.subStr(MIXTD_SURROGATEPAIR, "2;5")); assertEquals("ゴを", AlgoBox.subStr(JAPANESE2_STR, "2;4")); }