LCOV - code coverage report
Current view: top level - intl/locale - nsUConvPropertySearch.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 14 14 100.0 %
Date: 2017-07-14 16:53:18 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* This Source Code Form is subject to the terms of the Mozilla Public
       2             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       3             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       4             : 
       5             : #include "nsUConvPropertySearch.h"
       6             : #include "nsCRT.h"
       7             : #include "nsString.h"
       8             : #include "mozilla/BinarySearch.h"
       9             : 
      10             : namespace {
      11             : 
      12             : struct PropertyComparator
      13             : {
      14             :   const nsCString& mKey;
      15          40 :   explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {}
      16         216 :   int operator()(const nsUConvProp& aProperty) const {
      17         216 :     return mKey.Compare(aProperty.mKey);
      18             :   }
      19             : };
      20             : 
      21             : } // namespace
      22             : 
      23             : // static
      24             : nsresult
      25          40 : nsUConvPropertySearch::SearchPropertyValue(const nsUConvProp aProperties[],
      26             :                                            int32_t aNumberOfProperties,
      27             :                                            const nsACString& aKey,
      28             :                                            nsACString& aValue)
      29             : {
      30             :   using mozilla::BinarySearchIf;
      31             : 
      32          80 :   const nsCString& flat = PromiseFlatCString(aKey);
      33             :   size_t index;
      34          80 :   if (BinarySearchIf(aProperties, 0, aNumberOfProperties,
      35          80 :                      PropertyComparator(flat), &index)) {
      36           7 :     nsDependentCString val(aProperties[index].mValue,
      37          21 :                            aProperties[index].mValueLength);
      38           7 :     aValue.Assign(val);
      39           7 :     return NS_OK;
      40             :   }
      41             : 
      42          33 :   aValue.Truncate();
      43          33 :   return NS_ERROR_FAILURE;
      44           9 : }

Generated by: LCOV version 1.13