intl/locale/src/nsUConvPropertySearch.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 }

mercurial