2014-05-05 10:30:46 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-18 06:46:39 -07:00
|
|
|
int NS_FASTCALL
|
2014-05-27 00:15:35 -07:00
|
|
|
Compare(const nsTSubstring_CharT::base_string_type& aLhs,
|
|
|
|
const nsTSubstring_CharT::base_string_type& aRhs,
|
|
|
|
const nsTStringComparator_CharT& comp)
|
2014-05-05 10:30:46 -07:00
|
|
|
{
|
|
|
|
typedef nsTSubstring_CharT::size_type size_type;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
if (&aLhs == &aRhs) {
|
2014-05-05 10:30:46 -07:00
|
|
|
return 0;
|
2014-05-27 00:15:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
nsTSubstring_CharT::const_iterator leftIter, rightIter;
|
2014-05-27 00:15:35 -07:00
|
|
|
aLhs.BeginReading(leftIter);
|
|
|
|
aRhs.BeginReading(rightIter);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
size_type lLength = leftIter.size_forward();
|
|
|
|
size_type rLength = rightIter.size_forward();
|
|
|
|
size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
int result;
|
2014-05-27 00:15:35 -07:00
|
|
|
if ((result = comp(leftIter.get(), rightIter.get(),
|
|
|
|
lengthToCompare, lengthToCompare)) == 0) {
|
|
|
|
if (lLength < rLength) {
|
2014-05-05 10:30:46 -07:00
|
|
|
result = -1;
|
2014-05-27 00:15:35 -07:00
|
|
|
} else if (rLength < lLength) {
|
2014-05-05 10:30:46 -07:00
|
|
|
result = 1;
|
2014-05-27 00:15:35 -07:00
|
|
|
} else {
|
2014-05-05 10:30:46 -07:00
|
|
|
result = 0;
|
2014-05-27 00:15:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
int
|
2014-05-27 00:15:35 -07:00
|
|
|
nsTDefaultStringComparator_CharT::operator()(const char_type* aLhs,
|
|
|
|
const char_type* aRhs,
|
|
|
|
uint32_t aLLength,
|
|
|
|
uint32_t aRLength) const
|
2014-05-05 10:30:46 -07:00
|
|
|
{
|
2014-05-27 00:15:35 -07:00
|
|
|
return
|
|
|
|
aLLength == aRLength ? nsCharTraits<CharT>::compare(aLhs, aRhs, aLLength) :
|
|
|
|
(aLLength > aRLength) ? 1 : -1;
|
2014-05-05 10:30:46 -07:00
|
|
|
}
|