Flutter Engine
The Flutter Engine
Functions
SkTSearch.cpp File Reference
#include "src/base/SkTSearch.h"
#include "include/private/base/SkMalloc.h"
#include <cstring>
#include <ctype.h>

Go to the source code of this file.

Functions

static const char * index_into_base (const char *const *base, int index, size_t elemSize)
 
int SkStrSearch (const char *const *base, int count, const char target[], size_t target_len, size_t elemSize)
 
int SkStrSearch (const char *const *base, int count, const char target[], size_t elemSize)
 
int SkStrLCSearch (const char *const *base, int count, const char target[], size_t len, size_t elemSize)
 
int SkStrLCSearch (const char *const *base, int count, const char target[], size_t elemSize)
 

Function Documentation

◆ index_into_base()

static const char * index_into_base ( const char *const *  base,
int  index,
size_t  elemSize 
)
inlinestatic

Definition at line 16 of file SkTSearch.cpp.

18{
19 return *(const char*const*)((const char*)base + index * elemSize);
20}

◆ SkStrLCSearch() [1/2]

int SkStrLCSearch ( const char *const *  base,
int  count,
const char  target[],
size_t  elemSize 
)

Definition at line 74 of file SkTSearch.cpp.

76{
77 return SkStrLCSearch(base, count, target, strlen(target), elemSize);
78}
int count
Definition: FontMgrTest.cpp:50
int SkStrLCSearch(const char *const *base, int count, const char target[], size_t len, size_t elemSize)
Definition: SkTSearch.cpp:64
uint32_t * target

◆ SkStrLCSearch() [2/2]

int SkStrLCSearch ( const char *const *  base,
int  count,
const char  target[],
size_t  target_len,
size_t  elemSize 
)

Like SkStrSearch, but treats target as if it were all lower-case. Assumes that base points to a table of lower-case strings.

Definition at line 64 of file SkTSearch.cpp.

66{
68
70
71 return SkStrSearch(base, count, tolc.lc(), len, elemSize);
72}
#define SkASSERT(cond)
Definition: SkAssert.h:116
int SkStrSearch(const char *const *base, int count, const char target[], size_t target_len, size_t elemSize)
Definition: SkTSearch.cpp:22

◆ SkStrSearch() [1/2]

int SkStrSearch ( const char *const *  base,
int  count,
const char  target[],
size_t  elemSize 
)

Definition at line 58 of file SkTSearch.cpp.

60{
61 return SkStrSearch(base, count, target, strlen(target), elemSize);
62}

◆ SkStrSearch() [2/2]

int SkStrSearch ( const char *const *  base,
int  count,
const char  target[],
size_t  target_len,
size_t  elemSize 
)

Definition at line 22 of file SkTSearch.cpp.

24{
25 if (count <= 0)
26 return ~0;
27
28 SkASSERT(base != nullptr);
29
30 int lo = 0;
31 int hi = count - 1;
32
33 while (lo < hi)
34 {
35 int mid = (hi + lo) >> 1;
36 const char* elem = index_into_base(base, mid, elemSize);
37
38 int cmp = strncmp(elem, target, target_len);
39 if (cmp < 0)
40 lo = mid + 1;
41 else if (cmp > 0 || strlen(elem) > target_len)
42 hi = mid;
43 else
44 return mid;
45 }
46
47 const char* elem = index_into_base(base, hi, elemSize);
48 int cmp = strncmp(elem, target, target_len);
49 if (cmp || strlen(elem) > target_len)
50 {
51 if (cmp < 0)
52 hi += 1;
53 hi = ~hi;
54 }
55 return hi;
56}
static const char * index_into_base(const char *const *base, int index, size_t elemSize)
Definition: SkTSearch.cpp:16