Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsUConvPropertySearch.h" |
michael@0 | 6 | #include "nsCRT.h" |
michael@0 | 7 | #include "nsString.h" |
michael@0 | 8 | |
michael@0 | 9 | // static |
michael@0 | 10 | nsresult |
michael@0 | 11 | nsUConvPropertySearch::SearchPropertyValue(const char* aProperties[][3], |
michael@0 | 12 | int32_t aNumberOfProperties, |
michael@0 | 13 | const nsACString& aKey, |
michael@0 | 14 | nsACString& aValue) |
michael@0 | 15 | { |
michael@0 | 16 | const char* key = PromiseFlatCString(aKey).get(); |
michael@0 | 17 | int32_t lo = 0; |
michael@0 | 18 | int32_t hi = aNumberOfProperties - 1; |
michael@0 | 19 | while (lo <= hi) { |
michael@0 | 20 | uint32_t mid = (lo + hi) / 2; |
michael@0 | 21 | int32_t comp = nsCRT::strcmp(aProperties[mid][0], key); |
michael@0 | 22 | if (comp > 0) { |
michael@0 | 23 | hi = mid - 1; |
michael@0 | 24 | } else if (comp < 0) { |
michael@0 | 25 | lo = mid + 1; |
michael@0 | 26 | } else { |
michael@0 | 27 | nsDependentCString val(aProperties[mid][1], |
michael@0 | 28 | NS_PTR_TO_UINT32(aProperties[mid][2])); |
michael@0 | 29 | aValue.Assign(val); |
michael@0 | 30 | return NS_OK; |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | aValue.Truncate(); |
michael@0 | 34 | return NS_ERROR_FAILURE; |
michael@0 | 35 | } |