Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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"
9 // static
10 nsresult
11 nsUConvPropertySearch::SearchPropertyValue(const char* aProperties[][3],
12 int32_t aNumberOfProperties,
13 const nsACString& aKey,
14 nsACString& aValue)
15 {
16 const char* key = PromiseFlatCString(aKey).get();
17 int32_t lo = 0;
18 int32_t hi = aNumberOfProperties - 1;
19 while (lo <= hi) {
20 uint32_t mid = (lo + hi) / 2;
21 int32_t comp = nsCRT::strcmp(aProperties[mid][0], key);
22 if (comp > 0) {
23 hi = mid - 1;
24 } else if (comp < 0) {
25 lo = mid + 1;
26 } else {
27 nsDependentCString val(aProperties[mid][1],
28 NS_PTR_TO_UINT32(aProperties[mid][2]));
29 aValue.Assign(val);
30 return NS_OK;
31 }
32 }
33 aValue.Truncate();
34 return NS_ERROR_FAILURE;
35 }