mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-12 19:36:12 +08:00
moved case insensitive comparison utility functions into CString
from CHTTPProtocol.
This commit is contained in:
47
base/CString.cpp
Normal file
47
base/CString.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "CString.h"
|
||||
#include <ctype.h>
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// CStringUtil::CaselessCmp
|
||||
//
|
||||
|
||||
bool CStringUtil::CaselessCmp::cmpEqual(
|
||||
const CString::value_type& a,
|
||||
const CString::value_type& b)
|
||||
{
|
||||
// FIXME -- use std::tolower
|
||||
return tolower(a) == tolower(b);
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::cmpLess(
|
||||
const CString::value_type& a,
|
||||
const CString::value_type& b)
|
||||
{
|
||||
// FIXME -- use std::tolower
|
||||
return tolower(a) < tolower(b);
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::less(
|
||||
const CString& a,
|
||||
const CString& b)
|
||||
{
|
||||
return std::lexicographical_compare(
|
||||
a.begin(), a.end(),
|
||||
b.begin(), b.end(),
|
||||
&CStringUtil::CaselessCmp::cmpLess);
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::equal(
|
||||
const CString& a,
|
||||
const CString& b)
|
||||
{
|
||||
return !(less(a, b) || less(b, a));
|
||||
}
|
||||
|
||||
bool CStringUtil::CaselessCmp::operator()(
|
||||
const CString& a,
|
||||
const CString& b) const
|
||||
{
|
||||
return less(a, b);
|
||||
}
|
||||
@@ -44,6 +44,20 @@ public:
|
||||
_Myt(_f, _l CSTRING_ALLOC2) { }
|
||||
};
|
||||
|
||||
class CStringUtil {
|
||||
public:
|
||||
class CaselessCmp {
|
||||
public:
|
||||
bool operator()(const CString&, const CString&) const;
|
||||
static bool less(const CString&, const CString&);
|
||||
static bool equal(const CString&, const CString&);
|
||||
static bool cmpLess(const CString::value_type&,
|
||||
const CString::value_type&);
|
||||
static bool cmpEqual(const CString::value_type&,
|
||||
const CString::value_type&);
|
||||
};
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@ CXXFILES = \
|
||||
CLog.cpp \
|
||||
CFunctionJob.cpp \
|
||||
CStopwatch.cpp \
|
||||
CString.cpp \
|
||||
$(NULL)
|
||||
|
||||
targets: $(LIBTARGET)
|
||||
|
||||
@@ -99,6 +99,10 @@ SOURCE=.\CStopwatch.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CString.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XBase.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
|
||||
Reference in New Issue
Block a user