@Test public void beginPartTest() { String sql = null; int removePart = StringUtils.beginPart(sql, "", null, 0); Assert.assertEquals(removePart, -1); sql = " "; removePart = StringUtils.beginPart(sql, "", null, 0); Assert.assertEquals(removePart, -1); sql = "toto"; removePart = StringUtils.beginPart(sql, "", null, 0); Assert.assertEquals(removePart, -1); sql = "select Price from products;"; removePart = StringUtils.beginPart(sql, "", null, 0); Assert.assertEquals(removePart, -1); sql = " select Price from products;"; removePart = StringUtils.beginPart(sql, "", null, 0); Assert.assertEquals(removePart, 19); sql = " select Price from products; "; removePart = StringUtils.beginPart(sql, "", null, removePart); Assert.assertEquals(removePart, 19); }
public static int beginPart(final String str, final String start, final String end, final String exception, final int first) { if (str == null || str.length() == 0) { return -1; } final int startComment = str.indexOf(start, first); final int endComment = str.indexOf(end, first); if (startComment == -1 || endComment == -1 || startComment >= endComment) { return -1; } if (exception != null) { final int startException = str.indexOf(exception); if (startComment == startException) { int beginPart = beginPart(str, start, end, exception, endComment + end.length()); return beginPart; } } if (startComment > first) { return first; } return endComment + end.length(); }
StringUtils { public static int beginPart(final String str, final String start, final String end, final String exception, final int first) { if (str == null || str.length() == 0) { return -1; } final int startComment = str.indexOf(start, first); final int endComment = str.indexOf(end, first); if (startComment == -1 || endComment == -1 || startComment >= endComment) { return -1; } if (exception != null) { final int startException = str.indexOf(exception); if (startComment == startException) { int beginPart = beginPart(str, start, end, exception, endComment + end.length()); return beginPart; } } if (startComment > first) { return first; } return endComment + end.length(); } }
StringUtils { public static int beginPart(final String str, final String start, final String end, final String exception, final int first) { if (str == null || str.length() == 0) { return -1; } final int startComment = str.indexOf(start, first); final int endComment = str.indexOf(end, first); if (startComment == -1 || endComment == -1 || startComment >= endComment) { return -1; } if (exception != null) { final int startException = str.indexOf(exception); if (startComment == startException) { int beginPart = beginPart(str, start, end, exception, endComment + end.length()); return beginPart; } } if (startComment > first) { return first; } return endComment + end.length(); } private  StringUtils(); }
StringUtils { public static int beginPart(final String str, final String start, final String end, final String exception, final int first) { if (str == null || str.length() == 0) { return -1; } final int startComment = str.indexOf(start, first); final int endComment = str.indexOf(end, first); if (startComment == -1 || endComment == -1 || startComment >= endComment) { return -1; } if (exception != null) { final int startException = str.indexOf(exception); if (startComment == startException) { int beginPart = beginPart(str, start, end, exception, endComment + end.length()); return beginPart; } } if (startComment > first) { return first; } return endComment + end.length(); } private  StringUtils(); static String padRight(final String s, final int n); static String padRight(final String start, final String s, final int n); static String replaceAll(final String str, final String replace, final String replacement); static String removePart(final String str, final String start, final String end); static String removePart(final String str, final String start, final String end, final String exception); static int beginPart(final String str, final String start, final String end, final String exception,
			final int first); }
StringUtils { public static int beginPart(final String str, final String start, final String end, final String exception, final int first) { if (str == null || str.length() == 0) { return -1; } final int startComment = str.indexOf(start, first); final int endComment = str.indexOf(end, first); if (startComment == -1 || endComment == -1 || startComment >= endComment) { return -1; } if (exception != null) { final int startException = str.indexOf(exception); if (startComment == startException) { int beginPart = beginPart(str, start, end, exception, endComment + end.length()); return beginPart; } } if (startComment > first) { return first; } return endComment + end.length(); } private  StringUtils(); static String padRight(final String s, final int n); static String padRight(final String start, final String s, final int n); static String replaceAll(final String str, final String replace, final String replacement); static String removePart(final String str, final String start, final String end); static String removePart(final String str, final String start, final String end, final String exception); static int beginPart(final String str, final String start, final String end, final String exception,
			final int first);  }