all repos — min @ vm

A small but practical concatenative programming language.

minpkg/core/baseutils.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
import 
  strutils,
  os, 
  json

proc reverse*[T](xs: openarray[T]): seq[T] =
  result = newSeq[T](xs.len)
  for i, x in xs:
    result[result.len-i-1] = x 

proc simplifyPath*(filename: string, f: string): string =
  let file = strutils.replace(f, "\\", "/")
  let fn = strutils.replace(filename, "./", "")
  var dirs: seq[string] = fn.split("/")
  discard dirs.pop
  let pwd = dirs.join("/")
  if pwd == "":
    result = file
  else:
    result = pwd&"/"&file

proc unix*(s: string): string =
  return s.replace("\\", "/")
  
proc parentDirEx*(s: string): string =
  return s.parentDir
    
proc escapeEx*(s: string, unquoted = false): string =
  if unquoted:
    return s.escapeJsonUnquoted
  return s.escapeJson