fastjson
fastjson copied to clipboard
Add GetString function
Resolves #53
Convenience function so users don't have to do:
s := string(v.GetStringBytes("key", "a", "b"))
Codecov Report
Merging #54 into master will increase coverage by
0.01%. The diff coverage isn/a.
@@ Coverage Diff @@
## master #54 +/- ##
==========================================
+ Coverage 97.00% 97.01% +0.01%
==========================================
Files 9 9
Lines 1067 1072 +5
==========================================
+ Hits 1035 1040 +5
Misses 19 19
Partials 13 13
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 1649ca5...da55489. Read the comment docs.
Unfortunately this won't work as expected, since the returned string will contain garbage after the next call to Parser.Parse, since v.s is backed by byte slice, which is modified on each Parser.Parse call.
What do you suggest?
Either stick to string(v.GetStringBytes()) or use something unsafe like toUnsafeString(v.GetStringBytes()) if you know possible consequences of improper usage of the returned unsafe string.
What if GetString returned string(v.GetStringBytes())?
string(v.GetStringBytes()) will do a memory copy.
I think add "GetString" is not a good idea, we shall keep GetStringBytes and let users choose use b2s() or string() in their usecases.