fixes more nil string bugs
This commit is contained in:
parent
b07d1f1dc3
commit
babd31360a
3 changed files with 10 additions and 8 deletions
|
|
@ -312,7 +312,6 @@ proc setIndexTerm*(d: var RstGenerator, id, term: string,
|
||||||
## The index won't be written to disk unless you call `writeIndexFile()
|
## The index won't be written to disk unless you call `writeIndexFile()
|
||||||
## <#writeIndexFile>`_. The purpose of the index is documented in the `docgen
|
## <#writeIndexFile>`_. The purpose of the index is documented in the `docgen
|
||||||
## tools guide <docgen.html#index-switch>`_.
|
## tools guide <docgen.html#index-switch>`_.
|
||||||
assert(not d.theIndex.isNil)
|
|
||||||
var
|
var
|
||||||
entry = term
|
entry = term
|
||||||
isTitle = false
|
isTitle = false
|
||||||
|
|
|
||||||
|
|
@ -1366,7 +1366,9 @@ proc find*(s: string, sub: char, start: Natural = 0, last: Natural = 0): int {.n
|
||||||
if sub == s[i]: return i
|
if sub == s[i]: return i
|
||||||
else:
|
else:
|
||||||
when hasCStringBuiltin:
|
when hasCStringBuiltin:
|
||||||
let found = c_memchr(s[start].unsafeAddr, sub, last-start+1)
|
let L = last-start+1
|
||||||
|
if L > 0:
|
||||||
|
let found = c_memchr(s[start].unsafeAddr, sub, L)
|
||||||
if not found.isNil:
|
if not found.isNil:
|
||||||
return cast[ByteAddress](found) -% cast[ByteAddress](s.cstring)
|
return cast[ByteAddress](found) -% cast[ByteAddress](s.cstring)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1515,7 +1517,7 @@ proc replace*(s, sub: string, by = ""): string {.noSideEffect,
|
||||||
elif subLen == 1:
|
elif subLen == 1:
|
||||||
# when the pattern is a single char, we use a faster
|
# when the pattern is a single char, we use a faster
|
||||||
# char-based search that doesn't need a skip table:
|
# char-based search that doesn't need a skip table:
|
||||||
var c = sub[0]
|
let c = sub[0]
|
||||||
let last = s.high
|
let last = s.high
|
||||||
var i = 0
|
var i = 0
|
||||||
while true:
|
while true:
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ proc nimToCStringConv(s: NimString): cstring {.compilerProc, inline.} =
|
||||||
else: result = cstring(addr s.data)
|
else: result = cstring(addr s.data)
|
||||||
|
|
||||||
proc copyStr(s: NimString, start: int): NimString {.compilerProc.} =
|
proc copyStr(s: NimString, start: int): NimString {.compilerProc.} =
|
||||||
|
if s == nil: return nil
|
||||||
result = copyStrLast(s, start, s.len-1)
|
result = copyStrLast(s, start, s.len-1)
|
||||||
|
|
||||||
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue