Bug 1890689 remove DynamicResampler::mSetBufferDuration r=pehrsons
[gecko.git] / intl / locale / nsUConvPropertySearch.cpp
blob114b85e0fe28071a9d7e589c2020fabd1d8bdcc0
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/. */
5 #include "nsUConvPropertySearch.h"
6 #include "nsCRT.h"
7 #include "nsString.h"
8 #include "mozilla/BinarySearch.h"
10 namespace {
12 struct PropertyComparator {
13 const nsCString& mKey;
14 explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {}
15 int operator()(const nsUConvProp& aProperty) const {
16 return Compare(mKey, nsDependentCString(aProperty.mKey));
20 } // namespace
22 // static
23 nsresult nsUConvPropertySearch::SearchPropertyValue(
24 const nsUConvProp aProperties[], int32_t aNumberOfProperties,
25 const nsACString& aKey, nsACString& aValue) {
26 using mozilla::BinarySearchIf;
28 const nsCString& flat = PromiseFlatCString(aKey);
29 size_t index;
30 if (BinarySearchIf(aProperties, 0, aNumberOfProperties,
31 PropertyComparator(flat), &index)) {
32 nsDependentCString val(aProperties[index].mValue,
33 aProperties[index].mValueLength);
34 aValue.Assign(val);
35 return NS_OK;
38 aValue.Truncate();
39 return NS_ERROR_FAILURE;