Browse Source

[core] fix buffer_to_upper()

fix buffer_to_upper() and case-insensitive filesystem detection
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
2e385a1a53
  1. 2
      src/buffer.c
  2. 18
      src/t/test_buffer.c

2
src/buffer.c

@ -955,7 +955,7 @@ void buffer_to_upper(buffer *b) {
for (i = 0; i < b->used; ++i) {
char c = b->ptr[i];
if (c >= 'A' && c <= 'Z') b->ptr[i] &= ~0x20;
if (c >= 'a' && c <= 'z') b->ptr[i] &= ~0x20;
}
}

18
src/t/test_buffer.c

@ -1,5 +1,6 @@
#include "first.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@ -83,8 +84,25 @@ static void test_buffer_path_simplify(void) {
buffer_free(pdest);
}
static void test_buffer_to_lower_upper(void) {
buffer *psrc = buffer_init();
buffer_copy_string_len(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz"));
buffer_to_lower(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")));
buffer_to_upper(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
buffer_to_upper(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
buffer_to_lower(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")));
buffer_free(psrc);
}
int main() {
test_buffer_path_simplify();
test_buffer_to_lower_upper();
return 0;
}

Loading…
Cancel
Save