diff options
author | Araq <rumpf_a@web.de> | 2011-11-03 20:17:46 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-11-03 20:17:46 +0100 |
commit | d819350145a66cea793c359a4782d3b137c17dd2 (patch) | |
tree | e24b0def9a6c590b299e1b5af385437a74d99d76 /lib/pure | |
parent | 64e74cf4848d9a53074916b5705713855ab755db (diff) | |
download | Nim-d819350145a66cea793c359a4782d3b137c17dd2.tar.gz |
bugfix: new GCC version requires -ldl to come after object files
Diffstat (limited to 'lib/pure')
-rwxr-xr-x | lib/pure/parseutils.nim | 24 | ||||
-rw-r--r-- | lib/pure/uuid.nim | 30 |
2 files changed, 22 insertions, 32 deletions
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim index c78dbcf6f..8660eec2e 100755 --- a/lib/pure/parseutils.nim +++ b/lib/pure/parseutils.nim @@ -106,19 +106,29 @@ proc skipWhitespace*(s: string, start = 0): int {.inline.} = while s[start+result] in Whitespace: inc(result) proc skip*(s, token: string, start = 0): int {.inline.} = + ## skips the `token` starting at ``s[start]``. Returns the length of `token` + ## or 0 if there was no `token` at ``s[start]``. while result < token.len and s[result+start] == token[result]: inc(result) if result != token.len: result = 0 proc skipIgnoreCase*(s, token: string, start = 0): int = + ## same as `skip` but case is ignored for token matching. while result < token.len and toLower(s[result+start]) == toLower(token[result]): inc(result) if result != token.len: result = 0 proc skipUntil*(s: string, until: set[char], start = 0): int {.inline.} = - ## Skips all characters until one char from the set `token` is found. + ## Skips all characters until one char from the set `until` is found + ## or the end is reached. ## Returns number of characters skipped. while s[result+start] notin until and s[result+start] != '\0': inc(result) +proc skipUntil*(s: string, until: char, start = 0): int {.inline.} = + ## Skips all characters until the char `until` is found + ## or the end is reached. + ## Returns number of characters skipped. + while s[result+start] != until and s[result+start] != '\0': inc(result) + proc skipWhile*(s: string, toSkip: set[char], start = 0): int {.inline.} = ## Skips all characters while one char from the set `token` is found. ## Returns number of characters skipped. @@ -130,7 +140,17 @@ proc parseUntil*(s: string, token: var string, until: set[char], ## the number of the parsed characters or 0 in case of an error. A token ## consists of the characters notin `until`. var i = start - while s[i] notin until: inc(i) + while i < s.len and s[i] notin until: inc(i) + result = i-start + token = substr(s, start, i-1) + +proc parseUntil*(s: string, token: var string, until: char, + start = 0): int {.inline.} = + ## parses a token and stores it in ``token``. Returns + ## the number of the parsed characters or 0 in case of an error. A token + ## consists of any character that is not the `until` character. + var i = start + while i < s.len and s[i] != until: inc(i) result = i-start token = substr(s, start, i-1) diff --git a/lib/pure/uuid.nim b/lib/pure/uuid.nim deleted file mode 100644 index 36fa9e445..000000000 --- a/lib/pure/uuid.nim +++ /dev/null @@ -1,30 +0,0 @@ -# This module implements the RFC 4122 specification for generating universally unique identifiers -# http://en.wikipedia.org/wiki/Universally_unique_identifier - -# This module is a work-in-progress -# If you want to help with the implementation, take a loot at: -# http://dsource.org/projects/tango/docs/current/tango.util.uuid.Uuid.html - -type TUuid* = array[0..15, char] - -when defined(windows): - # This is actually available only on Windows 2000+ - type PUuid* {.importc: "UUID __RPC_FAR *", header: "<Rpc.h>".} = ptr TUuid - proc uuid1Sys*(uuid: PUuid) {.importc: "UuidCreateSequential", header: "<Rpc.h>".} - -else: - type PUuid {.importc: "uuid_t", header: "<uuid/uuid.h>".} = ptr TUuid - proc uuid1Sys*(uuid: PUuid) {.importc: "uuid_generate_time", header: "<uuid/uuid.h>".} - -# v1 UUIDs include the MAC address of the machine generating the ID and a timestamp -# This scheme has the strongest guaranty of uniqueness, but discloses when the ID was generated -proc uuidMacTime* : TUuid = uuid1Sys(addr(result)) - -# v4 UUID are created entirely using a random number generator. -# Some bits have fixed value in order to indicate the UUID type -proc uuidRandom*[RandomGenerator](rand: RandomGenerator) : TUuid = nil - -# v3 and v5 UUIDs are derived from given namespace and name using a secure hashing algorithm. -# v3 uses MD5, v5 uses SHA1. -proc uuidByName*[Hash](namespace: TUuid, name: string, hasher: Hash, v: int) : TUuid = nil - |