Browse Source

[core] buffer_substr_replace()

personal/stbuehler/mod-csrf
Glenn Strauss 4 years ago
parent
commit
05c34ce464
  1. 21
      src/buffer.c
  2. 2
      src/buffer.h

21
src/buffer.c

@ -461,6 +461,27 @@ void buffer_copy_string_hex(buffer *b, const char *in, size_t in_len) {
li_tohex(b->ptr, buffer_string_length(b)+1, in, in_len);
}
void buffer_substr_replace (buffer * const b, const size_t offset,
const size_t len, const buffer * const replace)
{
const size_t blen = buffer_string_length(b);
const size_t rlen = buffer_string_length(replace);
if (rlen > len) {
buffer_string_set_length(b, blen-len+rlen);
memmove(b->ptr+offset+rlen, b->ptr+offset+len, blen-offset-len);
}
memcpy(b->ptr+offset, replace->ptr, rlen);
if (rlen < len) {
memmove(b->ptr+offset+rlen, b->ptr+offset+len, blen-offset-len);
buffer_string_set_length(b, blen-len+rlen);
}
}
/* everything except: ! ( ) * - . 0-9 A-Z _ a-z */
static const char encoded_chars_rel_uri_part[] = {
/*

2
src/buffer.h

@ -113,6 +113,8 @@ int buffer_is_equal_string(const buffer *a, const char *s, size_t b_len);
int buffer_is_equal_caseless_string(const buffer *a, const char *s, size_t b_len);
int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len);
void buffer_substr_replace (buffer *b, size_t offset, size_t len, const buffer *replace);
typedef enum {
ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of a href */
ENCODING_REL_URI_PART, /* same as ENC_REL_URL plus coding / too as %2F */

Loading…
Cancel
Save