michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsUConvPropertySearch.h" michael@0: #include "nsCRT.h" michael@0: #include "nsString.h" michael@0: michael@0: // static michael@0: nsresult michael@0: nsUConvPropertySearch::SearchPropertyValue(const char* aProperties[][3], michael@0: int32_t aNumberOfProperties, michael@0: const nsACString& aKey, michael@0: nsACString& aValue) michael@0: { michael@0: const char* key = PromiseFlatCString(aKey).get(); michael@0: int32_t lo = 0; michael@0: int32_t hi = aNumberOfProperties - 1; michael@0: while (lo <= hi) { michael@0: uint32_t mid = (lo + hi) / 2; michael@0: int32_t comp = nsCRT::strcmp(aProperties[mid][0], key); michael@0: if (comp > 0) { michael@0: hi = mid - 1; michael@0: } else if (comp < 0) { michael@0: lo = mid + 1; michael@0: } else { michael@0: nsDependentCString val(aProperties[mid][1], michael@0: NS_PTR_TO_UINT32(aProperties[mid][2])); michael@0: aValue.Assign(val); michael@0: return NS_OK; michael@0: } michael@0: } michael@0: aValue.Truncate(); michael@0: return NS_ERROR_FAILURE; michael@0: }