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 memcpy(new_str, str32, len *
sizeof(*str32));
104 unsigned char *temp_buff = GetImageData(pix, left, top, wid, hgt);
105 if (temp_buff == NULL) {
122 if (char_samp == NULL) {
127 int stride = char_samp->
Stride();
128 int wid = char_samp->
Width();
129 int hgt = char_samp->
Height();
131 Pix *pix = pixCreate(wid, hgt, 1);
137 unsigned char *line = char_samp->
RawData();
138 for (
int y = 0; y < hgt ; y++, line += stride) {
139 for (
int x = 0; x < wid; x++) {
141 pixSetPixel(pix, x, y, 0);
143 pixSetPixel(pix, x, y, 255);
154 unsigned char *CubeUtils::GetImageData(Pix *pix,
int left,
int top,
157 if (left < 0 || top < 0 || wid < 0 || hgt < 0 ||
158 (left + wid) > pix->w || (top + hgt) > pix->h ||
164 unsigned char *temp_buff =
new unsigned char[wid * hgt];
172 pixGetDimensions(pix, &w, &h, &d);
173 wpl = pixGetWpl(pix);
174 data = pixGetData(pix);
175 line = data + (top * wpl);
177 for (
int y = 0, off = 0; y < hgt ; y++) {
178 for (
int x = 0; x < wid; x++, off++) {
179 temp_buff[off] = GET_DATA_BIT(line, x + left) ? 0 : 255;
191 FILE *fp = fopen(file_name.c_str(),
"rb");
197 fseek(fp, 0, SEEK_END);
198 int file_size = ftell(fp);
204 str->reserve(file_size);
207 char *buff =
new char[file_size];
208 int read_bytes = fread(buff, 1, static_cast<int>(file_size), fp);
209 if (read_bytes == file_size) {
210 str->append(buff, file_size);
214 return (read_bytes == file_size);
221 const string &delims,
222 vector<string> *str_vec) {
224 if (delims[0] !=
'\0' && delims[1] ==
'\0') {
226 const char* p = str.data();
227 const char* end = p + str.size();
232 const char* start = p;
233 while (++p != end && *p != c);
234 str_vec->push_back(
string(start, p - start));
240 string::size_type begin_index, end_index;
241 begin_index = str.find_first_not_of(delims);
242 while (begin_index != string::npos) {
243 end_index = str.find_first_of(delims, begin_index);
244 if (end_index == string::npos) {
245 str_vec->push_back(str.substr(begin_index));
248 str_vec->push_back(str.substr(begin_index, (end_index - begin_index)));
249 begin_index = str.find_first_not_of(delims, end_index);
258 int len = strlen(utf8_str);
260 for (
int ch = 0; ch < len; ch += step) {
263 UNICHAR uni_ch(utf8_str + ch, step);
274 for (
const char_32 *ch_32 = utf32_str; (*ch_32) != 0; ch_32++) {
285 bool all_one_case =
true;
298 first_upper = isupper(str32[0]);
299 first_lower = islower(str32[0]);
302 prev_upper = first_upper;
303 prev_lower = first_lower;
304 for (
int c = 1; str32[c] != 0; ++c) {
305 cur_upper = isupper(str32[c]);
306 cur_lower = islower(str32[c]);
307 if ((prev_upper && cur_lower) || (prev_lower && cur_upper))
308 all_one_case =
false;
311 prev_upper = cur_upper;
312 prev_lower = cur_lower;
321 prev_upper = first_upper;
322 prev_lower = first_lower;
324 for (
int c = 1; c <
StrLen(str32); ++c) {
327 if ((prev_upper && cur_lower) || (prev_lower && cur_upper))
328 all_one_case =
false;
331 prev_upper = cur_upper;
332 prev_lower = cur_lower;
335 return all_one_case || capitalized;
345 for (
int i = 0; i < len; ++i) {
347 if (ch == INVALID_UNICHAR_ID) {
356 if (!str32_lower ||
StrLen(str32_lower) != 1) {
360 lower[i] = str32_lower[0];
376 for (
int i = 0; i < len; ++i) {
378 if (ch == INVALID_UNICHAR_ID) {
387 if (!str32_upper ||
StrLen(str32_upper) != 1) {
391 upper[i] = str32_upper[0];
unsigned short Height() const
static char_32 * ToLower(const char_32 *str32, CharSet *char_set)
unsigned short Width() const
static bool ReadFileToString(const string &file_name, string *str)
static char_32 * ToUpper(const char_32 *str32, CharSet *char_set)
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
static double Cost2Prob(int cost)
static int Prob2Cost(double prob_val)
static void UTF32ToUTF8(const char_32 *utf32_str, string *str)
static int StrLen(const char_32 *str)
bool get_isupper(UNICHAR_ID unichar_id) const
static void SplitStringUsing(const string &str, const string &delims, vector< string > *str_vec)
static CharSamp * FromRawData(int left, int top, int wid, int hgt, unsigned char *data)
unsigned char * RawData() const
static bool IsCaseInvariant(const char_32 *str32, CharSet *char_set)
basic_string< char_32 > string_32
unsigned short Stride() const
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
UNICHARSET * InternalUnicharset()
static int StrCmp(const char_32 *str1, const char_32 *str2)
bool get_islower(UNICHAR_ID unichar_id) const
static void UTF8ToUTF32(const char *utf8_str, string_32 *str32)
int ClassID(const char_32 *str) const
static Pix * PixFromCharSample(CharSamp *char_samp)
static int utf8_step(const char *utf8_str)
const char_32 * ClassString(int class_id) const
static char_32 * StrDup(const char_32 *str)