diff options
author | David Tardon <dtardon@redhat.com> | 2014-09-02 16:19:36 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-09-02 16:19:36 +0200 |
commit | e8ac87f2e38d9f2a7a576fda9636f095174a4d35 (patch) | |
tree | 5c63a94a0729294979aab4011518ff835d0b47df | |
parent | 63f095f4ebdde853897153d31613eec614dd1689 (diff) |
implement format detection
-rw-r--r-- | src/lib/SDFDocument.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/SDFDocument.cpp b/src/lib/SDFDocument.cpp index d253c21..07743fd 100644 --- a/src/lib/SDFDocument.cpp +++ b/src/lib/SDFDocument.cpp @@ -25,8 +25,24 @@ using boost::shared_ptr; namespace libsdf { +static const unsigned char SDF_MIMETYPE[] = "application/x-sdf"; + SDFAPI bool SDFDocument::isSupported(librevenge::RVNGInputStream *const input) try { + if (input->isStructured() && input->existsSubStream("mimetype")) + { + RVNGInputStreamPtr_t mimetypeInput(input->getSubStreamByName("mimetype")); + + const unsigned long len = SDF_NUM_ELEMENTS(SDF_MIMETYPE) - 1; // ignore the trailing 0 + unsigned long readBytes = 0; + const unsigned char *const mimetype = mimetypeInput->read(len, readBytes); + if (readBytes == len) + { + unsigned char c = readU8(mimetypeInput); + return mimetypeInput->isEnd() && std::equal(mimetype, mimetype + len, SDF_MIMETYPE) && ('\n' == c); + } + } + return false; } catch (...) |