ChangeInfo * ChangeInfo::fromString(lString8 s) { lString8Collection rows(s, cs8("\n")); if (rows.length() < 3 || rows[0] != START_TAG || rows[rows.length() - 1] != END_TAG) return NULL; ChangeInfo * ci = new ChangeInfo(); CRBookmark bmk; for (int i=1; i<rows.length() - 1; i++) { lString8 row = rows[i]; int p = row.pos("="); if (p<1) continue; lString8 name = row.substr(0, p); lString8 value = row.substr(p + 1); if (name == ACTION_TAG) { ci->_deleted = (value == ACTION_DELETE_TAG); } else if (name == FILE_TAG) { ci->_fileName = decodeText(value); } else if (name == TYPE_TAG) { bmk.setType(value.atoi()); } else if (name == START_POS_TAG) { bmk.setStartPos(decodeText(value)); } else if (name == END_POS_TAG) { bmk.setEndPos(decodeText(value)); } else if (name == TIMESTAMP_TAG) { ci->_timestamp = value.atoi64() / 1000; bmk.setTimestamp(ci->_timestamp); } else if (name == PERCENT_TAG) { bmk.setPercent(value.atoi()); } else if (name == SHORTCUT_TAG) { bmk.setShortcut(value.atoi()); } else if (name == TITLE_TEXT_TAG) { bmk.setTitleText(decodeText(value)); } else if (name == POS_TEXT_TAG) { bmk.setPosText(decodeText(value)); } else if (name == COMMENT_TEXT_TAG) { bmk.setCommentText(decodeText(value)); } } if (bmk.isValid()) ci->_bookmark = new CRBookmark(bmk); if (ci->_fileName.empty() || ci->_timestamp == 0 || (!ci->_bookmark && !ci->_deleted)) { delete ci; return NULL; } return ci; }
/// called on text virtual void OnText( const lChar16 * text, int len, lUInt32 flags ) { CR_UNUSED(flags); lString16 txt( text, len ); switch (state) { case in_start_point: _curr_bookmark->setStartPos( txt ); break; case in_end_point: _curr_bookmark->setEndPos( txt ); break; case in_header_txt: _curr_bookmark->setTitleText( txt ); break; case in_selection_txt: _curr_bookmark->setPosText( txt ); break; case in_comment_txt: _curr_bookmark->setCommentText( txt ); break; case in_author: _curr_file->setAuthor( txt ); break; case in_title: _curr_file->setTitle( txt ); break; case in_series: _curr_file->setSeries( txt ); break; case in_filename: _curr_file->setFileName( txt ); break; case in_filepath: _curr_file->setFilePath( txt ); break; case in_filesize: _curr_file->setFileSize( txt.atoi() ); break; default: break; } }