Open timotheecour opened 3 years ago
That was my idea on the original PR too, but got chopped off as usual. 🤷
the fact that there was so many review comments and commits in the PR (because of failing edge cases) played a role IMO in the closing of that PR.
But regardless, the feature is useful and (as you discovered yourself) is tricky to implement correctly, which makes it a great candidate for stdlib; we should address the concerns raised in the closing comments regarding API though.
My first commit was fast and easy to understand, ...then people requested to support whatever crossed their mind.
The problem is that adds more and more defensive programming, maybe there needs to be 2 modes, via another proc or overload or a static argument on 1 proc, a "strict" one thats efficient and tiny, and another that parses/formats any random potato into a float.
I'm not saying it's an easy problem; the API needs to satisfy both:
12,345.78
)12.345,78
)12,34,56,789.0
) is TBD
(refs https://forum.nim-lang.org/t/8162#52487)formatEng
, so it could make sense thereit should be additive (analog to addFloat), which is the most composable/efficient, can be used in conjunction with sugar.dup
type OptFloatFmt = object
sep: char ...
type OptFloatParse = object
sep: char ...
proc addFloatCustom*(result: var string, a: SomeFloat, opt = initOptFloatFmt())
proc parseCustom*(ret: var SomeFloat, s: openArray[char], opt = initOptFloatParse()): int
# returns nb of chars parsed in `s`
https://github.com/timotheecour/Nim/issues/741 could be used to define packed object (more efficient + syntax sugar) instead of OptFloatFmt, OptFloatParse
- which module? strutils already has
formatEng
, so it could make sense there
strmisc
says This module contains various string utility routines that are uncommonly used in comparison to the ones in strutils.
I should live there IMHO.
possibly
links
implementation
https://forum.nim-lang.org/t/8162#52480