Files
sqlitebrowser/src/Data.h
Martin Kleusberg 27c657902e Improve handling of BOMs in table cells
Detect some Unicode BOMs and always treat data starting with a BOM as
text. We might need to fine-tune this later but it should be an
improvement already.

In the Edit Dialog remove the BOM from the text editor but keep it in
the hex editor. Also add it back to the text when saving changes in text
mode. This way the BOM is out of the way for text edits but is not lost
either when editing a cell.
2018-01-01 17:20:50 +01:00

21 lines
1.0 KiB
C

#ifndef DATA_H
#define DATA_H
#include <QString>
// This returns false if the data in the data parameter contains binary data. If it is text only, the function returns
// true. If the second parameter is specified, it will be used to convert the data from the given encoding to Unicode
// before doing the check. The third parameter can be used to only check the first couple of bytes which speeds up the
// text but makes it less reliable
bool isTextOnly(QByteArray data, const QString& encoding = QString(), bool quickTest = false);
// This function returns true if the data in the data parameter starts with a Unicode BOM. Otherwise it returns false.
bool startsWithBom(const QByteArray& data);
// This function checks if the data in the data parameter starts with a Unicode BOM. If so, the BOM is removed from the
// byte array and passed back to the caller separately as the return value of the function. If the data does not start
// with a BOM an empty byte array is returned and the original data is not modified.
QByteArray removeBom(QByteArray& data);
#endif