On Monday, 21 December 2015 at 09:46:58 UTC, Shriramana Sharma
wrote:
Jonathan M Davis via Digitalmars-d-learn wrote:
If it isn't, all that means is that the
array's capacity will be 0, so it's going to have to reallocate
So it's safe to return a string produced by fromStringz without
having
Jonathan M Davis via Digitalmars-d-learn wrote:
> If it isn't, all that means is that the
> array's capacity will be 0, so it's going to have to reallocate
So it's safe to return a string produced by fromStringz without having to
worry that the user would append to it?
Then why is it marked @sy
On Monday, 21 December 2015 at 08:35:22 UTC, Jonathan M Davis
wrote:
There's also fromStringz that Jakob suggests using elsewhere in
this thread, but that really just boils down to
return cString ? cString[0 .. strlen(cString)] : null;
So, using that over simply slicing is primarily for
d
On Monday, December 21, 2015 18:39:32 Rikki Cattermole via Digitalmars-d-learn
wrote:
> size_t strLen = ...;
> char* ptr = ...;
>
> string myCString = cast(string)ptr[0 .. strLen];
>
> I can't remember if it will include the null terminator or not, but if
> it does just decrease strLen by 1.
Cast
On Monday, December 21, 2015 05:43:59 Jakob Ovrum via Digitalmars-d-learn wrote:
> On Monday, 21 December 2015 at 05:41:31 UTC, Shriramana Sharma
> wrote:
> > Rikki Cattermole wrote:
> >
> >> string myCString = cast(string)ptr[0 .. strLen];
> >
> > Thanks but does this require that one doesn't atte
On Monday, 21 December 2015 at 06:00:45 UTC, Shriramana Sharma
wrote:
I suppose what you mean is, the onus of guaranteeing that
const(char)* refers to a null-terminated string is upon the
person calling the to! function? Yes I understand, and Phobos
documentation does say that using a pointer f
Jakob Ovrum wrote:
> Use std.string.fromStringz. to!string assumes that pointers to
> characters are null-terminated strings which is not safe or
> general
I suppose what you mean is, the onus of guaranteeing that const(char)*
refers to a null-terminated string is upon the person calling the to
On Monday, 21 December 2015 at 05:39:32 UTC, Rikki Cattermole
wrote:
size_t strLen = ...;
char* ptr = ...;
string myCString = cast(string)ptr[0 .. strLen];
I can't remember if it will include the null terminator or not,
but if it does just decrease strLen by 1.
Strings from C libraries shoul
On Monday, 21 December 2015 at 05:43:04 UTC, Rikki Cattermole
wrote:
On 21/12/15 6:41 PM, Shriramana Sharma wrote:
Rikki Cattermole wrote:
string myCString = cast(string)ptr[0 .. strLen];
Thanks but does this require that one doesn't attempt to
append to the
returned string using ~= or such
Rikki Cattermole wrote:
> string myCString = cast(string)ptr[0 .. strLen];
Thanks but does this require that one doesn't attempt to append to the
returned string using ~= or such? In which case it is not safe, right?
--
Shriramana Sharma, Penguin #395953
On 21/12/15 6:41 PM, Shriramana Sharma wrote:
Rikki Cattermole wrote:
string myCString = cast(string)ptr[0 .. strLen];
Thanks but does this require that one doesn't attempt to append to the
returned string using ~= or such? In which case it is not safe, right?
Correct, ~= should only be use
On Monday, 21 December 2015 at 05:41:31 UTC, Shriramana Sharma
wrote:
Rikki Cattermole wrote:
string myCString = cast(string)ptr[0 .. strLen];
Thanks but does this require that one doesn't attempt to append
to the returned string using ~= or such? In which case it is
not safe, right?
Grow
On Monday, 21 December 2015 at 05:34:07 UTC, Shriramana Sharma
wrote:
Hello. I have the following code:
import std.stdio, std.conv;
extern(C) const(char) * textAttrN(const (char) * specString,
size_t n);
string textAttr(const(char)[] specString)
{
const(char) * ptr = textAttrN(specString.p
On 21/12/15 6:34 PM, Shriramana Sharma wrote:
Hello. I have the following code:
import std.stdio, std.conv;
extern(C) const(char) * textAttrN(const (char) * specString, size_t n);
string textAttr(const(char)[] specString)
{
const(char) * ptr = textAttrN(specString.ptr, specString.length);
Hello. I have the following code:
import std.stdio, std.conv;
extern(C) const(char) * textAttrN(const (char) * specString, size_t n);
string textAttr(const(char)[] specString)
{
const(char) * ptr = textAttrN(specString.ptr, specString.length);
writeln(ptr);
return to!string(ptr);
}
voi
15 matches
Mail list logo