From 7cb534fd1fb2cbd0a338ba22457e18ba8cb57f78 Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 24 Jan 2022 17:22:42 +0100 Subject: Make non-alphabetic characters break words --- src/utils/twtstr.nim | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/utils') diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 3050d50e..e2d06535 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -131,12 +131,6 @@ func toAsciiLower*(str: string): string = func getrune(s: string): Rune = return s.toRunes()[0] -const breakWord = [ - Rune('\n'), Rune('/'), Rune('\\'), Rune(' '), Rune('&'), Rune('='), - Rune('?'), Rune('.'), Rune(';'), Rune('"'), "。".getrune(), "、".getrune(), - "「".getrune(), "」".getrune() -] - func genHexCharMap(): seq[int] = for i in 0..255: case chr(i) @@ -193,15 +187,15 @@ func equalsIgnoreCase*(s1: seq[Rune], s2: string): bool = func equalsIgnoreCase*(s1, s2: string): bool {.inline.} = return s1.cmpIgnoreCase(s2) == 0 -func breaksWord*(r: Rune): bool = - return r in breakWord - func isAlphaAscii*(r: Rune): bool = return int(r) < 256 and isAlphaAscii(char(r)) func isDigitAscii*(r: Rune): bool = return int(r) < 256 and isDigit(char(r)) +func breaksWord*(r: Rune): bool = + return not (r.isDigitAscii() or r.isAlpha()) + func substr*(s: seq[Rune], i, j: int): seq[Rune] = if s.len == 0: return @[] -- cgit