From 87d6f908cc21fef218209678dd8ea543b097905d Mon Sep 17 00:00:00 2001 From: Jean Cavallo Date: Mon, 30 Mar 2015 12:19:51 +0200 Subject: [PATCH] Fix #110 : use '^' rather than '-' for list negative indexes --- src/nimble.nim | 2 +- src/nimblepkg/download.nim | 4 ++-- src/nimblepkg/packageinfo.nim | 6 +++--- src/nimblepkg/tools.nim | 2 +- src/nimblepkg/version.nim | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index 3298e7c..eef6300 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -171,7 +171,7 @@ proc parseCmdLine(): Options = # Parse pkg@verRange if '@' in key: let i = find(key, '@') - let pkgTup = (key[0 .. i-1], key[i+1 .. -1].parseVersionRange()) + let pkgTup = (key[0 .. i-1], key[i+1 .. ^1].parseVersionRange()) result.action.packages.add(pkgTup) else: result.action.packages.add((key, VersionRange(kind: verAny))) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index 9e2ebac..ddd9112 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -104,7 +104,7 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = for i in output.splitLines(): if i == "": continue let start = i.find("refs/tags/")+"refs/tags/".len - let tag = i[start .. -1] + let tag = i[start .. ^1] if not tag.endswith("^{}"): result.add(tag) of DownloadMethod.hg: @@ -118,7 +118,7 @@ proc getVersionList*(tags: seq[string]): Table[Version, string] = if tag != "": let i = skipUntil(tag, Digits) # skip any chars before the version # TODO: Better checking, tags can have any names. Add warnings and such. - result[newVersion(tag[i .. -1])] = tag + result[newVersion(tag[i .. ^1])] = tag proc getDownloadMethod*(meth: string): DownloadMethod = case meth diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 42ccca1..51bf5a5 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -88,11 +88,11 @@ proc parseRequires(req: string): PkgTuple = if ' ' in req: var i = skipUntil(req, Whitespace) result.name = req[0 .. i].strip - result.ver = parseVersionRange(req[i .. -1]) + result.ver = parseVersionRange(req[i .. ^1]) elif '#' in req: var i = skipUntil(req, {'#'}) result.name = req[0 .. i-1] - result.ver = parseVersionRange(req[i .. -1]) + result.ver = parseVersionRange(req[i .. ^1]) else: result.name = req.strip result.ver = VersionRange(kind: verAny) @@ -339,7 +339,7 @@ proc getNameVersion*(pkgpath: string): tuple[name, version: string] = for i in countdown(tail.len-1, 0): if tail[i] == '-': result.name = tail[0 .. i-1] - result.version = tail[i+1 .. -1] + result.version = tail[i+1 .. ^1] break proc echoPackage*(pkg: Package) = diff --git a/src/nimblepkg/tools.nim b/src/nimblepkg/tools.nim index 7ced95a..d7b85d4 100644 --- a/src/nimblepkg/tools.nim +++ b/src/nimblepkg/tools.nim @@ -62,7 +62,7 @@ proc changeRoot*(origRoot, newRoot, path: string): string = ## path: /home/dom/bar/blah/2/foo.txt ## Return value -> /home/test/bar/blah/2/foo.txt if path.startsWith(origRoot): - return newRoot / path[origRoot.len .. -1] + return newRoot / path[origRoot.len .. ^1] else: raise newException(ValueError, "Cannot change root of path: Path does not begin with original root.") diff --git a/src/nimblepkg/version.nim b/src/nimblepkg/version.nim index f42eea6..f16c4d7 100644 --- a/src/nimblepkg/version.nim +++ b/src/nimblepkg/version.nim @@ -139,7 +139,7 @@ proc parseVersionRange*(s: string): VersionRange = new(result) if s[0] == '#': result.kind = verSpecial - result.spe = s[1 .. -1].Special + result.spe = s[1 .. ^1].Special return var i = 0