Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfactor and fix the 5 different (buggy) re-implementations of cmpIgnoreStyle #472

Closed
timotheecour opened this issue Dec 18, 2020 · 5 comments
Labels
bug Something isn't working cleanups stdlib

Comments

@timotheecour
Copy link
Owner

timotheecour commented Dec 18, 2020

the ones that are actually intended to be case insensitive should be renamed to something else, or cmpIgnoreStyle can get an extra param caseInsensitive = false

links

nim-lang#16391
nim-lang#16392

@ringabout
Copy link
Collaborator

I already plan to refactor them and place them in std/private/str*. Use templates so that make cstrutils support JS backend.

@timotheecour
Copy link
Owner Author

timotheecour commented Dec 19, 2020

@xflywind
cool!

Use templates so that make cstrutils support JS backend.

can be discussed in your PR, but here's how to get best of both worlds:

  • avoid code bloat (C optimizer is free to either inline or keep as separate proc)
  • keep implementation DRY
  • works in js, vm, c:
# proc fn[T: openArray[char] or cstring](a: T) = # nim BUG: this doesn't work

template fnImpl(a): untyped =
  # xxx: actual impl goes here
  for ai in a: echo (ai,)

proc fn(a: openArray[char]) = fnImpl(a)
proc fn(a: cstring) = fnImpl(a)
proc fn(a: string) = fnImpl(a)

proc main()=
  fn("abc")
  var b = "abc".cstring
  fn(b)
  fn(['a','b'])

main()
static: main()

@ringabout
Copy link
Collaborator

I won't consider VM backend in this PR too much.
I could clean up this in the next PR(cstrutils doesn't support VM currently. It needs more cares to make it work).

@ringabout
Copy link
Collaborator

Maybe we also need cmpNimIdentifier.

@ringabout
Copy link
Collaborator

ringabout commented Jan 1, 2021

  • Refactor startsWith and endsWith
  • Make cstrutils support VM
  • Write more functions to cstrutils
  • Add strutils.cmpNimIdentifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cleanups stdlib
Projects
None yet
Development

No branches or pull requests

2 participants