Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-07-06 21:54:45 +0300
committerJunio C Hamano <gitster@pobox.com>2023-07-06 21:54:45 +0300
commitda269af9207e38e820daad8aa993caa7d2fad76c (patch)
tree28567788ed00e6c037cb93684e95a473e3d2f412 /strbuf.h
parenta646b86cd10282de2ceb64ef33b5412e4fb2a54c (diff)
parent4416b86c6b34dad64b556bb1eb6711d5e6595a48 (diff)
Merge branch 'rs/strbuf-expand-step'
Code clean-up around strbuf_expand() API. * rs/strbuf-expand-step: strbuf: simplify strbuf_expand_literal_cb() replace strbuf_expand() with strbuf_expand_step() replace strbuf_expand_dict_cb() with strbuf_expand_step() strbuf: factor out strbuf_expand_step() pretty: factor out expand_separator()
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h57
1 files changed, 9 insertions, 48 deletions
diff --git a/strbuf.h b/strbuf.h
index 507670ce3c..69c2a4960f 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -314,58 +314,19 @@ const char *strbuf_join_argv(struct strbuf *buf, int argc,
const char **argv, char delim);
/**
- * This function 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.
- *
- * The format `%%` is automatically expanded to a single `%` as a quoting
- * mechanism; callers do not need to handle the `%` placeholder themselves,
- * and the callback function will not be invoked for this placeholder.
- *
- * 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 with any kind of data.
+ * Used with `strbuf_expand_step` to expand the literals %n and %x
+ * followed by two hexadecimal digits. Returns the number of recognized
+ * characters.
*/
-typedef size_t (*expand_fn_t) (struct strbuf *sb,
- const char *placeholder,
- void *context);
-void strbuf_expand(struct strbuf *sb,
- const char *format,
- expand_fn_t fn,
- void *context);
+size_t strbuf_expand_literal(struct strbuf *sb, const char *placeholder);
/**
- * Used as callback for `strbuf_expand` to only expand literals
- * (i.e. %n and %xNN). The context argument is ignored.
+ * If the string pointed to by `formatp` contains a percent sign ("%"),
+ * advance it to point to the character following the next one and
+ * return 1, otherwise return 0. Append the substring before that
+ * percent sign to `sb`, or the whole string if there is none.
*/
-size_t strbuf_expand_literal_cb(struct strbuf *sb,
- const char *placeholder,
- void *context);
-
-/**
- * Used as callback for `strbuf_expand()`, expects an array of
- * struct strbuf_expand_dict_entry as context, i.e. pairs of
- * placeholder and replacement string. The array needs to be
- * terminated by an entry with placeholder set to NULL.
- */
-struct strbuf_expand_dict_entry {
- const char *placeholder;
- const char *value;
-};
-size_t strbuf_expand_dict_cb(struct strbuf *sb,
- const char *placeholder,
- void *context);
+int strbuf_expand_step(struct strbuf *sb, const char **formatp);
/**
* Append the contents of one strbuf to another, quoting any