Browse Source

added functions for upper/lowercase a buffer and added 'len' the html-encoding

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@534 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.2
Jan Kneschke 17 years ago
parent
commit
f8687d3f6b
  1. 36
      src/buffer.c
  2. 7
      src/buffer.h

36
src/buffer.c

@ -660,7 +660,7 @@ int buffer_append_string_hex(buffer *b, const char *in, size_t in_len) {
return 0;
}
int buffer_append_string_url_encoded(buffer *b, const char *s) {
int buffer_append_string_url_encoded(buffer *b, const char *s, size_t s_len) {
unsigned char *ds, *d;
size_t d_len;
@ -670,6 +670,7 @@ int buffer_append_string_url_encoded(buffer *b, const char *s) {
SEGFAULT();
}
if (s_len == 0) return 0;
/* count to-be-encoded-characters */
for (ds = (unsigned char *)s, d_len = 0; *ds; ds++) {
@ -747,7 +748,7 @@ int buffer_append_string_url_encoded(buffer *b, const char *s) {
return 0;
}
int buffer_append_string_html_encoded(buffer *b, const char *s) {
int buffer_append_string_html_encoded(buffer *b, const char *s, size_t s_len) {
unsigned char *ds, *d;
size_t d_len;
@ -757,6 +758,8 @@ int buffer_append_string_html_encoded(buffer *b, const char *s) {
SEGFAULT();
}
/* nothing to append */
if (s_len == 0) return 0;
/* count to-be-encoded-characters */
for (ds = (unsigned char *)s, d_len = 0; *ds; ds++) {
@ -964,3 +967,32 @@ int light_isalpha(int c) {
int light_isalnum(int c) {
return light_isdigit(c) || light_isalpha(c);
}
int buffer_to_lower(buffer *b) {
char *c;
if (b->used == 0) return 0;
for (c = b->ptr; *c; c++) {
if (*c >= 'A' && *c <= 'Z') {
*c |= 32;
}
}
return 0;
}
int buffer_to_upper(buffer *b) {
char *c;
if (b->used == 0) return 0;
for (c = b->ptr; *c; c++) {
if (*c >= 'a' && *c <= 'z') {
*c &= ~32;
}
}
return 0;
}

7
src/buffer.h

@ -84,13 +84,16 @@ int buffer_is_equal_string(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);
int buffer_append_string_hex(buffer *b, const char *in, size_t in_len);
int buffer_append_string_url_encoded(buffer *b, const char *s);
int buffer_append_string_html_encoded(buffer *b, const char *s);
int buffer_append_string_url_encoded(buffer *b, const char *s, size_t s_len);
int buffer_append_string_html_encoded(buffer *b, const char *s, size_t s_len);
int buffer_urldecode_path(buffer *url);
int buffer_urldecode_query(buffer *url);
int buffer_path_simplify(buffer *dest, buffer *src);
int buffer_to_lower(buffer *b);
int buffer_to_upper(buffer *b);
/** deprecated */
int ltostr(char *buf, long val);
char hex2int(unsigned char c);

Loading…
Cancel
Save