www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19259] New: std.array.Appender needs a way to set the length


          Issue ID: 19259
           Summary: std.array.Appender needs a way to set the length
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: johnnymarler gmail.com

std.array.Appender needs a way to extend/add to the length of `data`.  See the
following use case:

uint tryAppendFullPathNameImpl(const(wchar)* nullTerminatedPath,
Appender!(wchar[]) builder)
    import core.sys.windows.winbase : GetFullPathNameW;
    auto prefixLength = builder.data.length;
    for (;;)
        const result = GetFullPathNameW(nullTerminatedPath, builder.capacity -
            builder.data.ptr + prefixLength, null);
        if (result <= (builder.capacity - prefixLength))
            // NO WAY TO DO THIS:
            //builder.overrideDataLength(prefixLength + result);
            return result;
        builder.reserve(prefixLength + result);

What's happening here is we are passing the Appender array to a C function that
populates the array with our resuling "full path".  Note that this
implementation is taken from .NET CoreFX:


The problem is that once it's populated, we have no way of extending the length
of the array after it was populated by the C function.

Sep 22 2018