Merge pull request #2419 from def-/dotdot

Dotdot
This commit is contained in:
Andreas Rumpf 2015-03-28 00:44:51 +01:00
commit bd56d36326
10 changed files with 93 additions and 93 deletions

View file

@ -61,8 +61,8 @@ proc pasv(ftp: AsyncFtpClient) {.async.} =
assertReply(pasvMsg, "227") assertReply(pasvMsg, "227")
var betweenParens = captureBetween(pasvMsg.string, '(', ')') var betweenParens = captureBetween(pasvMsg.string, '(', ')')
var nums = betweenParens.split(',') var nums = betweenParens.split(',')
var ip = nums[0.. -3] var ip = nums[0.. ^3]
var port = nums[-2.. -1] var port = nums[^2.. ^1]
var properPort = port[0].parseInt()*256+port[1].parseInt() var properPort = port[0].parseInt()*256+port[1].parseInt()
await ftp.dsock.connect(ip.join("."), Port(properPort.toU16)) await ftp.dsock.connect(ip.join("."), Port(properPort.toU16))
ftp.dsockConnected = true ftp.dsockConnected = true

View file

@ -241,8 +241,8 @@ proc pasv[T](ftp: FtpBase[T]) =
assertReply(pasvMsg, "227") assertReply(pasvMsg, "227")
var betweenParens = captureBetween(pasvMsg.string, '(', ')') var betweenParens = captureBetween(pasvMsg.string, '(', ')')
var nums = betweenParens.split(',') var nums = betweenParens.split(',')
var ip = nums[0.. -3] var ip = nums[0.. ^3]
var port = nums[-2.. -1] var port = nums[^2.. ^1]
var properPort = port[0].parseInt()*256+port[1].parseInt() var properPort = port[0].parseInt()*256+port[1].parseInt()
ftp.dsock.connect(ip.join("."), Port(properPort.toU16)) ftp.dsock.connect(ip.join("."), Port(properPort.toU16))
when T is AsyncSocket: when T is AsyncSocket:
@ -488,7 +488,7 @@ proc doUpload[T](ftp: FtpBase[T], async = false): bool =
if bytesSent == ftp.job.toStore.len: if bytesSent == ftp.job.toStore.len:
ftp.job.toStore = "" ftp.job.toStore = ""
elif bytesSent != ftp.job.toStore.len and bytesSent != 0: elif bytesSent != ftp.job.toStore.len and bytesSent != 0:
ftp.job.toStore = ftp.job.toStore[bytesSent .. -1] ftp.job.toStore = ftp.job.toStore[bytesSent .. ^1]
ftp.job.progress.inc(bytesSent) ftp.job.progress.inc(bytesSent)
ftp.job.oneSecond.inc(bytesSent) ftp.job.oneSecond.inc(bytesSent)
else: else:
@ -512,7 +512,7 @@ proc doUpload[T](ftp: FtpBase[T], async = false): bool =
if bytesSent == 0: if bytesSent == 0:
ftp.job.toStore.add(s) ftp.job.toStore.add(s)
elif bytesSent != s.len: elif bytesSent != s.len:
ftp.job.toStore.add(s[bytesSent .. -1]) ftp.job.toStore.add(s[bytesSent .. ^1])
len = bytesSent len = bytesSent
ftp.job.progress.inc(len) ftp.job.progress.inc(len)

View file

@ -227,7 +227,7 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
inc(linei, le) inc(linei, le)
# Status code # Status code
linei.inc skipWhitespace(line, linei) linei.inc skipWhitespace(line, linei)
result.status = line[linei .. -1] result.status = line[linei .. ^1]
parsedStatus = true parsedStatus = true
else: else:
# Parse headers # Parse headers
@ -238,7 +238,7 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
if line[linei] != ':': httpError("invalid headers") if line[linei] != ':': httpError("invalid headers")
inc(linei) # Skip : inc(linei) # Skip :
result.headers[name] = line[linei.. -1].strip() result.headers[name] = line[linei.. ^1].strip()
if not fullyRead: if not fullyRead:
httpError("Connection was closed before full request has been made") httpError("Connection was closed before full request has been made")
if getBody: if getBody:
@ -725,7 +725,7 @@ proc parseResponse(client: AsyncHttpClient,
inc(linei, le) inc(linei, le)
# Status code # Status code
linei.inc skipWhitespace(line, linei) linei.inc skipWhitespace(line, linei)
result.status = line[linei .. -1] result.status = line[linei .. ^1]
parsedStatus = true parsedStatus = true
else: else:
# Parse headers # Parse headers
@ -736,7 +736,7 @@ proc parseResponse(client: AsyncHttpClient,
if line[linei] != ':': httpError("invalid headers") if line[linei] != ':': httpError("invalid headers")
inc(linei) # Skip : inc(linei) # Skip :
result.headers[name] = line[linei.. -1].strip() result.headers[name] = line[linei.. ^1].strip()
if not fullyRead: if not fullyRead:
httpError("Connection was closed before full request has been made") httpError("Connection was closed before full request has been made")
if getBody: if getBody:

View file

@ -170,7 +170,7 @@ proc countFiles(filename: string): int =
if kind == pcFile: if kind == pcFile:
let llfn = name & ext & ExtSep let llfn = name & ext & ExtSep
if path.extractFilename.startsWith(llfn): if path.extractFilename.startsWith(llfn):
let numS = path.extractFilename[llfn.len .. -1] let numS = path.extractFilename[llfn.len .. ^1]
try: try:
let num = parseInt(numS) let num = parseInt(numS)
if num > result: if num > result:

View file

@ -2874,7 +2874,7 @@ when hostOS != "standalone":
## ##
## .. code-block:: nim ## .. code-block:: nim
## var s = "abcdef" ## var s = "abcdef"
## s[1 .. -2] = "xyz" ## s[1 .. ^2] = "xyz"
## assert s == "axyzf" ## assert s == "axyzf"
var a = x.a var a = x.a
var L = x.b - a + 1 var L = x.b - a + 1

View file

@ -7,6 +7,6 @@ discard """
proc test: string = proc test: string =
result = "blah" result = "blah"
result[1 .. -1] result[1 .. ^1]
echo test() echo test()

View file

@ -27,7 +27,7 @@ proc refExpr(exprNode: NimNode): string {.compileTime.} =
"expr" & $(exprNodes.len - 1) "expr" & $(exprNodes.len - 1)
proc derefExpr(exprRef: string): NimNode {.compileTime.} = proc derefExpr(exprRef: string): NimNode {.compileTime.} =
exprNodes[parseInt(exprRef[4 .. -1])] exprNodes[parseInt(exprRef[4 .. ^1])]
#=============================================================================== #===============================================================================
# Define a type that allows a callable expression to be mapped onto elements # Define a type that allows a callable expression to be mapped onto elements

View file

@ -36,7 +36,7 @@ echo()
var myseq = @[1, 2, 3, 4, 5, 6] var myseq = @[1, 2, 3, 4, 5, 6]
myseq[0..2] = myseq[-3.. -1] myseq[0..2] = myseq[^3 .. ^1]
for x in items(myseq): stdout.write(x) for x in items(myseq): stdout.write(x)
echo() echo()
@ -46,7 +46,7 @@ echo mystr
mystr[4..4] = "u" mystr[4..4] = "u"
# test full replacement # test full replacement
mystr[.. -2] = "egerichtet" mystr[.. ^2] = "egerichtet"
echo mystr echo mystr
@ -54,6 +54,6 @@ mystr[0..2] = "ve"
echo mystr echo mystr
var s = "abcdef" var s = "abcdef"
s[1 .. -2] = "xyz" s[1 .. ^2] = "xyz"
assert s == "axyzf" assert s == "axyzf"

View file

@ -205,7 +205,7 @@ proc findMainFile(dir: string): string =
var nimFiles = 0 var nimFiles = 0
for kind, file in os.walkDir(dir): for kind, file in os.walkDir(dir):
if kind == pcFile: if kind == pcFile:
if file.endsWith(cfgExt): return file[.. -(cfgExt.len+1)] & ".nim" if file.endsWith(cfgExt): return file[.. ^(cfgExt.len+1)] & ".nim"
elif file.endsWith(".nim"): elif file.endsWith(".nim"):
if result.len == 0: result = file if result.len == 0: result = file
inc nimFiles inc nimFiles

View file

@ -59,7 +59,7 @@ proc callCompiler(cmdTemplate, filename, options: string,
target: TTarget): TSpec = target: TTarget): TSpec =
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell]) "options", options, "file", filename.quoteShell])
var p = startProcess(command=c[0], args=c[1.. -1], var p = startProcess(command=c[0], args=c[1.. ^1],
options={poStdErrToStdOut, poUseShell}) options={poStdErrToStdOut, poUseShell})
let outp = p.outputStream let outp = p.outputStream
var suc = "" var suc = ""
@ -284,7 +284,7 @@ proc main() =
let testsDir = "tests" & DirSep let testsDir = "tests" & DirSep
for kind, dir in walkDir(testsDir): for kind, dir in walkDir(testsDir):
assert testsDir.startsWith(testsDir) assert testsDir.startsWith(testsDir)
let cat = dir[testsDir.len .. -1] let cat = dir[testsDir.len .. ^1]
if kind == pcDir and cat notin ["testament", "testdata", "nimcache"]: if kind == pcDir and cat notin ["testament", "testdata", "nimcache"]:
processCategory(r, Category(cat), p.cmdLineRest.string) processCategory(r, Category(cat), p.cmdLineRest.string)
for a in AdditionalCategories: for a in AdditionalCategories: