sb: add ty_sb_spaces_ltrim()

This commit is contained in:
Boris Faure 2020-05-15 23:15:18 +02:00
parent 4a12891493
commit 15ee3702db
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
2 changed files with 19 additions and 0 deletions

View File

@ -59,6 +59,24 @@ ty_sb_prepend(struct ty_sb *sb, const char *s, size_t len)
return 0;
}
/* unlike eina_strbuf_rtrim, only trims \t, \f, ' ' */
void
ty_sb_spaces_ltrim(struct ty_sb *sb)
{
if (!sb->buf)
return;
while (sb->len > 0)
{
char c = sb->buf[0];
if ((c != ' ') && (c != '\t') && (c != '\f'))
break;
sb->len--;
sb->buf++;
sb->gap++;
}
sb->buf[sb->len] = '\0';
}
/* unlike eina_strbuf_rtrim, only trims \t, \f, ' ' */
void

View File

@ -12,6 +12,7 @@ struct ty_sb {
int ty_sb_add(struct ty_sb *sb, const char *s, size_t len);
void ty_sb_spaces_rtrim(struct ty_sb *sb);
void ty_sb_spaces_ltrim(struct ty_sb *sb);
int ty_sb_prepend(struct ty_sb *sb, const char *s, size_t len);
char *ty_sb_steal_buf(struct ty_sb *sb);
void ty_sb_lskip(struct ty_sb *sb, int len);