2011-03-25 22:36:43 +00:00
|
|
|
/*
|
2012-08-16 03:47:55 +00:00
|
|
|
* $Id$
|
2011-03-25 22:36:43 +00:00
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2011-03-25 22:36:43 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2011-03-25 22:36:43 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2011-03-25 22:36:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qse/cmn/str.h>
|
|
|
|
#include <qse/cmn/chr.h>
|
|
|
|
|
|
|
|
int qse_mbscmp (const qse_mchar_t* s1, const qse_mchar_t* s2)
|
|
|
|
{
|
|
|
|
while (*s1 == *s2)
|
|
|
|
{
|
|
|
|
if (*s1 == QSE_MT('\0')) return 0;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return ((qse_mchau_t)*s1 > (qse_mchau_t)*s2)? 1: -1;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_mbsxcmp (const qse_mchar_t* s1, qse_size_t ln, const qse_mchar_t* s2)
|
|
|
|
{
|
|
|
|
const qse_mchar_t* end = s1 + ln;
|
2017-12-31 16:40:24 +00:00
|
|
|
|
2018-01-03 06:59:41 +00:00
|
|
|
while (s1 < end && *s2 != QSE_MT('\0'))
|
2017-12-31 16:40:24 +00:00
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
if (*s1 != *s2) return ((qse_mchau_t)*s1 > (qse_mchau_t)*s2)? 1: -1;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++;
|
2017-12-31 16:40:24 +00:00
|
|
|
}
|
2018-01-03 06:59:41 +00:00
|
|
|
|
|
|
|
/* if s1 < end, *s2 must be '\0'. */
|
2018-01-15 14:00:02 +00:00
|
|
|
return (s1 < end)? 1: ((*s2 == QSE_MT('\0'))? 0: -1);
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_mbsxncmp (
|
|
|
|
const qse_mchar_t* s1, qse_size_t ln1,
|
|
|
|
const qse_mchar_t* s2, qse_size_t ln2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
qse_mchau_t c1, c2;
|
2011-03-25 22:36:43 +00:00
|
|
|
const qse_mchar_t* end1 = s1 + ln1;
|
|
|
|
const qse_mchar_t* end2 = s2 + ln2;
|
|
|
|
|
|
|
|
while (s1 < end1)
|
|
|
|
{
|
|
|
|
c1 = *s1;
|
|
|
|
if (s2 < end2)
|
|
|
|
{
|
|
|
|
c2 = *s2;
|
|
|
|
if (c1 > c2) return 1;
|
|
|
|
if (c1 < c2) return -1;
|
|
|
|
}
|
|
|
|
else return 1;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (s2 < end2)? -1: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_mbscasecmp (const qse_mchar_t* s1, const qse_mchar_t* s2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
while (QSE_TOMUPPER((qse_mchau_t)*s1) == QSE_TOMUPPER((qse_mchau_t)*s2))
|
2011-03-25 22:36:43 +00:00
|
|
|
{
|
2018-01-15 14:00:02 +00:00
|
|
|
if (*s1 == QSE_T('\0')) return 0;
|
2013-03-22 14:48:57 +00:00
|
|
|
s1++; s2++;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return (QSE_TOMUPPER((qse_mchau_t)*s1) > QSE_TOMUPPER((qse_mchau_t)*s2))? 1: -1;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_mbsxcasecmp (const qse_mchar_t* s1, qse_size_t ln, const qse_mchar_t* s2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
qse_mchau_t c1, c2;
|
2017-12-31 16:40:24 +00:00
|
|
|
const qse_mchar_t* end = s1 + ln;
|
|
|
|
|
|
|
|
while (s1 < end && *s2 != QSE_MT('\0'))
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
c1 = QSE_TOMUPPER((qse_mchau_t)*s1);
|
|
|
|
c2 = QSE_TOMUPPER((qse_mchau_t)*s2);
|
2018-01-03 06:59:41 +00:00
|
|
|
if (c1 != c2) return (c1 > c2)? 1: -1;
|
2017-12-31 16:40:24 +00:00
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
2018-01-15 14:00:02 +00:00
|
|
|
return (s1 < end)? 1: ((*s2 == QSE_MT('\0'))? 0: -1);
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_mbsxncasecmp (
|
|
|
|
const qse_mchar_t* s1, qse_size_t ln1,
|
|
|
|
const qse_mchar_t* s2, qse_size_t ln2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
qse_mchau_t c1, c2;
|
2011-03-25 22:36:43 +00:00
|
|
|
const qse_mchar_t* end1 = s1 + ln1;
|
|
|
|
const qse_mchar_t* end2 = s2 + ln2;
|
|
|
|
|
|
|
|
while (s1 < end1)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
c1 = QSE_TOMUPPER ((qse_mchau_t)*s1);
|
2011-03-25 22:36:43 +00:00
|
|
|
if (s2 < end2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
c2 = QSE_TOMUPPER ((qse_mchau_t)*s2);
|
2011-03-25 22:36:43 +00:00
|
|
|
if (c1 > c2) return 1;
|
|
|
|
if (c1 < c2) return -1;
|
|
|
|
}
|
|
|
|
else return 1;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (s2 < end2)? -1: 0;
|
|
|
|
}
|
|
|
|
|
2011-09-01 09:43:46 +00:00
|
|
|
|
|
|
|
int qse_mbszcmp (const qse_mchar_t* s1, const qse_mchar_t* s2, qse_size_t n)
|
|
|
|
{
|
|
|
|
if (n == 0) return 0;
|
|
|
|
|
|
|
|
while (*s1 == *s2)
|
|
|
|
{
|
|
|
|
if (*s1 == QSE_MT('\0') || n == 1) return 0;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++; n--;
|
2011-09-01 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return ((qse_mchau_t)*s1 > (qse_mchau_t)*s2)? 1: -1;
|
2011-09-01 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 13:56:20 +00:00
|
|
|
int qse_mbszcasecmp (const qse_mchar_t* s1, const qse_mchar_t* s2, qse_size_t n)
|
|
|
|
{
|
|
|
|
if (n == 0) return 0;
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
while (QSE_TOMUPPER((qse_mchau_t)*s1) == QSE_TOMUPPER((qse_mchau_t)*s2))
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
|
|
|
if (*s1 == QSE_MT('\0') || n == 1) return 0;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++; n--;
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return (QSE_TOMUPPER((qse_mchau_t)*s1) > QSE_TOMUPPER((qse_mchau_t)*s2))? 1: -1;
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2011-03-25 22:36:43 +00:00
|
|
|
int qse_wcscmp (const qse_wchar_t* s1, const qse_wchar_t* s2)
|
|
|
|
{
|
|
|
|
while (*s1 == *s2)
|
|
|
|
{
|
|
|
|
if (*s1 == QSE_WT('\0')) return 0;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (*s1 > *s2)? 1: -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_wcsxcmp (const qse_wchar_t* s1, qse_size_t ln, const qse_wchar_t* s2)
|
|
|
|
{
|
|
|
|
const qse_wchar_t* end = s1 + ln;
|
2018-01-03 06:59:41 +00:00
|
|
|
|
|
|
|
while (s1 < end && *s2 != QSE_WT('\0'))
|
2017-12-31 16:40:24 +00:00
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
if (*s1 != *s2) return ((qse_wchau_t)*s1 > (qse_wchau_t)*s2)? 1: -1;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++;
|
2017-12-31 16:40:24 +00:00
|
|
|
}
|
2018-01-03 06:59:41 +00:00
|
|
|
|
2018-01-15 14:00:02 +00:00
|
|
|
return (s1 < end)? 1: ((*s2 == QSE_WT('\0'))? 0: -1);
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-30 09:26:33 +00:00
|
|
|
int qse_wcsxncmp (const qse_wchar_t* s1, qse_size_t ln1, const qse_wchar_t* s2, qse_size_t ln2)
|
2011-03-25 22:36:43 +00:00
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
qse_wchau_t c1, c2;
|
2011-03-25 22:36:43 +00:00
|
|
|
const qse_wchar_t* end1 = s1 + ln1;
|
|
|
|
const qse_wchar_t* end2 = s2 + ln2;
|
|
|
|
|
|
|
|
while (s1 < end1)
|
|
|
|
{
|
|
|
|
c1 = *s1;
|
|
|
|
if (s2 < end2)
|
|
|
|
{
|
|
|
|
c2 = *s2;
|
|
|
|
if (c1 > c2) return 1;
|
|
|
|
if (c1 < c2) return -1;
|
|
|
|
}
|
|
|
|
else return 1;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (s2 < end2)? -1: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_wcscasecmp (const qse_wchar_t* s1, const qse_wchar_t* s2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
while (QSE_TOWUPPER((qse_wchau_t)*s1) == QSE_TOWUPPER((qse_wchau_t)*s2))
|
2011-03-25 22:36:43 +00:00
|
|
|
{
|
2018-01-15 14:00:02 +00:00
|
|
|
if (*s1 == QSE_T('\0')) return 0;
|
|
|
|
s1++; s2++;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return (QSE_TOWUPPER((qse_wchau_t)*s1) > QSE_TOWUPPER((qse_wchau_t)*s2))? 1: -1;
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_wcsxcasecmp (const qse_wchar_t* s1, qse_size_t ln, const qse_wchar_t* s2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
qse_wchau_t c1, c2;
|
2011-03-25 22:36:43 +00:00
|
|
|
const qse_wchar_t* end = s1 + ln;
|
|
|
|
|
2018-01-03 06:59:41 +00:00
|
|
|
while (s1 < end && *s2 != QSE_WT('\0'))
|
2011-03-25 22:36:43 +00:00
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
c1 = QSE_TOWUPPER((qse_wchau_t)*s1);
|
|
|
|
c2 = QSE_TOWUPPER((qse_wchau_t)*s2);
|
2018-01-03 06:59:41 +00:00
|
|
|
if (c1 != c2) return (c1 > c2)? 1: -1;
|
2011-03-25 22:36:43 +00:00
|
|
|
s1++; s2++;
|
|
|
|
}
|
2018-01-15 14:00:02 +00:00
|
|
|
return (s1 < end)? 1: ((*s2 == QSE_WT('\0'))? 0: -1);
|
2011-03-25 22:36:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-30 09:26:33 +00:00
|
|
|
int qse_wcsxncasecmp (const qse_wchar_t* s1, qse_size_t ln1, const qse_wchar_t* s2, qse_size_t ln2)
|
2011-03-25 22:36:43 +00:00
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
qse_wchau_t c1, c2;
|
2011-03-25 22:36:43 +00:00
|
|
|
const qse_wchar_t* end1 = s1 + ln1;
|
|
|
|
const qse_wchar_t* end2 = s2 + ln2;
|
|
|
|
|
|
|
|
while (s1 < end1)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
c1 = QSE_TOWUPPER((qse_wchau_t)*s1);
|
2011-03-25 22:36:43 +00:00
|
|
|
if (s2 < end2)
|
|
|
|
{
|
2018-01-08 08:25:49 +00:00
|
|
|
c2 = QSE_TOWUPPER((qse_wchau_t)*s2);
|
2011-03-25 22:36:43 +00:00
|
|
|
if (c1 > c2) return 1;
|
|
|
|
if (c1 < c2) return -1;
|
|
|
|
}
|
|
|
|
else return 1;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (s2 < end2)? -1: 0;
|
|
|
|
}
|
2011-09-01 09:43:46 +00:00
|
|
|
|
|
|
|
int qse_wcszcmp (const qse_wchar_t* s1, const qse_wchar_t* s2, qse_size_t n)
|
|
|
|
{
|
|
|
|
if (n == 0) return 0;
|
|
|
|
|
|
|
|
while (*s1 == *s2)
|
|
|
|
{
|
|
|
|
if (*s1 == QSE_WT('\0') || n == 1) return 0;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++; n--;
|
2011-09-01 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return ((qse_wchau_t)*s1 > (qse_wchau_t)*s2)? 1: -1;
|
2011-09-01 09:43:46 +00:00
|
|
|
}
|
2012-09-30 13:56:20 +00:00
|
|
|
|
|
|
|
int qse_wcszcasecmp (const qse_wchar_t* s1, const qse_wchar_t* s2, qse_size_t n)
|
|
|
|
{
|
|
|
|
if (n == 0) return 0;
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
while (QSE_TOWUPPER((qse_wchau_t)*s1) == QSE_TOWUPPER((qse_wchau_t)*s2))
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
|
|
|
if (*s1 == QSE_WT('\0') || n == 1) return 0;
|
2018-01-03 06:59:41 +00:00
|
|
|
s1++; s2++; n--;
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
return (QSE_TOWUPPER((qse_wchau_t)*s1) > QSE_TOWUPPER((qse_wchau_t)*s2))? 1: -1;
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
2019-09-10 08:53:59 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int qse_wcsmbscmp (const qse_wchar_t* s1, const qse_mchar_t* s2)
|
|
|
|
{
|
|
|
|
while (*s1 == *s2)
|
|
|
|
{
|
|
|
|
if (*s1 == QSE_WT('\0')) return 0;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*s1 > *s2)? 1: -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_wcsxmbscmp (const qse_wchar_t* s1, qse_size_t ln, const qse_mchar_t* s2)
|
|
|
|
{
|
|
|
|
const qse_wchar_t* end = s1 + ln;
|
|
|
|
|
|
|
|
while (s1 < end && *s2 != QSE_MT('\0'))
|
|
|
|
{
|
|
|
|
if (*s1 != *s2) return ((qse_wchau_t)*s1 > (qse_wchau_t)(qse_mchau_t)*s2)? 1: -1;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (s1 < end)? 1: ((*s2 == QSE_MT('\0'))? 0: -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_mbsxwcscmp (const qse_mchar_t* s1, qse_size_t ln, const qse_wchar_t* s2)
|
|
|
|
{
|
|
|
|
const qse_mchar_t* end = s1 + ln;
|
|
|
|
|
|
|
|
while (s1 < end && *s2 != QSE_WT('\0'))
|
|
|
|
{
|
|
|
|
if (*s1 != *s2) return ((qse_wchau_t)(qse_mchau_t)*s1 > (qse_wchau_t)*s2)? 1: -1;
|
|
|
|
s1++; s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (s1 < end)? 1: ((*s2 == QSE_WT('\0'))? 0: -1);
|
|
|
|
}
|