Use ^ instead of - in slices
This commit is contained in:
parent
2b80d75aa2
commit
64903e7050
10 changed files with 93 additions and 93 deletions
|
|
@ -61,8 +61,8 @@ proc pasv(ftp: AsyncFtpClient) {.async.} =
|
|||
assertReply(pasvMsg, "227")
|
||||
var betweenParens = captureBetween(pasvMsg.string, '(', ')')
|
||||
var nums = betweenParens.split(',')
|
||||
var ip = nums[0.. -3]
|
||||
var port = nums[-2.. -1]
|
||||
var ip = nums[0.. ^3]
|
||||
var port = nums[^2.. ^1]
|
||||
var properPort = port[0].parseInt()*256+port[1].parseInt()
|
||||
await ftp.dsock.connect(ip.join("."), Port(properPort.toU16))
|
||||
ftp.dsockConnected = true
|
||||
|
|
|
|||
|
|
@ -241,8 +241,8 @@ proc pasv[T](ftp: FtpBase[T]) =
|
|||
assertReply(pasvMsg, "227")
|
||||
var betweenParens = captureBetween(pasvMsg.string, '(', ')')
|
||||
var nums = betweenParens.split(',')
|
||||
var ip = nums[0.. -3]
|
||||
var port = nums[-2.. -1]
|
||||
var ip = nums[0.. ^3]
|
||||
var port = nums[^2.. ^1]
|
||||
var properPort = port[0].parseInt()*256+port[1].parseInt()
|
||||
ftp.dsock.connect(ip.join("."), Port(properPort.toU16))
|
||||
when T is AsyncSocket:
|
||||
|
|
@ -488,7 +488,7 @@ proc doUpload[T](ftp: FtpBase[T], async = false): bool =
|
|||
if bytesSent == ftp.job.toStore.len:
|
||||
ftp.job.toStore = ""
|
||||
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.oneSecond.inc(bytesSent)
|
||||
else:
|
||||
|
|
@ -512,7 +512,7 @@ proc doUpload[T](ftp: FtpBase[T], async = false): bool =
|
|||
if bytesSent == 0:
|
||||
ftp.job.toStore.add(s)
|
||||
elif bytesSent != s.len:
|
||||
ftp.job.toStore.add(s[bytesSent .. -1])
|
||||
ftp.job.toStore.add(s[bytesSent .. ^1])
|
||||
len = bytesSent
|
||||
|
||||
ftp.job.progress.inc(len)
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
|
|||
inc(linei, le)
|
||||
# Status code
|
||||
linei.inc skipWhitespace(line, linei)
|
||||
result.status = line[linei .. -1]
|
||||
result.status = line[linei .. ^1]
|
||||
parsedStatus = true
|
||||
else:
|
||||
# Parse headers
|
||||
|
|
@ -238,7 +238,7 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
|
|||
if line[linei] != ':': httpError("invalid headers")
|
||||
inc(linei) # Skip :
|
||||
|
||||
result.headers[name] = line[linei.. -1].strip()
|
||||
result.headers[name] = line[linei.. ^1].strip()
|
||||
if not fullyRead:
|
||||
httpError("Connection was closed before full request has been made")
|
||||
if getBody:
|
||||
|
|
@ -725,7 +725,7 @@ proc parseResponse(client: AsyncHttpClient,
|
|||
inc(linei, le)
|
||||
# Status code
|
||||
linei.inc skipWhitespace(line, linei)
|
||||
result.status = line[linei .. -1]
|
||||
result.status = line[linei .. ^1]
|
||||
parsedStatus = true
|
||||
else:
|
||||
# Parse headers
|
||||
|
|
@ -736,7 +736,7 @@ proc parseResponse(client: AsyncHttpClient,
|
|||
if line[linei] != ':': httpError("invalid headers")
|
||||
inc(linei) # Skip :
|
||||
|
||||
result.headers[name] = line[linei.. -1].strip()
|
||||
result.headers[name] = line[linei.. ^1].strip()
|
||||
if not fullyRead:
|
||||
httpError("Connection was closed before full request has been made")
|
||||
if getBody:
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ proc countFiles(filename: string): int =
|
|||
if kind == pcFile:
|
||||
let llfn = name & ext & ExtSep
|
||||
if path.extractFilename.startsWith(llfn):
|
||||
let numS = path.extractFilename[llfn.len .. -1]
|
||||
let numS = path.extractFilename[llfn.len .. ^1]
|
||||
try:
|
||||
let num = parseInt(numS)
|
||||
if num > result:
|
||||
|
|
|
|||
|
|
@ -2874,7 +2874,7 @@ when hostOS != "standalone":
|
|||
##
|
||||
## .. code-block:: nim
|
||||
## var s = "abcdef"
|
||||
## s[1 .. -2] = "xyz"
|
||||
## s[1 .. ^2] = "xyz"
|
||||
## assert s == "axyzf"
|
||||
var a = x.a
|
||||
var L = x.b - a + 1
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ discard """
|
|||
|
||||
proc test: string =
|
||||
result = "blah"
|
||||
result[1 .. -1]
|
||||
result[1 .. ^1]
|
||||
|
||||
echo test()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ proc refExpr(exprNode: NimNode): string {.compileTime.} =
|
|||
"expr" & $(exprNodes.len - 1)
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ echo()
|
|||
|
||||
|
||||
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)
|
||||
echo()
|
||||
|
|
@ -46,7 +46,7 @@ echo mystr
|
|||
mystr[4..4] = "u"
|
||||
|
||||
# test full replacement
|
||||
mystr[.. -2] = "egerichtet"
|
||||
mystr[.. ^2] = "egerichtet"
|
||||
|
||||
echo mystr
|
||||
|
||||
|
|
@ -54,6 +54,6 @@ mystr[0..2] = "ve"
|
|||
echo mystr
|
||||
|
||||
var s = "abcdef"
|
||||
s[1 .. -2] = "xyz"
|
||||
s[1 .. ^2] = "xyz"
|
||||
assert s == "axyzf"
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ proc findMainFile(dir: string): string =
|
|||
var nimFiles = 0
|
||||
for kind, file in os.walkDir(dir):
|
||||
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"):
|
||||
if result.len == 0: result = file
|
||||
inc nimFiles
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ proc callCompiler(cmdTemplate, filename, options: string,
|
|||
target: TTarget): TSpec =
|
||||
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
|
||||
"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})
|
||||
let outp = p.outputStream
|
||||
var suc = ""
|
||||
|
|
@ -284,7 +284,7 @@ proc main() =
|
|||
let testsDir = "tests" & DirSep
|
||||
for kind, dir in walkDir(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"]:
|
||||
processCategory(r, Category(cat), p.cmdLineRest.string)
|
||||
for a in AdditionalCategories:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue