// Reads all boxes from the string. Otherwise, as ReadAllBoxes. bool ReadMemBoxes(int target_page, bool skip_blanks, const char* box_data, GenericVector<TBOX>* boxes, GenericVector<STRING>* texts, GenericVector<STRING>* box_texts, GenericVector<int>* pages) { STRING box_str(box_data); GenericVector<STRING> lines; box_str.split('\n', &lines); if (lines.empty()) return false; int num_boxes = 0; for (int i = 0; i < lines.size(); ++i) { int page = 0; STRING utf8_str; TBOX box; if (!ParseBoxFileStr(lines[i].string(), &page, &utf8_str, &box)) { continue; } if (skip_blanks && (utf8_str == " " || utf8_str == "\t")) continue; if (target_page >= 0 && page != target_page) continue; if (boxes != NULL) boxes->push_back(box); if (texts != NULL) texts->push_back(utf8_str); if (box_texts != NULL) { STRING full_text; MakeBoxFileStr(utf8_str.string(), box, target_page, &full_text); box_texts->push_back(full_text); } if (pages != NULL) pages->push_back(page); ++num_boxes; } return num_boxes > 0; }
// Returns a string debug representation of the given sample: // font, unichar_str, bounding box, page. STRING TrainingSampleSet::SampleToString(const TrainingSample &sample) const { STRING boxfile_str; MakeBoxFileStr(unicharset_.id_to_unichar(sample.class_id()), sample.bounding_box(), sample.page_num(), &boxfile_str); return STRING(fontinfo_table_.get(sample.font_id()).name) + " " + boxfile_str; }