jsony icon indicating copy to clipboard operation
jsony copied to clipboard

add support for cstring, seq[char] and openArray[char] as input string

Open gpicron opened this issue 2 years ago • 3 comments

gpicron avatar Apr 26 '23 09:04 gpicron

Although I would like to support cstring, seq[char] and openArray[char], I do feel like that it makes code and documentation more complex. I can't think of good cases where you would not have a string already or couldn't get one easily.

Do you have a good situation where this matters?

treeform avatar May 02 '23 01:05 treeform

non-mutable string parameter shouldn't even be allowed when openArray[char] exists

SolitudeSF avatar May 02 '23 07:05 SolitudeSF

Although I would like to support cstring, seq[char] and openArray[char], I do feel like that it makes code and documentation more complex. I can't think of good cases where you would not have a string already or couldn't get one easily.

Do you have a good situation where this matters?

cstring is convenient in JS backend has it avoid to convert the whole input to String (utf16 -> utf8) I found it also interesting when getting cstring from ffi linked libs yet in UTF8 (like sqlite). It avoid a copy of the whole cstring to nim string.

seq[char] and openArray[char] is coming from the fact I'm using a libsodium binding. after decryption I have either a seq[byte] or an openArray[byte]. Casting those to seq[char] or openArray[char] is safe when I know by the application that it is a utf8 sequence and avoid a copy to the Nim String. I don't think it is safe to cast a seq[byte] to nim string even if I see it in lot of libs because, up to my knowledge, there is no guaranty the underlying C structs will remain compatible.

gpicron avatar May 02 '23 10:05 gpicron