mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Added strcasecmp(3), strncasecmp(3) and <strings.h>.
Why <strings.h>? Stupid POSIX.
This commit is contained in:
parent
2b57319c1c
commit
9b2de25f9b
2 changed files with 73 additions and 0 deletions
40
libmaxsi/include/strings.h
Normal file
40
libmaxsi/include/strings.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
strings.h
|
||||
String operations.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _STRINGS_H
|
||||
#define _STRINGS_H 1
|
||||
|
||||
#include <features.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@include(size_t.h)
|
||||
@include(locale_t.h)
|
||||
|
||||
int strcasecmp(const char* a, const char* b);
|
||||
int strncasecmp(const char* a, const char* b, size_t n);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -27,6 +27,7 @@
|
|||
#include <libmaxsi/memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
namespace Maxsi
|
||||
{
|
||||
|
@ -121,6 +122,38 @@ namespace Maxsi
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifndef SORTIX_KERNEL
|
||||
inline int charcasecmp(char a, char b)
|
||||
{
|
||||
return tolower(a) == tolower(b);
|
||||
}
|
||||
|
||||
extern "C" int strcasecmp(const char* a, const char* b)
|
||||
{
|
||||
while ( true )
|
||||
{
|
||||
char achar = *a++;
|
||||
char bchar = *b++;
|
||||
if ( !achar && !bchar ) { return 0; }
|
||||
int cmp = charcasecmp(achar, bchar);
|
||||
if ( cmp ) { return cmp; }
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int strncasecmp(const char* a, const char* b, size_t n)
|
||||
{
|
||||
while ( n-- )
|
||||
{
|
||||
char achar = *a++;
|
||||
char bchar = *b++;
|
||||
if ( !achar && !bchar ) { return 0; }
|
||||
int cmp = charcasecmp(achar, bchar);
|
||||
if ( cmp ) { return cmp; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
DUAL_FUNCTION(size_t, strspn, Accept, (const char* str, const char* accept))
|
||||
{
|
||||
size_t acceptlen = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue