options/ansi: Impl tolower, strcasecmp and strcoll

This commit is contained in:
Andreas Hampicke 2018-05-26 16:30:32 +02:00
parent 6700a08a9d
commit 9fc5869f9e
3 changed files with 25 additions and 6 deletions

View file

@ -48,9 +48,12 @@ int isxdigit(int c) {
}
int tolower(int c) {
__ensure(!"Not implemented");
__builtin_unreachable();
// TODO: this really needs to be redesigned and support other charsets.
if(c >= 'A' && c <= 'Z')
return c - 'A' + 'a';
return c;
}
int toupper(int c) {
// TODO: this really needs to be redesigned and support other charsets.
if(c >= 'a' && c <= 'z')

View file

@ -80,10 +80,12 @@ int strcmp(const char *a, const char *b) {
i++;
}
}
int strcoll(const char *a, const char *b) {
__ensure(!"Not implemented");
__builtin_unreachable();
// TODO: strcoll should take "LC_COLLATE" into account.
return strcmp(a, b);
}
int strncmp(const char *a, const char *b, size_t max_size) {
size_t i = 0;
while(true) {

View file

@ -1,16 +1,30 @@
#include <strings.h>
#include <ctype.h>
#include <bits/ensure.h>
int ffs(int word) {
__ensure(!"Not implemented");
__builtin_unreachable();
}
int strcasecmp(const char *a, const char *b) {
__ensure(!"Not implemented");
__builtin_unreachable();
size_t i = 0;
while(true) {
unsigned char a_byte = tolower(a[i]);
unsigned char b_byte = tolower(b[i]);
if(!a_byte && !b_byte)
return 0;
// If only one char is null, one of the following cases applies.
if(a_byte < b_byte)
return -1;
if(a_byte > b_byte)
return 1;
i++;
}
}
int strncasecmp(const char *a, const char *b, size_t size) {
__ensure(!"Not implemented");
__builtin_unreachable();