about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-12-05 19:55:13 +0100
committerbptato <nincsnevem662@gmail.com>2021-12-05 19:55:13 +0100
commit31117cad22df103f84cfbe97dff08debcde72a66 (patch)
tree5f9e4b0515e63e953758fe10da9fc52d45171e0f /src/utils/twtstr.nim
parent0f9c94abf5ff9e4f2ce4d8d49424c9458bbf6229 (diff)
downloadchawan-31117cad22df103f84cfbe97dff08debcde72a66.tar.gz
Change configuration format to toml
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim88
1 files changed, 78 insertions, 10 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 2dd8615b..d437be6a 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -5,6 +5,7 @@ import tables
 import json
 import bitops
 import os
+import math
 
 when defined(posix):
   import posix
@@ -40,15 +41,6 @@ func fitValueToSize*(str: string, size: int): string =
     return str & ' '.repeat(size - str.runeLen)
   return str.maxString(size)
 
-func buttonFmt*(str: string): seq[string] =
-  return "[".ansiFgColor(fgRed) & str.ansiFgColor(fgRed).ansiReset() & "]".ansiFgColor(fgRed).ansiReset()
-
-func buttonFmt*(str: seq[string]): seq[string] =
-  return "[".ansiFgColor(fgRed) & str.ansiFgColor(fgRed).ansiReset() & "]".ansiFgColor(fgRed).ansiReset()
-
-func buttonRaw*(str: string): string =
-  return "[" & str & "]"
-
 func remove*(str: string, c: string): string =
   let rem = c.toRunes()[0]
   for rune in str.runes:
@@ -198,6 +190,83 @@ func skipBlanks*(buf: string, at: int): int =
   while result < buf.len and buf[result].isWhitespace():
     inc result
 
+func parseInt64*(s: string): int64 =
+  var sign = 1
+  var t = 1
+  var d = 0
+  var integer: int64 = 0
+  var e: int64 = 0
+
+  var i = 0
+  if i < s.len and s[i] == '-':
+    sign = -1
+    inc i
+  elif i < s.len and s[i] == '+':
+    inc i
+
+  while i < s.len and isDigit(s[i]):
+    integer *= 10
+    integer += decValue(s[i])
+    inc i
+
+  if i < s.len and (s[i] == 'e' or s[i] == 'E'):
+    inc i
+    if i < s.len and s[i] == '-':
+      t = -1
+      inc i
+    elif i < s.len and s[i] == '+':
+      inc i
+
+    while i < s.len and isDigit(s[i]):
+      e *= 10
+      e += decValue(s[i])
+      inc i
+
+  return sign * integer * 10 ^ t * e
+
+func parseFloat64*(s: string): float64 =
+  var sign = 1
+  var t = 1
+  var d = 0
+  var integer: float64 = 0
+  var f: float64 = 0
+  var e: float64 = 0
+
+  var i = 0
+  if i < s.len and s[i] == '-':
+    sign = -1
+    inc i
+  elif i < s.len and s[i] == '+':
+    inc i
+
+  while i < s.len and isDigit(s[i]):
+    integer *= 10
+    integer += float64(decValue(s[i]))
+    inc i
+
+  if i < s.len and s[i] == '.':
+    inc i
+    while i < s.len and isDigit(s[i]):
+      f *= 10
+      f += float64(decValue(s[i]))
+      inc i
+      inc d
+
+  if i < s.len and (s[i] == 'e' or s[i] == 'E'):
+    inc i
+    if i < s.len and s[i] == '-':
+      t = -1
+      inc i
+    elif i < s.len and s[i] == '+':
+      inc i
+
+    while i < s.len and isDigit(s[i]):
+      e *= 10
+      e += float64(decValue(s[i]))
+      inc i
+
+  return float64(sign) * (integer + f * pow(10, float64(-d))) * pow(10, (float64(t) * e))
+
 proc expandPath*(path: string): string =
   if path.len == 0:
     return path
@@ -599,4 +668,3 @@ proc fullwidth*(s: seq[Rune]): seq[Rune] =
 
 proc fullwidth*(s: string): string =
   return $fullwidth(s.toRunes())
-