void unserialize(Mapping& map, const string& data) { string::const_iterator it = data.begin(); string::const_iterator end = data.end(); Row* row = &map.rows.back(); size_t column = 0; size_t source = 0; size_t in_line = 0; size_t in_col = 0; size_t token = 0; vector<int> offset; while(true) { // check if we reached a delimiter for entries if (it == end || *it == ',' || *it == ';') { // only create valid entries // checks out of bound access if ( offset.size() == 1 && int(offset[0] + column) >= 0 ) { row->addEntry(Entry( column += offset[0] )); } else if ( offset.size() == 4 && int(offset[0] + column) >= 0 && int(offset[1] + source) >= 0 && int(offset[2] + in_line) >= 0 && int(offset[3] + in_col) >= 0 ) { row->addEntry(Entry( column += offset[0], source += offset[1], in_line += offset[2], in_col += offset[3] )); } else if ( offset.size() == 5 && int(offset[0] + column) >= 0 && int(offset[1] + source) >= 0 && int(offset[2] + in_line) >= 0 && int(offset[3] + in_col) >= 0 && int(offset[4] + token) >= 0 ) { row->addEntry(Entry( column += offset[0], source += offset[1], in_line += offset[2], in_col += offset[3], token += offset[4] )); } // empty rows are allowed else if (offset.size() != 0) { // everything else is not valid throw(runtime_error("invalid source map entry")); } // create a new row if (*it == ';') { map.addNewLine(); row = &map.rows.back(); column = 0; } // clear for next offset.clear(); // exit loop if at end if (it == end) break; } else { // parse a vlq number and put to offset offset.push_back(decodeVLQ(it, end)); } // advance ++it; } }