void TextSearchIndex::splitSearchResult(const std::string& result, std::string& text, ObjectFileRef& ref) const { // Get the index that marks the end of the // the text and where the FileOffset begins // Each result has only one offset that occupies // the last offsetSizeBytes bytes of the string, and // the offset is in MSB left to right FileOffset offset=0; FileOffset add=0; size_t idx=result.size()-1; for(size_t i=0; i < offsetSizeBytes; i++) { add = (unsigned char)(result[idx]); offset |= (add << (i*8)); idx--; } // Immediately preceding the FileOffset is // a single byte that denotes offset type RefType reftype=static_cast<RefType>((unsigned char)(result[idx])); ref.Set(offset,reftype); text=result.substr(0,idx); }
bool FileScanner::Read(ObjectFileRef& ref) { uint8_t typeByte; FileOffset fileOffset; if (!(Read(typeByte) && ReadFileOffset(fileOffset))) { return false; } ref.Set(fileOffset,(RefType)typeByte); return true; }
bool LocationIndex::Read(FileScanner& scanner, ObjectFileRef& object) const { uint8_t type; FileOffset fileOffset; if (!scanner.Read(type)) { return false; } switch (type) { case refNode: if (!scanner.ReadFileOffset(fileOffset, bytesForNodeFileOffset)) { return false; } break; case refArea: if (!scanner.ReadFileOffset(fileOffset, bytesForAreaFileOffset)) { return false; } break; case refWay: if (!scanner.ReadFileOffset(fileOffset, bytesForWayFileOffset)) { return false; } break; default: return false; } object.Set(fileOffset, (RefType)type); return true; }