Browse Source Download (without any required ccan dependencies)

Module:

tal/str

Summary:

string helper routines which use tal

Author:

Rusty Russell <rusty@rustcorp.com.au>

Dependencies:

Description:

This is a grab bag of functions for string operations, designed to enhance the standard string.h; these are separated from the non-tal-needing string utilities in "str.h".

Example:

#include <ccan/tal/str/str.h>
#include <ccan/tal/grab_file/grab_file.h>
#include <err.h>

// Dumb demo program to double-linespace a file.
int main(int argc, char *argv[])
{
        char *textfile;
        char **lines;

        // Grab lines in file.
        textfile = grab_file(NULL, argv[1]);
        if (!textfile)
                err(1, "Failed reading %s", argv[1]);
        lines = tal_strsplit(textfile, textfile, "\n", STR_EMPTY_OK);

        // Join them back together with two linefeeds.
        printf("%s", tal_strjoin(textfile, lines, "\n\n", STR_TRAIL));

        // Free everything, just because we can.
        tal_free(textfile);
        return 0;
}

License:

BSD-MIT