added another version of eqIdent
This commit is contained in:
parent
e101773d8b
commit
97129ebd8a
1 changed files with 17 additions and 1 deletions
|
|
@ -818,6 +818,8 @@ proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} =
|
||||||
else: result = c
|
else: result = c
|
||||||
var i = 0
|
var i = 0
|
||||||
var j = 0
|
var j = 0
|
||||||
|
# first char is case sensitive
|
||||||
|
if a[0] != b[0]: return 1
|
||||||
while true:
|
while true:
|
||||||
while a[i] == '_': inc(i)
|
while a[i] == '_': inc(i)
|
||||||
while b[j] == '_': inc(j) # BUGFIX: typo
|
while b[j] == '_': inc(j) # BUGFIX: typo
|
||||||
|
|
@ -828,9 +830,23 @@ proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} =
|
||||||
inc(i)
|
inc(i)
|
||||||
inc(j)
|
inc(j)
|
||||||
|
|
||||||
proc eqIdent* (a, b: string): bool = cmpIgnoreStyle(a, b) == 0
|
proc eqIdent*(a, b: string): bool = cmpIgnoreStyle(a, b) == 0
|
||||||
## Check if two idents are identical.
|
## Check if two idents are identical.
|
||||||
|
|
||||||
|
proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} =
|
||||||
|
## Check if node is some identifier node (``nnkIdent``, ``nnkSym``, etc.)
|
||||||
|
## is the same as ``s``. Note that this is the preferred way to check! Most
|
||||||
|
## other ways like ``node.ident`` are much more error-prone, unfortunately.
|
||||||
|
case node.kind
|
||||||
|
of nnkIdent:
|
||||||
|
result = node.ident == !s
|
||||||
|
of nnkSym:
|
||||||
|
result = eqIdent($node.symbol, s)
|
||||||
|
of nnkOpenSymChoice, nnkClosedSymChoice:
|
||||||
|
result = eqIdent($node[0], s)
|
||||||
|
else:
|
||||||
|
result = false
|
||||||
|
|
||||||
proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}=
|
proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}=
|
||||||
## Search nnkFormalParams for an argument.
|
## Search nnkFormalParams for an argument.
|
||||||
assert params.kind == nnkFormalParams
|
assert params.kind == nnkFormalParams
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue