Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkAutoAsciiToLC Class Reference

#include <SkTSearch.h>

Public Member Functions

 SkAutoAsciiToLC (const char str[], size_t len=(size_t) -1)
 
 ~SkAutoAsciiToLC ()
 
const char * lc () const
 
size_t length () const
 

Detailed Description

Helper class to convert a string to lower-case, but only modifying the ascii characters. This makes the routine very fast and never changes the string length, but it is not suitable for linguistic purposes. Normally this is used for buiding and searching string tables.

Definition at line 112 of file SkTSearch.h.

Constructor & Destructor Documentation

◆ SkAutoAsciiToLC()

SkAutoAsciiToLC::SkAutoAsciiToLC ( const char  str[],
size_t  len = (size_t)-1 
)

Definition at line 82 of file SkTSearch.cpp.

83{
84 // see if we need to compute the length
85 if ((long)len < 0) {
86 len = strlen(str);
87 }
88 fLength = len;
89
90 // assign lc to our preallocated storage if len is small enough, or allocate
91 // it on the heap
92 char* lc;
93 if (len <= STORAGE) {
94 lc = fStorage;
95 } else {
96 lc = (char*)sk_malloc_throw(len + 1);
97 }
98 fLC = lc;
99
100 // convert any asii to lower-case. we let non-ascii (utf8) chars pass
101 // through unchanged
102 for (int i = (int)(len - 1); i >= 0; --i) {
103 int c = str[i];
104 if ((c & 0x80) == 0) { // is just ascii
105 c = tolower(c);
106 }
107 lc[i] = c;
108 }
109 lc[len] = 0;
110}
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
const char * lc() const
Definition: SkTSearch.h:117

◆ ~SkAutoAsciiToLC()

SkAutoAsciiToLC::~SkAutoAsciiToLC ( )

Definition at line 112 of file SkTSearch.cpp.

113{
114 if (fLC != fStorage) {
115 sk_free(fLC);
116 }
117}
SK_API void sk_free(void *)

Member Function Documentation

◆ lc()

const char * SkAutoAsciiToLC::lc ( ) const
inline

Definition at line 117 of file SkTSearch.h.

117{ return fLC; }

◆ length()

size_t SkAutoAsciiToLC::length ( ) const
inline

Definition at line 118 of file SkTSearch.h.

118{ return fLength; }

The documentation for this class was generated from the following files: