NativeBoost: Null-terminated Strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NativeBoost: Null-terminated Strings

Udo Schneider
All,

I just wrapped a few functions using NB - as easy as it used to be in
Dolphin! Really nice.

I'm stuck with a simple thing however. I'm passing a string buffer into
a function which fills this buffer (null-terminated String). The passed
in String however contains all the nulls as well (which is not
surprising). What's the "official" way to truncate the String to it's
correct length?

Best Regards,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: NativeBoost: Null-terminated Strings

Igor Stasenko
String pseudo type corresponds to
'const char *' type.. because it passes the string by copying it on stack and null terminating it there,
and then pushing the pointer (which on stack), as argument to function.
That means that original string is never modified, in your case function will modify a temporary
string on stack, and after call finished it will be lost.

If function takes pointer to write some data at given location, you can just pass a ByteArray instance
as a buffer to hold that string (so function will receive a pointer of first byte in it)..
and after it return, trim/convert it to ByteString.

 


On 20 August 2013 19:45, Udo Schneider <[hidden email]> wrote:
All,

I just wrapped a few functions using NB - as easy as it used to be in Dolphin! Really nice.

I'm stuck with a simple thing however. I'm passing a string buffer into a function which fills this buffer (null-terminated String). The passed in String however contains all the nulls as well (which is not surprising). What's the "official" way to truncate the String to it's correct length?

Best Regards,

Udo





--
Best regards,
Igor Stasenko.