Implemented KRDataBlock::getString()

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40207
This commit is contained in:
kearwood
2013-01-04 20:31:39 +00:00
parent 70894249c1
commit b10ee3923b
2 changed files with 12 additions and 0 deletions

View File

@@ -199,3 +199,12 @@ bool KRDataBlock::save(const std::string& path) {
return true;
}
}
// Get contents as a string
std::string KRDataBlock::getString()
{
KRDataBlock b;
b.append(*this);
b.append((void *)"\0", 1); // Ensure data is null terminated, to read as a string safely
return std::string((char *)b.getStart());
}

View File

@@ -69,6 +69,9 @@ public:
// Return the size of the data block. Use append() or expand() to make the data block larger
size_t getSize() const;
// Get the contents as a string
std::string getString();
private:
void *m_data;
size_t m_data_size;