diff --git a/src/Range.hs b/src/Range.hs index 5c1dcd60a..3e871e7e9 100644 --- a/src/Range.hs +++ b/src/Range.hs @@ -20,6 +20,15 @@ rangesAndWordsFrom startIndex string = case break (not . isWord) string of ([], rest) | (whitespace, rest) <- break isWord rest -> rangesAndWordsFrom (startIndex + length whitespace) rest (word, rest) -> (Range startIndex $ startIndex + length word, word) : case break isWord rest of (whitespace, rest) -> rangesAndWordsFrom (startIndex + length word + length whitespace) rest where + word string = case span isWord string of + ([], _) -> Nothing + (word, rest) -> Just (word, rest) + punctuation string = case break (\ c -> isWord c || Char.isSpace c) string of + ([], _) -> Nothing + (punctuation, rest) -> Just (punctuation, rest) + space string = case span Char.isSeparator of + ([], _) -> Nothing + (space, rest) -> Just (space, rest) -- | Is this a word character? -- | Word characters are defined as in [Ruby’s `\p{Word}` syntax](http://ruby-doc.org/core-2.1.1/Regexp.html#class-Regexp-label-Character+Properties), i.e.: -- | > A member of one of the following Unicode general category _Letter_, _Mark_, _Number_, _Connector_Punctuation_