Skip to content

Commit ebe0a91

Browse files
committed
rename calcsize to computeLength, and expose it. closes #5
1 parent 176e72e commit ebe0a91

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

struct.nim

+6-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ proc getDouble*(node: StructNode): float64 {.noSideEffect, inline.} =
123123
proc getString*(node: StructNode): string {.noSideEffect, inline.} =
124124
node.str
125125

126-
proc calcsize(format: string): int =
126+
proc computeLength*(format: string): int =
127+
## Compute the length for string represent `format`
127128
var repeat = newString(0)
128129
for i in 0..format.len-1:
129130
let f: char = format[i]
@@ -262,9 +263,9 @@ proc unpack_string(vars: var seq[StructNode], ctx: var StructContext) =
262263
proc unpack*(fmt, buf: string): seq[StructNode] =
263264
result = @[]
264265

265-
let size = calcsize(fmt)
266-
if buf.len < size:
267-
raise newException(ValueError, "unpack requires a string argument of length " & $size & ", input: " & $buf.len)
266+
let length = computeLength(fmt)
267+
if buf.len < length:
268+
raise newException(ValueError, "unpack requires a string argument of length " & $length & ", input: " & $buf.len)
268269

269270
var context = newStructContext()
270271
context.buffer = buf
@@ -407,7 +408,7 @@ proc pack_pad(result: var string, ctx: var StructContext) =
407408
inc(ctx.index, ctx.repeat)
408409

409410
proc pack*(fmt: string, vars: varargs[StructNode]): string =
410-
result = newString(calcsize(fmt))
411+
result = newString(computeLength(fmt))
411412
var context = newStructContext()
412413
var repeat = newString(0)
413414
for i in 0..fmt.len-1:

struct.nimble

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Package]
22
name = "struct"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
author = "Huy Doan"
55
description = "Python-like 'struct' for Nim"
66
license = "MIT"

0 commit comments

Comments
 (0)