TempCString

Temporary string buffer. It can be used to build temporary \0 ended C strings. For lengths < 255, it uses static char array, mallocated buffer otherwise.

NOTE: be careful that pointer becomes invalid as soon as the struct comes out of scope! NOTE: inspired by std.internal.cstring.TempCStringBuffer in Phobos library

Constructors

this
this()
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Alias This

ptr

Members

Functions

opIndex
const(C)[] opIndex()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

bufPtr
inout(C)* bufPtr [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
ptr
const(C)* ptr [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

import core.stdc.string : strlen;

string str = "abc";

// Intended usage
assert(strlen(str.tempCString()) == 3);

// Correct usage
auto tmp = str.tempCString();
assert(strlen(tmp) == 3); // or `tmp.ptr`, or `tmp.buffPtr`

// $(RED WARNING): $(RED Incorrect usage)
auto pInvalid1 = str.tempCString().ptr;
const char* pInvalid2 = str.tempCString();

Meta