• E
    virBuffer: add way to trim back extra text · cdb87b1c
    Eric Blake 提交于
    I'm tired of writing:
    
    bool sep = false;
    while (...) {
        if (sep)
           virBufferAddChar(buf, ',');
        sep = true;
        virBufferAdd(buf, str);
    }
    
    This makes it easier, allowing one to write:
    
    while (...)
        virBufferAsprintf(buf, "%s,", str);
    virBufferTrim(buf, ",", -1);
    
    to trim any remaining comma.
    
    * src/util/buf.h (virBufferTrim): Declare.
    * src/util/buf.c (virBufferTrim): New function.
    * tests/virbuftest.c (testBufTrim): Test it.
    cdb87b1c
buf.h 2.0 KB