summary refs log tree commit diff stats
path: root/lib/std/private
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-05-05 05:56:15 -0700
committerGitHub <noreply@github.com>2020-05-05 14:56:15 +0200
commitc28a057a6bd5f20445e11d82c4028762ae1bf1b6 (patch)
treed5a6e7ab9e53dc68eda848c1c2dd3afc67972acb /lib/std/private
parent6b7b5fb4fa7865d17f2433ddc49bac1483b19a01 (diff)
downloadNim-c28a057a6bd5f20445e11d82c4028762ae1bf1b6.tar.gz
fix js stacktraces, unify all file,line,col formatting into a single function (#14230)
* fix https://github.com/timotheecour/Nim/issues/135 ; unify all file,line,col formatting into a single function
Diffstat (limited to 'lib/std/private')
-rw-r--r--lib/std/private/miscdollars.nim15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/std/private/miscdollars.nim b/lib/std/private/miscdollars.nim
new file mode 100644
index 000000000..a41cf1bc1
--- /dev/null
+++ b/lib/std/private/miscdollars.nim
@@ -0,0 +1,15 @@
+template toLocation*(result: var string, file: string | cstring, line: int, col: int) =
+  ## avoids spurious allocations
+  # Hopefully this can be re-used everywhere so that if a user needs to customize,
+  # it can be done in a single place.
+  result.add file
+  if line > 0:
+    result.add "("
+    # simplify this after moving moving `include strmantle` above import assertions`
+    when declared(addInt): result.addInt line
+    else: result.add $line
+    if col > 0:
+      result.add ", "
+      when declared(addInt): result.addInt col
+      else: result.add $col
+    result.add ")"