55 if (char_32_ptr ==
NULL) {
59 while (char_32_ptr[++len]);
70 for (; (*pch1) != 0 && (*pch2) != 0; pch1++, pch2++) {
71 if ((*pch1) != (*pch2)) {
72 return (*pch1) - (*pch2);
93 if (new_str ==
NULL) {
96 memcpy(new_str, str32, len *
sizeof(*str32));
107 unsigned char *temp_buff = GetImageData(pix, left, top, wid, hgt);
108 if (temp_buff ==
NULL) {
125 if (char_samp ==
NULL) {
130 int stride = char_samp->
Stride();
131 int wid = char_samp->
Width();
132 int hgt = char_samp->
Height();
134 Pix *pix = pixCreate(wid, hgt, 1);
140 unsigned char *line = char_samp->
RawData();
141 for (
int y = 0; y < hgt ; y++, line += stride) {
142 for (
int x = 0; x < wid; x++) {
144 pixSetPixel(pix, x, y, 0);
146 pixSetPixel(pix, x, y, 255);
157 unsigned char *CubeUtils::GetImageData(Pix *pix,
int left,
int top,
160 if (left < 0 || top < 0 || wid < 0 || hgt < 0 ||
161 (left + wid) > pix->w || (top + hgt) > pix->h ||
167 unsigned char *temp_buff =
new unsigned char[wid * hgt];
168 if (temp_buff ==
NULL) {
178 pixGetDimensions(pix, &w, &h, &d);
179 wpl = pixGetWpl(pix);
180 data = pixGetData(pix);
181 line = data + (top * wpl);
183 for (
int y = 0, off = 0; y < hgt ; y++) {
184 for (
int x = 0; x < wid; x++, off++) {
185 temp_buff[off] = GET_DATA_BIT(line, x + left) ? 0 : 255;
197 FILE *fp = fopen(file_name.c_str(),
"rb");
203 fseek(fp, 0, SEEK_END);
204 int file_size = ftell(fp);
210 str->reserve(file_size);
213 char *buff =
new char[file_size];
218 int read_bytes = fread(buff, 1, static_cast<int>(file_size), fp);
219 if (read_bytes == file_size) {
220 str->append(buff, file_size);
224 return (read_bytes == file_size);
231 const string &delims,
232 vector<string> *str_vec) {
234 if (delims[0] !=
'\0' && delims[1] ==
'\0') {
236 const char* p = str.data();
237 const char* end = p + str.size();
242 const char* start = p;
243 while (++p != end && *p != c);
244 str_vec->push_back(
string(start, p - start));
250 string::size_type begin_index, end_index;
251 begin_index = str.find_first_not_of(delims);
252 while (begin_index != string::npos) {
253 end_index = str.find_first_of(delims, begin_index);
254 if (end_index == string::npos) {
255 str_vec->push_back(str.substr(begin_index));
258 str_vec->push_back(str.substr(begin_index, (end_index - begin_index)));
259 begin_index = str.find_first_not_of(delims, end_index);
268 int len = strlen(utf8_str);
270 for (
int ch = 0; ch < len; ch += step) {
273 UNICHAR uni_ch(utf8_str + ch, step);
284 for (
const char_32 *ch_32 = utf32_str; (*ch_32) != 0; ch_32++) {
295 bool all_one_case =
true;
308 first_upper = isupper(str32[0]);
309 first_lower = islower(str32[0]);
312 prev_upper = first_upper;
313 prev_lower = islower(str32[0]);
314 for (
int c = 1; str32[c] != 0; ++c) {
315 cur_upper = isupper(str32[c]);
316 cur_lower = islower(str32[c]);
317 if ((prev_upper && cur_lower) || (prev_lower && cur_upper))
318 all_one_case =
false;
321 prev_upper = cur_upper;
322 prev_lower = cur_lower;
331 prev_upper = first_upper;
334 for (
int c = 1; c <
StrLen(str32); ++c) {
337 if ((prev_upper && cur_lower) || (prev_lower && cur_upper))
338 all_one_case =
false;
341 prev_upper = cur_upper;
342 prev_lower = cur_lower;
345 return all_one_case || capitalized;
357 for (
int i = 0; i < len; ++i) {
359 if (ch == INVALID_UNICHAR_ID) {
368 if (!str32_lower ||
StrLen(str32_lower) != 1) {
372 lower[i] = str32_lower[0];
390 for (
int i = 0; i < len; ++i) {
392 if (ch == INVALID_UNICHAR_ID) {
401 if (!str32_upper ||
StrLen(str32_upper) != 1) {
405 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
basic_string< char_32 > string_32
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)
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