git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Strbuf documentation: document most functions

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Jun 3, 2008, 15:41 UTC
Message-ID
<48456632.9040103@lsrfire.ath.cx>
In-Reply-To
<1212447591-4870-1-git-send-email-vmiklos@frugalware.org>
Miklos Vajna schrieb:
> Actually this is a bit of request for help, I haven't figured out what
> strbuf_expand() does [...]

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é
Previous: Pierre HabouzitNext: Miklos Vajna
Message 5 of 8 in “Strbuf documentation: document most functions”
  1. Strbuf documentation: document most functionsMiklos Vajna, Jun 2, 2008
  2. Junio C HamanoJun 2, 2008
  3. Johannes SchindelinJun 3, 2008
  4. Pierre HabouzitJun 3, 2008
  5. René ScharfeJun 3, 2008
  6. Strbuf documentation: document most functionsMiklos Vajna, Jun 4, 2008
  7. Junio C HamanoJun 4, 2008
  8. Strbuf documentation: document most functionsMiklos Vajna, Jun 4, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.