Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. private static String nextWordOrSeparator(String text, int position,
  2. Set<Character> separators) {
  3. assert text != null : "Violation of: text is not null";
  4. assert separators != null : "Violation of: separators is not null";
  5. assert 0 <= position : "Violation of: 0 <= position";
  6. assert position < text.length() : "Violation of: position < |text|";
  7.  
  8. String answer = "";
  9.  
  10. int endPosition = position + 1;
  11. boolean wordOrSep = separators.contains(text.charAt(position));
  12.  
  13. while (endPosition < text.length() && (wordOrSep == separators
  14. .contains(text.charAt(endPosition)))) {
  15. endPosition++;
  16. }
  17.  
  18. answer = text.substring(position, endPosition);
  19.  
  20. return answer;
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement