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 element attribute virtual void OnAttribute( const lChar16 * nsname, const lChar16 * attrname, const lChar16 * attrvalue ) { CR_UNUSED(nsname); if ( lStr_cmp(attrname, "type")==0 && state==in_bm ) { static const char * tnames[] = {"lastpos", "position", "comment", "correction"}; for ( int i=0; i<4; i++) { if ( lStr_cmp(attrvalue, tnames[i])==0 ) { _curr_bookmark->setType( (bmk_type)i ); return; } } } else if ( lStr_cmp(attrname, "shortcut")==0 && state==in_bm ) { int n = lString16( attrvalue ).atoi(); _curr_bookmark->setShortcut( n ); } else if ( lStr_cmp(attrname, "percent")==0 && state==in_bm ) { int n1=0, n2=0; int i=0; for ( ; attrvalue[i]>='0' && attrvalue[i]<='9'; i++) n1 = n1*10 + (attrvalue[i]-'0'); if ( attrvalue[i]=='.' ) { i++; if (attrvalue[i]>='0' && attrvalue[i]<='9') n2 = (attrvalue[i++]-'0')*10; if (attrvalue[i]>='0' && attrvalue[i]<='9') n2 = (attrvalue[i++]-'0'); } _curr_bookmark->setPercent( n1*100 + n2 ); } else if ( lStr_cmp(attrname, "timestamp")==0 && state==in_bm ) { time_t n1=0; int i=0; for ( ; attrvalue[i]>='0' && attrvalue[i]<='9'; i++) n1 = n1*10 + (attrvalue[i]-'0'); _curr_bookmark->setTimestamp( n1 ); } else if (lStr_cmp(attrname, "page")==0 && state==in_bm) { _curr_bookmark->setBookmarkPage(lString16( attrvalue ).atoi()); } }