xpcom/string/src/nsTStringComparator.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/string/src/nsTStringComparator.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +int NS_FASTCALL
    1.11 +Compare( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs, const nsTStringComparator_CharT& comp )
    1.12 +  {
    1.13 +    typedef nsTSubstring_CharT::size_type size_type;
    1.14 +
    1.15 +    if ( &lhs == &rhs )
    1.16 +      return 0;
    1.17 +
    1.18 +    nsTSubstring_CharT::const_iterator leftIter, rightIter;
    1.19 +    lhs.BeginReading(leftIter);
    1.20 +    rhs.BeginReading(rightIter);
    1.21 +
    1.22 +    size_type lLength = leftIter.size_forward();
    1.23 +    size_type rLength = rightIter.size_forward();
    1.24 +    size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
    1.25 +
    1.26 +    int result;
    1.27 +    if ( (result = comp(leftIter.get(), rightIter.get(), lengthToCompare, lengthToCompare)) == 0 )
    1.28 +      {
    1.29 +        if ( lLength < rLength )
    1.30 +          result = -1;
    1.31 +        else if ( rLength < lLength )
    1.32 +          result = 1;
    1.33 +        else
    1.34 +          result = 0;
    1.35 +      }
    1.36 +
    1.37 +    return result;
    1.38 +  }
    1.39 +
    1.40 +int
    1.41 +nsTDefaultStringComparator_CharT::operator()( const char_type* lhs, const char_type* rhs, uint32_t lLength, uint32_t rLength) const
    1.42 +  {
    1.43 +    return (lLength == rLength) ? nsCharTraits<CharT>::compare(lhs, rhs, lLength) :
    1.44 +           (lLength > rLength) ? 1 : -1;
    1.45 +  }

mercurial