Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/locale/nsUConvPropertySearch.cpp
Line
Count
Source (jump to first uncovered line)
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
0
  explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {}
16
0
  int operator()(const nsUConvProp& aProperty) const {
17
0
    return mKey.Compare(aProperty.mKey);
18
0
  }
19
};
20
21
} // namespace
22
23
// static
24
nsresult
25
nsUConvPropertySearch::SearchPropertyValue(const nsUConvProp aProperties[],
26
                                           int32_t aNumberOfProperties,
27
                                           const nsACString& aKey,
28
                                           nsACString& aValue)
29
0
{
30
0
  using mozilla::BinarySearchIf;
31
0
32
0
  const nsCString& flat = PromiseFlatCString(aKey);
33
0
  size_t index;
34
0
  if (BinarySearchIf(aProperties, 0, aNumberOfProperties,
35
0
                     PropertyComparator(flat), &index)) {
36
0
    nsDependentCString val(aProperties[index].mValue,
37
0
                           aProperties[index].mValueLength);
38
0
    aValue.Assign(val);
39
0
    return NS_OK;
40
0
  }
41
0
42
0
  aValue.Truncate();
43
0
  return NS_ERROR_FAILURE;
44
0
}