On Sat, 28 Dec 2019 22:35:54 -0800, T <T...@invalid.invalid> wrote:
>Hi All,
>
>I have four different way of converting a Raku/Perl6 string
>into a C++ string to pass to native call. Three come out
The word string has two defined meanings in the C++ language. One is
the name of a type (std::string) defined in the Standard Template
Library. The other is an array of characters terminated by a 0 value
as defined in the C standard which is included in C++ by reference.
Which one do you mean?
What does "native call" mean? Is it to a C (or C++) function? What
does that function expect? Show us the prototype of the function.
>the same and one comes out with a 0x0000 (hex) at the end.
No they did not. The last three are significantly different from each
other.
>The "say" functions shows me each byte in the converted
>string. Which one is correct?
No, say did not show you that. It showed you its interpretation of
the argument you gave it. At the very least, it did not show you
seven bytes of data in the uint16 array.
Furthermore, none of the results is a std::string and only one of the
results is a C-style string.
>The following is "abcdefg" converted to a C string,
>"wstr", etc. is the method I used and is not part
>of the C string:
Something appears to be missing from this sentence. What is the
method you used? And what is not part of what?
>97 98 99 100 101 102 103 wstr
>97 98 99 100 101 102 103 0 to-c-str
This is a valid C-style string consisting of eight bytes/characters.
>97 98 99 100 101 102 103 CArray[uint8].new
This is an array of seven bytes/integers that may be considered
characters but it is not a string.
>97 98 99 100 101 102 103 CArray[uint16].new
This is an array of fourteen bytes (seven integers) that may be
considered wide characters but it is not a string.
>And why do I care if I am using "uint8" or "uint16"
>to convert visable text? What about the one
You care because the function you are calling may expect one or the
other (or possibly have code to let it determine which you provided
but that is unlikely).
>with the 0 at the end?
This is the only one that is a string. Whether that matters depends
on the function you are calling.
--
Remove del for email