about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-08-11 22:26:30 +0200
committerbptato <nincsnevem662@gmail.com>2021-08-11 22:26:30 +0200
commit2f32d6ed51e14d6871c7be4fd1f8ccdc0455a0bb (patch)
treebcc405a077944852780551d5700d284958e49ce1 /src/utils/twtstr.nim
parent6cea57b35e4e749de531faf6502237c1cf7ed022 (diff)
downloadchawan-2f32d6ed51e14d6871c7be4fd1f8ccdc0455a0bb.tar.gz
Get rid of some old code, work on css property handling
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 707b09a9..9cf63d68 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -464,8 +464,11 @@ const HasHanDakuten = "ぱぴぷぺぽパピプペポ".toRunes()
 #in unicode, char + 1 is dakuten and char + 2 handakuten
 #゙゚
 
-const Dakuten = "゙".toRunes()[0]
-const HanDakuten = "゚".toRunes()[0]
+const HalfDakuten = "゙".toRunes()[0]
+const HalfHanDakuten = "゚".toRunes()[0]
+
+const Dakuten = Rune(0x3099)
+const HanDakuten = Rune(0x309A)
 
 func dakuten*(r: Rune): Rune =
   if r in CanHaveDakuten:
@@ -509,15 +512,20 @@ func halfwidth*(r: Rune): Rune =
 
 func halfwidth*(s: seq[Rune]): seq[Rune] =
   for r in s:
-    #TODO implement a setting to enable this, I personally dislike it
-    #if r in HasDakuten:
-    #  result.add(halfwidth(r.nodakuten()))
-    #  result.add(Dakuten)
-    #elif r in HasHanDakuten:
-    #  result.add(halfwidth(r.nohandakuten()))
-    #  result.add(HanDakuten)
-    #else:
-    result.add(halfwidth(r))
+    #TODO combining dakuten don't always work with half width chars
+    #a proper solution would be something like:
+    #* try to detect if they work, if not fallback to halfwidth handakuten
+    #* add a config option for overriding this
+    #* also add an option to completely ignore dakuten
+    #* and one to disable half width ruby of course
+    if r in HasDakuten:
+      result.add(halfwidth(r.nodakuten()))
+      result.add(Dakuten)
+    elif r in HasHanDakuten:
+      result.add(halfwidth(r.nohandakuten()))
+      result.add(HanDakuten)
+    else:
+      result.add(halfwidth(r))
 
 func halfwidth*(s: string): string =
   return $halfwidth(s.toRunes())
@@ -542,3 +550,4 @@ proc fullwidth*(s: seq[Rune]): seq[Rune] =
 
 proc fullwidth*(s: string): string =
   return $fullwidth(s.toRunes())
+