Karax: prepare for the Nim release where 'nil' is not a thing for strings anymore
This commit is contained in:
parent
52026d1687
commit
b05c037bb0
2 changed files with 11 additions and 10 deletions
|
|
@ -208,7 +208,7 @@ template markDirty*(c: VComponent) =
|
|||
inc c.version
|
||||
|
||||
proc setAttr*(n: VNode; key: kstring; val: kstring = "") =
|
||||
if n.attrs.isNil:
|
||||
if n.attrs.len == 0:
|
||||
n.attrs = @[key, val]
|
||||
else:
|
||||
for i in countup(0, n.attrs.len-2, 2):
|
||||
|
|
@ -291,7 +291,7 @@ proc addEventListener*(n: VNode; event: EventKind; handler: EventHandler) =
|
|||
n.events.add((event, handler, nil))
|
||||
|
||||
template toStringAttr(field) =
|
||||
if n.field != nil:
|
||||
if n.field.len > 0:
|
||||
result.add " " & astToStr(field) & " = " & $n.field
|
||||
|
||||
proc toString*(n: VNode; result: var string; indent: int) =
|
||||
|
|
@ -306,7 +306,7 @@ proc toString*(n: VNode; result: var string; indent: int) =
|
|||
if n.kind == VNodeKind.text:
|
||||
result.add n.text
|
||||
else:
|
||||
if n.text != nil:
|
||||
if n.text.len > 0:
|
||||
result.add " value = "
|
||||
result.add n.text
|
||||
for child in items(n):
|
||||
|
|
@ -379,11 +379,11 @@ proc add*(result: var string, n: VNode, indent = 0, indWidth = 2) =
|
|||
let kind = $n.kind
|
||||
result.add('<')
|
||||
result.add(kind)
|
||||
if n.id != nil:
|
||||
if n.id.len > 0:
|
||||
result.add " id=\""
|
||||
result.addEscapedAttr(n.id)
|
||||
result.add('"')
|
||||
if n.class != nil:
|
||||
if n.class.len > 0:
|
||||
result.add " class=\""
|
||||
result.addEscapedAttr(n.class)
|
||||
result.add('"')
|
||||
|
|
|
|||
|
|
@ -241,8 +241,8 @@ proc setAttr(s: VStyle; a, value: kstring) {.noSideEffect.} =
|
|||
s[i+1] = value
|
||||
return
|
||||
elif s[i] > a:
|
||||
s.add nil
|
||||
s.add nil
|
||||
s.add ""
|
||||
s.add ""
|
||||
# insertion point here:
|
||||
for j in countdown(s.len-1, i, 2):
|
||||
s[j] = s[j-2]
|
||||
|
|
@ -255,18 +255,19 @@ proc setAttr(s: VStyle; a, value: kstring) {.noSideEffect.} =
|
|||
s.add value
|
||||
|
||||
proc setAttr*(s: VStyle; attr: StyleAttr, value: kstring) {.noSideEffect.} =
|
||||
assert value != nil, "value must not be nil"
|
||||
when kstring is cstring:
|
||||
assert value != nil, "value must not be nil"
|
||||
setAttr(s, toStyleAttrName[attr], value)
|
||||
|
||||
proc getAttr*(s: VStyle; attr: StyleAttr): kstring {.noSideEffect.} =
|
||||
## returns 'nil' if the attribute has not been set.
|
||||
## returns "" if the attribute has not been set.
|
||||
var i = 0
|
||||
let a = toStyleAttrName[attr]
|
||||
while i < s.len:
|
||||
if s[i] == a:
|
||||
return s[i+1]
|
||||
elif s[i] > a:
|
||||
return nil
|
||||
return ""
|
||||
inc i, 2
|
||||
|
||||
proc style*(pairs: varargs[(StyleAttr, kstring)]): VStyle {.noSideEffect.} =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue