case consistency: next steps
This commit is contained in:
parent
1101a40f91
commit
438703f59e
77 changed files with 513 additions and 514 deletions
|
|
@ -645,7 +645,7 @@ proc hasKey*(node: PJsonNode, key: string): bool =
|
|||
## Checks if `key` exists in `node`.
|
||||
assert(node.kind == JObject)
|
||||
for k, item in items(node.fields):
|
||||
if k == key: return True
|
||||
if k == key: return true
|
||||
proc existsKey*(node: PJsonNode, key: string): bool {.deprecated.} = node.hasKey(key)
|
||||
## Deprecated for `hasKey`
|
||||
|
||||
|
|
@ -730,8 +730,8 @@ proc escapeJson*(s: string): string =
|
|||
result.add(toHex(r, 4))
|
||||
result.add("\"")
|
||||
|
||||
proc toPretty(result: var string, node: PJsonNode, indent = 2, ml = True,
|
||||
lstArr = False, currIndent = 0) =
|
||||
proc toPretty(result: var string, node: PJsonNode, indent = 2, ml = true,
|
||||
lstArr = false, currIndent = 0) =
|
||||
case node.kind
|
||||
of JObject:
|
||||
if currIndent != 0 and not lstArr: result.nl(ml)
|
||||
|
|
@ -747,7 +747,7 @@ proc toPretty(result: var string, node: PJsonNode, indent = 2, ml = True,
|
|||
result.indent(newIndent(currIndent, indent, ml))
|
||||
result.add(escapeJson(node.fields[i].key))
|
||||
result.add(": ")
|
||||
toPretty(result, node.fields[i].val, indent, ml, False,
|
||||
toPretty(result, node.fields[i].val, indent, ml, false,
|
||||
newIndent(currIndent, indent, ml))
|
||||
result.nl(ml)
|
||||
result.indent(currIndent) # indent the same as {
|
||||
|
|
@ -776,7 +776,7 @@ proc toPretty(result: var string, node: PJsonNode, indent = 2, ml = True,
|
|||
result.add(", ")
|
||||
result.nl(ml) # New Line
|
||||
toPretty(result, node.elems[i], indent, ml,
|
||||
True, newIndent(currIndent, indent, ml))
|
||||
true, newIndent(currIndent, indent, ml))
|
||||
result.nl(ml)
|
||||
result.indent(currIndent)
|
||||
result.add("]")
|
||||
|
|
@ -794,7 +794,7 @@ proc pretty*(node: PJsonNode, indent = 2): string =
|
|||
proc `$`*(node: PJsonNode): string =
|
||||
## Converts `node` to its JSON Representation on one line.
|
||||
result = ""
|
||||
toPretty(result, node, 1, False)
|
||||
toPretty(result, node, 1, false)
|
||||
|
||||
iterator items*(node: PJsonNode): PJsonNode =
|
||||
## Iterator for the items of `node`. `node` has to be a JArray.
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ proc fillBuffer(L: var TBaseLexer) =
|
|||
oldBufLen = L.BufLen
|
||||
L.bufLen = L.BufLen * 2
|
||||
L.buf = cast[cstring](realloc(L.buf, L.bufLen * chrSize))
|
||||
assert(L.bufLen - oldBuflen == oldBufLen)
|
||||
assert(L.bufLen - oldBufLen == oldBufLen)
|
||||
charsRead = readData(L.input, addr(L.buf[oldBufLen]),
|
||||
oldBufLen * chrSize) div chrSize
|
||||
if charsRead < oldBufLen:
|
||||
|
|
|
|||
|
|
@ -95,8 +95,8 @@ elif defined(macos):
|
|||
const
|
||||
CurDir* = ':'
|
||||
ParDir* = "::"
|
||||
Dirsep* = ':'
|
||||
Altsep* = Dirsep
|
||||
DirSep* = ':'
|
||||
AltSep* = Dirsep
|
||||
PathSep* = ','
|
||||
FileSystemCaseSensitive* = false
|
||||
ExeExt* = ""
|
||||
|
|
@ -123,10 +123,10 @@ elif defined(macos):
|
|||
# grandparent etc.
|
||||
elif doslike:
|
||||
const
|
||||
Curdir* = '.'
|
||||
Pardir* = ".."
|
||||
Dirsep* = '\\' # seperator within paths
|
||||
Altsep* = '/'
|
||||
CurDir* = '.'
|
||||
ParDir* = ".."
|
||||
DirSep* = '\\' # seperator within paths
|
||||
AltSep* = '/'
|
||||
PathSep* = ';' # seperator between paths
|
||||
FileSystemCaseSensitive* = false
|
||||
ExeExt* = "exe"
|
||||
|
|
@ -134,19 +134,19 @@ elif doslike:
|
|||
DynlibFormat* = "$1.dll"
|
||||
elif defined(PalmOS) or defined(MorphOS):
|
||||
const
|
||||
Dirsep* = '/'
|
||||
Altsep* = Dirsep
|
||||
DirSep* = '/'
|
||||
AltSep* = Dirsep
|
||||
PathSep* = ';'
|
||||
Pardir* = ".."
|
||||
ParDir* = ".."
|
||||
FileSystemCaseSensitive* = false
|
||||
ExeExt* = ""
|
||||
ScriptExt* = ""
|
||||
DynlibFormat* = "$1.prc"
|
||||
elif defined(RISCOS):
|
||||
const
|
||||
Dirsep* = '.'
|
||||
Altsep* = '.'
|
||||
Pardir* = ".." # is this correct?
|
||||
DirSep* = '.'
|
||||
AltSep* = '.'
|
||||
ParDir* = ".." # is this correct?
|
||||
PathSep* = ','
|
||||
FileSystemCaseSensitive* = true
|
||||
ExeExt* = ""
|
||||
|
|
@ -154,10 +154,10 @@ elif defined(RISCOS):
|
|||
DynlibFormat* = "lib$1.so"
|
||||
else: # UNIX-like operating system
|
||||
const
|
||||
Curdir* = '.'
|
||||
Pardir* = ".."
|
||||
Dirsep* = '/'
|
||||
Altsep* = Dirsep
|
||||
CurDir* = '.'
|
||||
ParDir* = ".."
|
||||
DirSep* = '/'
|
||||
AltSep* = Dirsep
|
||||
PathSep* = ':'
|
||||
FileSystemCaseSensitive* = true
|
||||
ExeExt* = ""
|
||||
|
|
@ -308,7 +308,7 @@ proc unixToNativePath*(path: string): string {.
|
|||
start = 1
|
||||
elif path[0] == '.' and path[1] == '/':
|
||||
# current directory
|
||||
result = $Curdir
|
||||
result = $CurDir
|
||||
start = 2
|
||||
else:
|
||||
result = ""
|
||||
|
|
@ -538,7 +538,7 @@ proc splitPath*(path: string): tuple[head, tail: string] {.
|
|||
## splitPath("") -> ("", "")
|
||||
var sepPos = -1
|
||||
for i in countdown(len(path)-1, 0):
|
||||
if path[i] in {Dirsep, Altsep}:
|
||||
if path[i] in {DirSep, AltSep}:
|
||||
sepPos = i
|
||||
break
|
||||
if sepPos >= 0:
|
||||
|
|
@ -550,9 +550,9 @@ proc splitPath*(path: string): tuple[head, tail: string] {.
|
|||
|
||||
proc parentDirPos(path: string): int =
|
||||
var q = 1
|
||||
if path[len(path)-1] in {Dirsep, Altsep}: q = 2
|
||||
if path[len(path)-1] in {DirSep, AltSep}: q = 2
|
||||
for i in countdown(len(path)-q, 0):
|
||||
if path[i] in {Dirsep, Altsep}: return i
|
||||
if path[i] in {DirSep, AltSep}: return i
|
||||
result = -1
|
||||
|
||||
proc parentDir*(path: string): string {.
|
||||
|
|
@ -593,8 +593,8 @@ iterator parentDirs*(path: string, fromRoot=false, inclusive=true): string =
|
|||
else:
|
||||
for i in countup(0, path.len - 2): # ignore the last /
|
||||
# deal with non-normalized paths such as /foo//bar//baz
|
||||
if path[i] in {Dirsep, Altsep} and
|
||||
(i == 0 or path[i-1] notin {Dirsep, Altsep}):
|
||||
if path[i] in {DirSep, AltSep} and
|
||||
(i == 0 or path[i-1] notin {DirSep, AltSep}):
|
||||
yield path.substr(0, i)
|
||||
|
||||
if inclusive: yield path
|
||||
|
|
@ -619,7 +619,7 @@ proc searchExtPos(s: string): int =
|
|||
if s[i] == ExtSep:
|
||||
result = i
|
||||
break
|
||||
elif s[i] in {Dirsep, Altsep}:
|
||||
elif s[i] in {DirSep, AltSep}:
|
||||
break # do not skip over path
|
||||
|
||||
proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
||||
|
|
@ -639,7 +639,7 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
|||
## If `path` has no extension, `ext` is the empty string.
|
||||
## If `path` has no directory component, `dir` is the empty string.
|
||||
## If `path` has no filename component, `name` and `ext` are empty strings.
|
||||
if path.len == 0 or path[path.len-1] in {DirSep, Altsep}:
|
||||
if path.len == 0 or path[path.len-1] in {DirSep, AltSep}:
|
||||
result = (path, "", "")
|
||||
else:
|
||||
var sepPos = -1
|
||||
|
|
@ -647,8 +647,8 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
|||
for i in countdown(len(path)-1, 0):
|
||||
if path[i] == ExtSep:
|
||||
if dotPos == path.len and i > 0 and
|
||||
path[i-1] notin {Dirsep, Altsep}: dotPos = i
|
||||
elif path[i] in {Dirsep, Altsep}:
|
||||
path[i-1] notin {DirSep, AltSep}: dotPos = i
|
||||
elif path[i] in {DirSep, AltSep}:
|
||||
sepPos = i
|
||||
break
|
||||
result.dir = substr(path, 0, sepPos-1)
|
||||
|
|
@ -659,7 +659,7 @@ proc extractFilename*(path: string): string {.
|
|||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Extracts the filename of a given `path`. This is the same as
|
||||
## ``name & ext`` from ``splitFile(path)``.
|
||||
if path.len == 0 or path[path.len-1] in {DirSep, Altsep}:
|
||||
if path.len == 0 or path[path.len-1] in {DirSep, AltSep}:
|
||||
result = ""
|
||||
else:
|
||||
result = splitPath(path).tail
|
||||
|
|
@ -814,11 +814,11 @@ proc sameFileContent*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
|||
if not open(b, path2):
|
||||
close(a)
|
||||
return false
|
||||
var bufA = alloc(bufsize)
|
||||
var bufB = alloc(bufsize)
|
||||
var bufA = alloc(bufSize)
|
||||
var bufB = alloc(bufSize)
|
||||
while true:
|
||||
var readA = readBuffer(a, bufA, bufsize)
|
||||
var readB = readBuffer(b, bufB, bufsize)
|
||||
var readA = readBuffer(a, bufA, bufSize)
|
||||
var readB = readBuffer(b, bufB, bufSize)
|
||||
if readA != readB:
|
||||
result = false
|
||||
break
|
||||
|
|
@ -1159,7 +1159,7 @@ iterator walkFiles*(pattern: string): string {.tags: [FReadDir].} =
|
|||
while true:
|
||||
if not skipFindData(f):
|
||||
yield splitFile(pattern).dir / extractFilename(getFilename(f))
|
||||
if findnextFile(res, f) == 0'i32: break
|
||||
if findNextFile(res, f) == 0'i32: break
|
||||
findClose(res)
|
||||
else: # here we use glob
|
||||
var
|
||||
|
|
@ -1214,7 +1214,7 @@ iterator walkDir*(dir: string): tuple[kind: TPathComponent, path: string] {.
|
|||
if (f.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) != 0'i32:
|
||||
k = pcDir
|
||||
yield (k, dir / extractFilename(getFilename(f)))
|
||||
if findnextFile(h, f) == 0'i32: break
|
||||
if findNextFile(h, f) == 0'i32: break
|
||||
findClose(h)
|
||||
else:
|
||||
var d = openDir(dir)
|
||||
|
|
@ -1308,7 +1308,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
|||
when defined(doslike):
|
||||
omitNext = isAbsolute(dir)
|
||||
for i in 1.. dir.len-1:
|
||||
if dir[i] in {Dirsep, Altsep}:
|
||||
if dir[i] in {DirSep, AltSep}:
|
||||
if omitNext:
|
||||
omitNext = false
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ when defined(Windows) and not defined(useNimRtl):
|
|||
|
||||
proc startProcess(command: string,
|
||||
workingDir: string = "",
|
||||
args: openarray[string] = [],
|
||||
args: openArray[string] = [],
|
||||
env: PStringTable = nil,
|
||||
options: set[TProcessOption] = {poStdErrToStdOut}): PProcess =
|
||||
var
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ proc next*(p: var TOptParser) {.
|
|||
of '-':
|
||||
inc(i)
|
||||
if p.cmd[i] == '-':
|
||||
p.kind = cmdLongOption
|
||||
p.kind = cmdLongoption
|
||||
inc(i)
|
||||
i = parseWord(p.cmd, i, p.key.string, {'\0', ' ', '\x09', ':', '='})
|
||||
while p.cmd[i] in {'\x09', ' '}: inc(i)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
when hostos == "solaris":
|
||||
when hostOS == "solaris":
|
||||
{.passl: "-lsocket -lnsl".}
|
||||
|
||||
import os, parseutils
|
||||
|
|
@ -467,7 +467,7 @@ template acceptAddrPlain(noClientRet, successRet: expr,
|
|||
sslImplementation: stmt): stmt {.immediate.} =
|
||||
assert(client != nil)
|
||||
var sockAddress: Tsockaddr_in
|
||||
var addrLen = sizeof(sockAddress).Tsocklen
|
||||
var addrLen = sizeof(sockAddress).TSockLen
|
||||
var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
|
||||
addr(addrLen))
|
||||
|
||||
|
|
@ -1258,10 +1258,10 @@ proc recvLine*(socket: TSocket, line: var TaintedString, timeout = -1): bool {.
|
|||
if n > 0 and c == '\L':
|
||||
discard recv(socket, addr(c), 1)
|
||||
elif n <= 0: return false
|
||||
addNlIfEmpty()
|
||||
addNLIfEmpty()
|
||||
return true
|
||||
elif c == '\L':
|
||||
addNlIfEmpty()
|
||||
addNLIfEmpty()
|
||||
return true
|
||||
add(line.string, c)
|
||||
|
||||
|
|
@ -1299,10 +1299,10 @@ proc readLine*(socket: TSocket, line: var TaintedString, timeout = -1) {.
|
|||
if n > 0 and c == '\L':
|
||||
discard recv(socket, addr(c), 1)
|
||||
elif n <= 0: osError(osLastError())
|
||||
addNlIfEmpty()
|
||||
addNLIfEmpty()
|
||||
return
|
||||
elif c == '\L':
|
||||
addNlIfEmpty()
|
||||
addNLIfEmpty()
|
||||
return
|
||||
add(line.string, c)
|
||||
|
||||
|
|
@ -1457,7 +1457,7 @@ proc recvAsync*(socket: TSocket, s: var TaintedString): bool {.
|
|||
let err = osLastError()
|
||||
when defined(windows):
|
||||
if err.int32 == WSAEWOULDBLOCK:
|
||||
return False
|
||||
return false
|
||||
else: osError(err)
|
||||
else:
|
||||
if err.int32 == EAGAIN or err.int32 == EWOULDBLOCK:
|
||||
|
|
@ -1469,7 +1469,7 @@ proc recvAsync*(socket: TSocket, s: var TaintedString): bool {.
|
|||
# increase capacity:
|
||||
setLen(s.string, s.string.len + bufSize)
|
||||
inc(pos, bytesRead)
|
||||
result = True
|
||||
result = true
|
||||
|
||||
proc recvFrom*(socket: TSocket, data: var string, length: int,
|
||||
address: var string, port: var TPort, flags = 0'i32): int {.
|
||||
|
|
@ -1510,7 +1510,7 @@ proc recvFromAsync*(socket: TSocket, data: var string, length: int,
|
|||
let err = osLastError()
|
||||
when defined(windows):
|
||||
if err.int32 == WSAEWOULDBLOCK:
|
||||
return False
|
||||
return false
|
||||
else: osError(err)
|
||||
else:
|
||||
if err.int32 == EAGAIN or err.int32 == EWOULDBLOCK:
|
||||
|
|
@ -1710,6 +1710,6 @@ proc isBlocking*(socket: TSocket): bool = not socket.nonblocking
|
|||
|
||||
when defined(Windows):
|
||||
var wsa: TWSAData
|
||||
if WSAStartup(0x0101'i16, addr wsa) != 0: osError(osLastError())
|
||||
if wsaStartup(0x0101'i16, addr wsa) != 0: osError(osLastError())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ iterator split*(s: string, seps: set[char] = Whitespace): string =
|
|||
while last < len(s):
|
||||
while s[last] in seps: inc(last)
|
||||
var first = last
|
||||
while last < len(s) and s[last] not_in seps: inc(last) # BUGFIX!
|
||||
while last < len(s) and s[last] notin seps: inc(last) # BUGFIX!
|
||||
if first <= last-1:
|
||||
yield substr(s, first, last-1)
|
||||
|
||||
|
|
|
|||
|
|
@ -1115,10 +1115,10 @@ proc toLower*(c: TRune): TRune {.rtl, extern: "nuc$1", procvar.} =
|
|||
## Converts `c` into lower case. This works for any Unicode character.
|
||||
## If possible, prefer `toLower` over `toUpper`.
|
||||
var c = IRune(c)
|
||||
var p = binarySearch(c, tolowerRanges, len(toLowerRanges) div 3, 3)
|
||||
var p = binarySearch(c, tolowerRanges, len(tolowerRanges) div 3, 3)
|
||||
if p >= 0 and c >= tolowerRanges[p] and c <= tolowerRanges[p+1]:
|
||||
return TRune(c + tolowerRanges[p+2] - 500)
|
||||
p = binarySearch(c, toLowerSinglets, len(toLowerSinglets) div 2, 2)
|
||||
p = binarySearch(c, tolowerSinglets, len(tolowerSinglets) div 2, 2)
|
||||
if p >= 0 and c == tolowerSinglets[p]:
|
||||
return TRune(c + tolowerSinglets[p+1] - 500)
|
||||
return TRune(c)
|
||||
|
|
@ -1127,10 +1127,10 @@ proc toUpper*(c: TRune): TRune {.rtl, extern: "nuc$1", procvar.} =
|
|||
## Converts `c` into upper case. This works for any Unicode character.
|
||||
## If possible, prefer `toLower` over `toUpper`.
|
||||
var c = IRune(c)
|
||||
var p = binarySearch(c, toUpperRanges, len(toUpperRanges) div 3, 3)
|
||||
var p = binarySearch(c, toupperRanges, len(toupperRanges) div 3, 3)
|
||||
if p >= 0 and c >= toupperRanges[p] and c <= toupperRanges[p+1]:
|
||||
return TRune(c + toupperRanges[p+2] - 500)
|
||||
p = binarySearch(c, toUpperSinglets, len(toUpperSinglets) div 2, 2)
|
||||
p = binarySearch(c, toupperSinglets, len(toupperSinglets) div 2, 2)
|
||||
if p >= 0 and c == toupperSinglets[p]:
|
||||
return TRune(c + toupperSinglets[p+1] - 500)
|
||||
return TRune(c)
|
||||
|
|
@ -1147,10 +1147,10 @@ proc isLower*(c: TRune): bool {.rtl, extern: "nuc$1", procvar.} =
|
|||
## If possible, prefer `isLower` over `isUpper`.
|
||||
var c = IRune(c)
|
||||
# Note: toUpperRanges is correct here!
|
||||
var p = binarySearch(c, toUpperRanges, len(toUpperRanges) div 3, 3)
|
||||
var p = binarySearch(c, toupperRanges, len(toupperRanges) div 3, 3)
|
||||
if p >= 0 and c >= toupperRanges[p] and c <= toupperRanges[p+1]:
|
||||
return true
|
||||
p = binarySearch(c, toUpperSinglets, len(toUpperSinglets) div 2, 2)
|
||||
p = binarySearch(c, toupperSinglets, len(toupperSinglets) div 2, 2)
|
||||
if p >= 0 and c == toupperSinglets[p]:
|
||||
return true
|
||||
|
||||
|
|
@ -1159,10 +1159,10 @@ proc isUpper*(c: TRune): bool {.rtl, extern: "nuc$1", procvar.} =
|
|||
## If possible, prefer `isLower` over `isUpper`.
|
||||
var c = IRune(c)
|
||||
# Note: toLowerRanges is correct here!
|
||||
var p = binarySearch(c, toLowerRanges, len(toLowerRanges) div 3, 3)
|
||||
var p = binarySearch(c, tolowerRanges, len(tolowerRanges) div 3, 3)
|
||||
if p >= 0 and c >= tolowerRanges[p] and c <= tolowerRanges[p+1]:
|
||||
return true
|
||||
p = binarySearch(c, toLowerSinglets, len(toLowerSinglets) div 2, 2)
|
||||
p = binarySearch(c, tolowerSinglets, len(tolowerSinglets) div 2, 2)
|
||||
if p >= 0 and c == tolowerSinglets[p]:
|
||||
return true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue