Skip to content

Commit

Permalink
bstr: add bstr_xappend0
Browse files Browse the repository at this point in the history
  • Loading branch information
guidocella authored and kasper93 committed Nov 27, 2024
1 parent b9e6030 commit f7e2a8c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
5 changes: 5 additions & 0 deletions misc/bstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ struct bstr bstr_strip_linebreaks(struct bstr str);
*/
void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);

static inline void bstr_xappend0(void *talloc_ctx, bstr *s, const char *append)
{
return bstr_xappend(talloc_ctx, s, bstr0(append));
}

/**
* @brief Append a formatted string to the existing bstr.
*
Expand Down
1 change: 0 additions & 1 deletion player/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ bool str_in_list(bstr str, char **list)
bstr_xappend_asprintf(ctx, &dst, " %s%s", first ? "[" : "", flag); \
first = false; \
} while(0)
#define bstr_xappend0(ctx, dst, s) bstr_xappend(ctx, dst, bstr0(s))

char *mp_format_track_metadata(void *ctx, struct track *t, bool add_lang)
{
Expand Down
2 changes: 0 additions & 2 deletions video/out/gpu/shader_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ void gl_sc_enable_extension(struct gl_shader_cache *sc, char *name)
MP_TARRAY_APPEND(sc, sc->exts, sc->num_exts, talloc_strdup(sc, name));
}

#define bstr_xappend0(sc, b, s) bstr_xappend(sc, b, bstr0(s))

void gl_sc_add(struct gl_shader_cache *sc, const char *text)
{
bstr_xappend0(sc, &sc->text, text);
Expand Down
12 changes: 6 additions & 6 deletions video/out/vo_tct.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ static void print_seq3(bstr *frame, struct lut_item *lut, bstr prefix,
bstr_xappend(NULL, frame, (bstr){ lut[r].str, lut[r].width });
bstr_xappend(NULL, frame, (bstr){ lut[g].str, lut[g].width });
bstr_xappend(NULL, frame, (bstr){ lut[b].str, lut[b].width });
bstr_xappend(NULL, frame, (bstr)bstr0_lit("m"));
bstr_xappend0(NULL, frame, "m");
}

static void print_seq1(bstr *frame, struct lut_item *lut, bstr prefix, uint8_t c)
{
bstr_xappend(NULL, frame, prefix);
bstr_xappend(NULL, frame, (bstr){ lut[c].str, lut[c].width });
bstr_xappend(NULL, frame, (bstr)bstr0_lit("m"));
bstr_xappend0(NULL, frame, "m");
}

static void print_buffer(bstr *frame)
Expand Down Expand Up @@ -155,11 +155,11 @@ static void write_plain(bstr *frame,
} else {
print_seq3(frame, lut, TERM_ESC_COLOR24BIT_BG, r, g, b);
}
bstr_xappend(NULL, frame, (bstr)bstr0_lit(" "));
bstr_xappend0(NULL, frame, " ");
if (buffering <= VO_TCT_BUFFER_PIXEL)
print_buffer(frame);
}
bstr_xappend(NULL, frame, (bstr)bstr0_lit(TERM_ESC_CLEAR_COLORS));
bstr_xappend0(NULL, frame, TERM_ESC_CLEAR_COLORS);
if (buffering <= VO_TCT_BUFFER_LINE)
print_buffer(frame);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ static void write_half_blocks(bstr *frame,
if (buffering <= VO_TCT_BUFFER_PIXEL)
print_buffer(frame);
}
bstr_xappend(NULL, frame, (bstr)bstr0_lit(TERM_ESC_CLEAR_COLORS));
bstr_xappend0(NULL, frame, TERM_ESC_CLEAR_COLORS);
if (buffering <= VO_TCT_BUFFER_LINE)
print_buffer(frame);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ static void flip_page(struct vo *vo)
p->opts.term256, p->lut, p->opts.buffering);
}

bstr_xappend(NULL, &p->frame_buf, (bstr)bstr0_lit("\n"));
bstr_xappend0(NULL, &p->frame_buf, "\n");
if (p->opts.buffering <= VO_TCT_BUFFER_FRAME)
print_buffer(&p->frame_buf);

Expand Down

0 comments on commit f7e2a8c

Please sign in to comment.