Common string functions including filename manipulation.


Walter Bright,

Source: common/string.d

  • Declaration

    struct SmallBuffer(T);

    Defines a temporary array using a fixed-length buffer as back store. If the length of the buffer suffices, it is readily used. Otherwise, malloc is used to allocate memory for the array and free is used for deallocation in the destructor.


    This type is meant to use exclusively as an automatic variable. It is not default constructible or copyable.



    1. char[230] buf = void; auto a = SmallBuffer!char(10, buf); assert(a[] is buf[0 .. 10]); auto b = SmallBuffer!char(1000, buf); assert(b[] !is buf[]); b.create(1000); assert(b.length == 1000); assert(b[] !is buf[]);

  • Declaration

    pure nothrow @nogc auto asDString(C)(C* stringz);

    Converts a zero-terminated C string to a D slice. Takes linear time and allocates no memory.


    C* stringz

    the C string to be converted

    Return Value

    a slice comprehending the string. The terminating 0 is not part of the slice.


    1. const char* p = "123".ptr; assert(p.asDString == "123");