dmd.common.string

Common string functions including filename manipulation.

Authors

Walter Bright, https://www.digitalmars.com

Source: common/string.d

  • Declaration

    struct SmallBuffer(Element);

    Defines a temporary array of Elements 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.

    Discussion

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

    Examples

    ditto

    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

      scope this(size_t len, return scope Element[] buffer);

      Construct a SmallBuffer

      Parameters

      size_t len

      number of elements in array

      Element[] buffer

      slice to use as backing-store, if len will fit in it

    • Declaration

      scope void create(size_t len);

      Resize existing SmallBuffer.

      Parameters

      size_t len

      number of elements after resize

  • 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.

    Parameters

    C* stringz

    the C string to be converted

    Return Value

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

    Examples

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