SkTSearch.h revision 80bacfeb4bda06541e8695bd502229727bccfea
180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkTSearch_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkTSearch_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypes.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  All of the SkTSearch variants want to return the index (0...N-1) of the
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  found element, or the bit-not of where to insert the element.
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  At a simple level, if the return value is negative, it was not found.
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  For clients that want to insert the new element if it was not found, use
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  the following logic:
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  int index = SkTSearch(...);
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  if (index >= 0) {
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *      // found at index
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  } else {
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *      index = ~index; // now we are positive
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *      // insert at index
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  }
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutemplate <typename T>
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkTSearch(const T* base, int count, const T& target, size_t elemSize)
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count >= 0);
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (count <= 0)
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return ~0;
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(base != NULL); // base may be NULL if count is zero
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int lo = 0;
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int hi = count - 1;
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (lo < hi)
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int mid = (hi + lo) >> 1;
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const T* elem = (const T*)((const char*)base + mid * elemSize);
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (*elem < target)
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            lo = mid + 1;
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi = mid;
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const T* elem = (const T*)((const char*)base + hi * elemSize);
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (*elem != target)
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (*elem < target)
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi += 1;
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        hi = ~hi;
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return hi;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutemplate <typename T, int (COMPARE)(const T*, const T*)>
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkTSearch(const T* base, int count, const T& target, size_t elemSize)
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count >= 0);
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (count <= 0) {
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return ~0;
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(base != NULL); // base may be NULL if count is zero
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int lo = 0;
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int hi = count - 1;
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (lo < hi) {
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int mid = (hi + lo) >> 1;
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const T* elem = (const T*)((const char*)base + mid * elemSize);
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (COMPARE(elem, &target) < 0)
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            lo = mid + 1;
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi = mid;
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const T* elem = (const T*)((const char*)base + hi * elemSize);
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int pred = COMPARE(elem, &target);
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (pred != 0) {
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (pred < 0)
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi += 1;
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        hi = ~hi;
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return hi;
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutemplate <typename T>
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkTSearch(const T* base, int count, const T& target, size_t elemSize,
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru              int (*compare)(const T*, const T*))
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count >= 0);
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (count <= 0) {
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return ~0;
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(base != NULL); // base may be NULL if count is zero
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int lo = 0;
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int hi = count - 1;
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (lo < hi) {
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int mid = (hi + lo) >> 1;
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const T* elem = (const T*)((const char*)base + mid * elemSize);
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if ((*compare)(elem, &target) < 0)
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            lo = mid + 1;
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi = mid;
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const T* elem = (const T*)((const char*)base + hi * elemSize);
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int pred = (*compare)(elem, &target);
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (pred != 0) {
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (pred < 0)
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi += 1;
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        hi = ~hi;
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return hi;
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutemplate <typename T>
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkTSearch(const T** base, int count, const T* target, size_t elemSize,
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int (*compare)(const T*, const T*))
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count >= 0);
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (count <= 0)
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return ~0;
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(base != NULL); // base may be NULL if count is zero
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int lo = 0;
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int hi = count - 1;
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (lo < hi)
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int mid = (hi + lo) >> 1;
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const T* elem = *(const T**)((const char*)base + mid * elemSize);
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if ((*compare)(elem, target) < 0)
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            lo = mid + 1;
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi = mid;
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const T* elem = *(const T**)((const char*)base + hi * elemSize);
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int pred = (*compare)(elem, target);
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (pred != 0)
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (pred < 0)
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi += 1;
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        hi = ~hi;
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return hi;
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutemplate <typename T,  int (COMPARE)(const T*, const T*)>
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkTSearch(const T** base, int count, const T* target, size_t elemSize)
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count >= 0);
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (count <= 0)
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return ~0;
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(base != NULL); // base may be NULL if count is zero
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int lo = 0;
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int hi = count - 1;
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (lo < hi)
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int mid = (hi + lo) >> 1;
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const T* elem = *(const T**)((const char*)base + mid * elemSize);
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (COMPARE(elem, target) < 0)
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            lo = mid + 1;
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi = mid;
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const T* elem = *(const T**)((const char*)base + hi * elemSize);
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int pred = COMPARE(elem, target);
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (pred != 0)
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (pred < 0)
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            hi += 1;
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        hi = ~hi;
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return hi;
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkStrSearch(const char*const* base, int count, const char target[],
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                size_t target_len, size_t elemSize);
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkStrSearch(const char*const* base, int count, const char target[],
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                size_t elemSize);
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** Like SkStrSearch, but treats target as if it were all lower-case. Assumes that
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    base points to a table of lower-case strings.
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkStrLCSearch(const char*const* base, int count, const char target[],
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                  size_t target_len, size_t elemSize);
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkStrLCSearch(const char*const* base, int count, const char target[],
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                  size_t elemSize);
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** Helper class to convert a string to lower-case, but only modifying the ascii
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    characters. This makes the routine very fast and never changes the string
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    length, but it is not suitable for linguistic purposes. Normally this is
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    used for buiding and searching string tables.
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/
21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkAutoAsciiToLC {
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkAutoAsciiToLC(const char str[], size_t len = (size_t)-1);
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ~SkAutoAsciiToLC();
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const char* lc() const { return fLC; }
22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t      length() const { return fLength; }
22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    char*   fLC;    // points to either the heap or fStorage
22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t  fLength;
23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum {
23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        STORAGE = 64
23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    char    fStorage[STORAGE+1];
23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Helper when calling qsort with a compare proc that has typed its arguments
23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void*)>(compare)
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
241