Re: [PATCH] Strbuf documentation: document most functions

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: René Scharfe
Date: Tuesday, June 3, 2008 - 8:41 am

Miklos Vajna schrieb:

It can be used to expand a format string containing placeholders.  To
that end, it parses the string and calls the specified function for
every percent sign found.

The callback function is given a pointer to the character after the '%'
and a pointer to the struct strbuf.  It is expected to add the expanded
version of the placeholder to the strbuf, e.g. to add a newline
character if the letter 'n' appears after a '%'.  The function returns
the length of the placeholder recognized and strbuf_expand skips over it.

All other characters (non-percent and not skipped ones) are copied
verbatim to the strbuf.  If the callback returned zero, meaning that the
placeholder is unknown, then the percent sign is copied, too.

In order to facilitate caching and to make it possible to give
parameters to the callback, strbuf_expand passes a context pointer,
which can be used by the programmer of the callback as she sees fit.

You can see it in action in pretty.c, where it expands --pretty=format:
placeholder strings.  The callback may be a bit heavy for a first
encounter, though. ;-)

René
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Strbuf documentation: document most functions, Miklos Vajna, (Mon Jun 2, 3:59 pm)
Re: [PATCH] Strbuf documentation: document most functions, Junio C Hamano, (Mon Jun 2, 4:39 pm)
Re: [PATCH] Strbuf documentation: document most functions, Johannes Schindelin, (Mon Jun 2, 5:00 pm)
Re: [PATCH] Strbuf documentation: document most functions, Pierre Habouzit, (Tue Jun 3, 1:42 am)
Re: [PATCH] Strbuf documentation: document most functions, René Scharfe, (Tue Jun 3, 8:41 am)
[PATCH] Strbuf documentation: document most functions, Miklos Vajna, (Tue Jun 3, 6:15 pm)
Re: [PATCH] Strbuf documentation: document most functions, Junio C Hamano, (Wed Jun 4, 12:45 am)
[PATCH] Strbuf documentation: document most functions, Miklos Vajna, (Wed Jun 4, 2:20 pm)