49 if (char_32_ptr ==
NULL) {
53 while (char_32_ptr[++len]);
62 for (; (*pch1) != 0 && (*pch2) != 0; pch1++, pch2++) {
63 if ((*pch1) != (*pch2)) {
64 return (*pch1) - (*pch2);
83 if (new_str ==
NULL) {
86 memcpy(new_str, str32, len *
sizeof(*str32));
95 unsigned char *temp_buff = GetImageData(pix, left, top, wid, hgt);
96 if (temp_buff ==
NULL) {
111 if (char_samp ==
NULL) {
116 int stride = char_samp->
Stride();
117 int wid = char_samp->
Width();
118 int hgt = char_samp->
Height();
120 Pix *pix = pixCreate(wid, hgt, 1);
126 unsigned char *line = char_samp->
RawData();
127 for (
int y = 0; y < hgt ; y++, line += stride) {
128 for (
int x = 0; x < wid; x++) {
130 pixSetPixel(pix, x, y, 0);
132 pixSetPixel(pix, x, y, 255);
141 unsigned char *CubeUtils::GetImageData(Pix *pix,
int left,
int top,
144 if (left < 0 || top < 0 || wid < 0 || hgt < 0 ||
145 (left + wid) > pix->w || (top + hgt) > pix->h ||
151 unsigned char *temp_buff =
new unsigned char[wid * hgt];
152 if (temp_buff ==
NULL) {
162 pixGetDimensions(pix, &w, &h, &d);
163 wpl = pixGetWpl(pix);
164 data = pixGetData(pix);
165 line = data + (top * wpl);
167 for (
int y = 0, off = 0; y < hgt ; y++) {
168 for (
int x = 0; x < wid; x++, off++) {
169 temp_buff[off] = GET_DATA_BIT(line, x + left) ? 0 : 255;
179 FILE *fp = fopen(file_name.c_str(),
"rb");
185 fseek(fp, 0, SEEK_END);
186 int file_size = ftell(fp);
192 str->reserve(file_size);
195 char *buff =
new char[file_size];
200 int read_bytes = fread(buff, 1, static_cast<int>(file_size), fp);
201 if (read_bytes == file_size) {
202 str->append(buff, file_size);
206 return (read_bytes == file_size);
211 const string &delims,
212 vector<string> *str_vec) {
214 if (delims[0] !=
'\0' && delims[1] ==
'\0') {
216 const char* p = str.data();
217 const char* end = p + str.size();
222 const char* start = p;
223 while (++p != end && *p != c);
224 str_vec->push_back(
string(start, p - start));
230 string::size_type begin_index, end_index;
231 begin_index = str.find_first_not_of(delims);
232 while (begin_index != string::npos) {
233 end_index = str.find_first_of(delims, begin_index);
234 if (end_index == string::npos) {
235 str_vec->push_back(str.substr(begin_index));
238 str_vec->push_back(str.substr(begin_index, (end_index - begin_index)));
239 begin_index = str.find_first_not_of(delims, end_index);
246 int len = strlen(utf8_str);
248 for (
int ch = 0; ch < len; ch += step) {
251 UNICHAR uni_ch(utf8_str + ch, step);
260 for (
const char_32 *ch_32 = utf32_str; (*ch_32) != 0; ch_32++) {
271 bool all_one_case =
true;
284 first_upper = isupper(str32[0]);
285 first_lower = islower(str32[0]);
288 prev_upper = first_upper;
289 prev_lower = islower(str32[0]);
290 for (
int c = 1; str32[c] != 0; ++c) {
291 cur_upper = isupper(str32[c]);
292 cur_lower = islower(str32[c]);
293 if ((prev_upper && cur_lower) || (prev_lower && cur_upper))
294 all_one_case =
false;
297 prev_upper = cur_upper;
298 prev_lower = cur_lower;
307 prev_upper = first_upper;
310 for (
int c = 1; c <
StrLen(str32); ++c) {
313 if ((prev_upper && cur_lower) || (prev_lower && cur_upper))
314 all_one_case =
false;
317 prev_upper = cur_upper;
318 prev_lower = cur_lower;
321 return all_one_case || capitalized;
333 for (
int i = 0; i < len; ++i) {
335 if (ch == INVALID_UNICHAR_ID) {
344 if (!str32_lower ||
StrLen(str32_lower) != 1) {
348 lower[i] = str32_lower[0];
366 for (
int i = 0; i < len; ++i) {
368 if (ch == INVALID_UNICHAR_ID) {
377 if (!str32_upper ||
StrLen(str32_upper) != 1) {
381 upper[i] = str32_upper[0];
static Pix * PixFromCharSample(CharSamp *char_samp)
static int Prob2Cost(double prob_val)
unsigned char * RawData() const
bool get_isupper(UNICHAR_ID unichar_id) const
static bool ReadFileToString(const string &file_name, string *str)
static char_32 * ToLower(const char_32 *str32, CharSet *char_set)
unsigned short Width() const
static CharSamp * FromRawData(int left, int top, int wid, int hgt, unsigned char *data)
UNICHARSET * InternalUnicharset()
static void UTF8ToUTF32(const char *utf8_str, string_32 *str32)
int ClassID(const char_32 *str) const
static int utf8_step(const char *utf8_str)
bool get_islower(UNICHAR_ID unichar_id) const
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
unsigned short Stride() const
static double Cost2Prob(int cost)
static int StrLen(const char_32 *str)
static void UTF32ToUTF8(const char_32 *utf32_str, string *str)
static void SplitStringUsing(const string &str, const string &delims, vector< string > *str_vec)
static int StrCmp(const char_32 *str1, const char_32 *str2)
unsigned short Height() const
static char_32 * ToUpper(const char_32 *str32, CharSet *char_set)
static bool IsCaseInvariant(const char_32 *str32, CharSet *char_set)
basic_string< char_32 > string_32
static char_32 * StrDup(const char_32 *str)
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
const char_32 * ClassString(int class_id) const