intl/locale/src/nsUConvPropertySearch.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/locale/src/nsUConvPropertySearch.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "nsUConvPropertySearch.h"
     1.9 +#include "nsCRT.h"
    1.10 +#include "nsString.h"
    1.11 +
    1.12 +// static
    1.13 +nsresult
    1.14 +nsUConvPropertySearch::SearchPropertyValue(const char* aProperties[][3],
    1.15 +                                           int32_t aNumberOfProperties,
    1.16 +                                           const nsACString& aKey,
    1.17 +                                           nsACString& aValue)
    1.18 +{
    1.19 +  const char* key = PromiseFlatCString(aKey).get();
    1.20 +  int32_t lo = 0;
    1.21 +  int32_t hi = aNumberOfProperties - 1;
    1.22 +  while (lo <= hi) {
    1.23 +    uint32_t mid = (lo + hi) / 2;
    1.24 +    int32_t comp = nsCRT::strcmp(aProperties[mid][0], key);
    1.25 +    if (comp > 0) {
    1.26 +      hi = mid - 1;
    1.27 +    } else if (comp < 0) {
    1.28 +      lo = mid + 1;
    1.29 +    } else {
    1.30 +      nsDependentCString val(aProperties[mid][1],
    1.31 +                             NS_PTR_TO_UINT32(aProperties[mid][2]));
    1.32 +      aValue.Assign(val);
    1.33 +      return NS_OK;
    1.34 +    }
    1.35 +  }
    1.36 +  aValue.Truncate();
    1.37 +  return NS_ERROR_FAILURE;
    1.38 +}

mercurial