int (String text, int start, int end) { boolean slash = false; boolean ws = false; int doubleQuotes = 0; for (int i = start; i < end; i++) { final char ch = text.charAt(i); if (ch == '\\') slash = !slash; else if (ch == ' ' || ch == '\t') ws = true; else { if (slash) { if (ch == 'n') { if (!ws) return i - 1; } else if (ch == '\'') { return i - 1; } else if (ch == '"' && doubleQuotes < 2) { if (i == end - 1) return -1; if (i == end - 2) return i - 1; if (i < end - 2 && text.charAt(i + 1) == '"') { if (doubleQuotes != 1 && text.charAt(i + 2) != '"') return i - 1; } else { return i - 1; } } doubleQuotes = 0; } else if (ch == '"') doubleQuotes++; else doubleQuotes = 0; slash = false; ws = false; } } return -1; }