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
|
|
|
|
2010-05-10 07:09:13 -07:00
|
|
|
#include "nsUConvPropertySearch.h"
|
|
|
|
#include "nsCRT.h"
|
2013-09-27 09:45:04 -07:00
|
|
|
#include "nsString.h"
|
2014-09-17 06:46:24 -07:00
|
|
|
#include "mozilla/BinarySearch.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct PropertyComparator
|
|
|
|
{
|
|
|
|
const nsCString& mKey;
|
2014-09-24 06:16:53 -07:00
|
|
|
explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {}
|
2014-09-17 06:46:24 -07:00
|
|
|
int operator()(const char* (&aProperty)[3]) const {
|
|
|
|
return mKey.Compare(aProperty[0]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-10 07:09:13 -07:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
nsUConvPropertySearch::SearchPropertyValue(const char* aProperties[][3],
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNumberOfProperties,
|
2010-05-10 07:09:13 -07:00
|
|
|
const nsACString& aKey,
|
|
|
|
nsACString& aValue)
|
|
|
|
{
|
2014-09-17 06:46:24 -07:00
|
|
|
using mozilla::BinarySearchIf;
|
|
|
|
|
|
|
|
const nsCString& flat = PromiseFlatCString(aKey);
|
|
|
|
size_t index;
|
|
|
|
if (BinarySearchIf(aProperties, 0, aNumberOfProperties,
|
|
|
|
PropertyComparator(flat), &index)) {
|
|
|
|
nsDependentCString val(aProperties[index][1],
|
|
|
|
NS_PTR_TO_UINT32(aProperties[index][2]));
|
|
|
|
aValue.Assign(val);
|
|
|
|
return NS_OK;
|
2010-05-10 07:09:13 -07:00
|
|
|
}
|
2014-09-17 06:46:24 -07:00
|
|
|
|
2010-05-10 07:09:13 -07:00
|
|
|
aValue.Truncate();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|