Renamed toUUID to parseUUID
This commit is contained in:
parent
3951521a16
commit
e9772338df
2 changed files with 4 additions and 4 deletions
|
|
@ -21,7 +21,7 @@ proc genUUID*(): UUID =
|
||||||
## Uses random values obtained from system source (e.g. urandom).
|
## Uses random values obtained from system source (e.g. urandom).
|
||||||
## In the future this will use a cryptographically secure PRNG for efficiency.
|
## In the future this will use a cryptographically secure PRNG for efficiency.
|
||||||
|
|
||||||
proc toUUID*(s: string): UUID {.raises: [ValueError].}
|
proc parseUUID*(s: string): UUID {.raises: [ValueError].}
|
||||||
## Converts string representation of an UUID to UUID object.
|
## Converts string representation of an UUID to UUID object.
|
||||||
## Raises ValueError if invalid format is provided.
|
## Raises ValueError if invalid format is provided.
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ proc genUUID*(): UUID =
|
||||||
result.leastSigBits = (result.leastSigBits and 0x3FFFFFFFFFFFFFFF'i64) or
|
result.leastSigBits = (result.leastSigBits and 0x3FFFFFFFFFFFFFFF'i64) or
|
||||||
0x8000000000004000'i64
|
0x8000000000004000'i64
|
||||||
|
|
||||||
proc toUUID*(s: string): UUID {.raises: [ValueError].} =
|
proc parseUUID*(s: string): UUID {.raises: [ValueError].} =
|
||||||
## Converts string representation of an UUID to UUID object.
|
## Converts string representation of an UUID to UUID object.
|
||||||
## Raises ``ValueError`` if invalid format is provided.
|
## Raises ``ValueError`` if invalid format is provided.
|
||||||
let parts = s.split('-')
|
let parts = s.split('-')
|
||||||
|
|
@ -79,5 +79,5 @@ when isMainModule:
|
||||||
assert(uuidStr.len == 36)
|
assert(uuidStr.len == 36)
|
||||||
assert(uuidStr[14] == '4') # version
|
assert(uuidStr[14] == '4') # version
|
||||||
assert(uuidStr[19] in {'8', '9', 'a', 'b'}) # variant (2 bits)
|
assert(uuidStr[19] in {'8', '9', 'a', 'b'}) # variant (2 bits)
|
||||||
assert(uuidStr.toUUID() == uuid)
|
assert(uuidStr.parseUUID() == uuid)
|
||||||
assert(uuidStr.toUUID().hash() == uuid.hash())
|
assert(uuidStr.parseUUID().hash() == uuid.hash())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue