mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Update string compare family to current coding conventions.
This commit is contained in:
parent
2bbbc11246
commit
cc43c96acc
8 changed files with 37 additions and 28 deletions
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -27,9 +27,10 @@
|
||||||
|
|
||||||
extern "C" int strcasecmp(const char* a, const char* b)
|
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' )
|
if ( ac == '\0' && bc == '\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -26,9 +26,10 @@
|
||||||
|
|
||||||
extern "C" int strcmp(const char* a, const char* b)
|
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' )
|
if ( ac == '\0' && bc == '\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -25,11 +25,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.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' )
|
if ( ac == '\0' && bc == '\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -24,11 +24,12 @@
|
||||||
|
|
||||||
#include <string.h>
|
#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' )
|
if ( ac == '\0' && bc == '\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
extern "C"
|
extern "C"
|
||||||
int wcscasecmp(const wchar_t* a, const wchar_t* b)
|
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' )
|
if ( ac == L'\0' && bc == L'\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -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.
|
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)
|
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' )
|
if ( ac == L'\0' && bc == L'\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -26,11 +26,12 @@
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
extern "C"
|
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' )
|
if ( ac == L'\0' && bc == L'\0' )
|
||||||
return 0;
|
return 0;
|
||||||
if ( ac < bc )
|
if ( ac < bc )
|
||||||
|
|
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -24,15 +24,17 @@
|
||||||
|
|
||||||
#include <wchar.h>
|
#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;
|
return 0;
|
||||||
if ( a[i] < b[i] )
|
if ( ac < bc )
|
||||||
return -1;
|
return -1;
|
||||||
if ( a[i] > b[i] )
|
if ( ac > bc )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue