Update string compare family to current coding conventions.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-09-24 21:03:12 +02:00
parent 2bbbc11246
commit cc43c96acc
8 changed files with 37 additions and 28 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of the Sortix C Library.
@ -27,9 +27,10 @@
extern "C" int strcasecmp(const char* a, const char* b)
{
while ( true )
for ( size_t i = 0; true; i++ )
{
char ac = tolower(*a++), bc = tolower(*b++);
unsigned char ac = (unsigned char) tolower((unsigned char) a[i]);
unsigned char bc = (unsigned char) tolower((unsigned char) b[i]);
if ( ac == '\0' && bc == '\0' )
return 0;
if ( ac < bc )

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of the Sortix C Library.
@ -26,9 +26,10 @@
extern "C" int strcmp(const char* a, const char* b)
{
while ( true )
for ( size_t i = 0; true; i++ )
{
char ac = *a++, bc = *b++;
unsigned char ac = (unsigned char) a[i];
unsigned char bc = (unsigned char) b[i];
if ( ac == '\0' && bc == '\0' )
return 0;
if ( ac < bc )

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of the Sortix C Library.
@ -25,11 +25,12 @@
#include <string.h>
#include <ctype.h>
extern "C" int strncasecmp(const char* a, const char* b, size_t maxcount)
extern "C" int strncasecmp(const char* a, const char* b, size_t max_count)
{
while ( maxcount-- )
for ( size_t i = 0; i < max_count; i++ )
{
char ac = tolower(*a++), bc = tolower(*b++);
unsigned char ac = (unsigned char) tolower((unsigned char) a[i]);
unsigned char bc = (unsigned char) tolower((unsigned char) b[i]);
if ( ac == '\0' && bc == '\0' )
return 0;
if ( ac < bc )

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of the Sortix C Library.
@ -24,11 +24,12 @@
#include <string.h>
extern "C" int strncmp(const char* a, const char* b, size_t maxcount)
extern "C" int strncmp(const char* a, const char* b, size_t max_count)
{
while ( maxcount-- )
for ( size_t i = 0; i < max_count; i++ )
{
char ac = *a++, bc = *b++;
unsigned char ac = (unsigned char) a[i];
unsigned char bc = (unsigned char) b[i];
if ( ac == '\0' && bc == '\0' )
return 0;
if ( ac < bc )

View File

@ -28,9 +28,10 @@
extern "C"
int wcscasecmp(const wchar_t* a, const wchar_t* b)
{
while ( true )
for ( size_t i = 0; true; i++ )
{
wchar_t ac = towlower(*a++), bc = towlower(*b++);
wint_t ac = towlower((wint_t) a[i]);
wint_t bc = towlower((wint_t) b[i]);
if ( ac == L'\0' && bc == L'\0' )
return 0;
if ( ac < bc )

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library.
@ -26,9 +26,10 @@
extern "C" int wcscmp(const wchar_t* a, const wchar_t* b)
{
while ( true )
for ( size_t i = 0; true; i++ )
{
wchar_t ac = *a++, bc = *b++;
wint_t ac = (wint_t) a[i];
wint_t bc = (wint_t) b[i];
if ( ac == L'\0' && bc == L'\0' )
return 0;
if ( ac < bc )

View File

@ -26,11 +26,12 @@
#include <wctype.h>
extern "C"
int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t maxcount)
int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t max_count)
{
while ( maxcount-- )
for ( size_t i = 0; i < max_count; i++ )
{
wchar_t ac = towlower(*a++), bc = towlower(*b++);
wint_t ac = towlower((wint_t) a[i]);
wint_t bc = towlower((wint_t) b[i]);
if ( ac == L'\0' && bc == L'\0' )
return 0;
if ( ac < bc )

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
This file is part of the Sortix C Library.
@ -24,15 +24,17 @@
#include <wchar.h>
extern "C" int wcsncmp(const wchar_t* a, const wchar_t* b, size_t n)
extern "C" int wcsncmp(const wchar_t* a, const wchar_t* b, size_t max_count)
{
for ( size_t i = 0; i < n; i++ )
for ( size_t i = 0; i < max_count; i++ )
{
if ( a[i] == L'\0' && b[i] == L'\0' )
wint_t ac = (wint_t) a[i];
wint_t bc = (wint_t) b[i];
if ( ac == L'\0' && bc == L'\0' )
return 0;
if ( a[i] < b[i] )
if ( ac < bc )
return -1;
if ( a[i] > b[i] )
if ( ac > bc )
return 1;
}
return 0;