List<String> (@NotNull String query) { List<String> words = new ArrayList<>(); int length = query.length(); int index = 0; while (index < length) { char startCh = query.charAt(index++); if (startCh == ' ') { continue; } if (startCh == '"') { int end = query.indexOf('"', index); if (end == -1) { break; } words.add(query.substring(index, end)); index = end + 1; continue; } int start = index - 1; while (index <= length) { if (index == length) { words.add(query.substring(start)); break; } char nextCh = query.charAt(index++); if (nextCh == ':' || nextCh == ' ' || index == length) { words.add(query.substring(start, nextCh == ' ' ? index - 1 : index)); break; } } } return words; }