comparison semiconginev2/old/core/utils.nim @ 1218:56781cc0fc7c compiletime-tests

did: renamge main package
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 21:01:37 +0700
parents semicongine/old/core/utils.nim@a3eb305bcac2
children
comparison
equal deleted inserted replaced
1217:f819a874058f 1218:56781cc0fc7c
1 import std/typetraits
2 import std/strutils
3 import std/paths
4 import std/os
5 import std/strformat
6
7 type
8 HorizontalAlignment* = enum
9 Left
10 Center
11 Right
12 VerticalAlignment* = enum
13 Top
14 Center
15 Bottom
16
17 func CleanString*(str: openArray[char]): string =
18 for i in 0 ..< len(str):
19 if str[i] == char(0):
20 result = join(str[0 ..< i])
21 break
22
23 func ToCPointer*[T](list: openArray[T]): ptr T =
24 if list.len > 0: addr(list[0]) else: nil
25
26 proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} =
27 let (output, exitcode) = gorgeEx(
28 command = command,
29 input = input)
30 if exitcode != 0:
31 raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output)
32 return output
33
34 proc AppName*(): string =
35 return string(Path(getAppFilename()).splitFile.name)
36
37 func Size*[T: seq](list: T): uint64 =
38 uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))