aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-02-19 12:12:49 +0100
committerbptato <nincsnevem662@gmail.com>2022-02-19 12:12:49 +0100
commit1aec6113a6dbae0878f849675ec9d1417cb6a787 (patch)
tree7df49d9b0bdeb438c9fe353b5db4fdd89809a8d9 /src/utils
parent7fd9de65e4acfdbb71b284353043c19e2f152acd (diff)
downloadchawan-1aec6113a6dbae0878f849675ec9d1417cb6a787.tar.gz
twtstr: replace bisearch with stdlib binarySearch
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/twtstr.nim22
1 files changed, 2 insertions, 20 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index df8cfa6e..a48f80b2 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -1,3 +1,4 @@
+import algorithm
import terminal
import strutils
import unicode
@@ -760,28 +761,9 @@ const ambiguous = [
# to UCS without changing the traditional terminal character-width behaviour.
# It is not otherwise recommended for general use.
-# auxiliary function for binary search in interval table
-func bisearch(ucs: Rune, table: openarray[(int, int)]): bool =
- var max = table.high
- var min = 0
- var mid: int
-
- if int(ucs) < table[0][0] or int(ucs) > table[max][1]:
- return false
-
- while max >= min:
- mid = (min + max) div 2
- if int(ucs) > table[mid][1]:
- min = mid + 1
- elif int(ucs) < table[mid][0]:
- max = mid - 1
- else:
- return true
- return false
-
func is_dwidth_cjk(r: Rune): bool =
# binary search in table of non-spacing characters
- if bisearch(r, ambiguous):
+ if binarySearch(ambiguous, int32(r), (x, y) => (if x[0] < y: -1 elif x[1] > y: 1 else: 0)) != -1:
return true
return r.is_dwidth()