fb2utils.cpp 533 B

123456789101112131415161718192021222324252627
  1. #include "fb2utils.h"
  2. #include <QFile>
  3. #include <QTextStream>
  4. namespace FB2 {
  5. QString read(const QString &filename)
  6. {
  7. // TODO: throw an exception instead of
  8. // returning an empty string
  9. QFile file( filename );
  10. if (!file.open( QFile::ReadOnly)) return QString();
  11. QTextStream in( &file );
  12. // Input should be UTF-8
  13. in.setCodec( "UTF-8" );
  14. // This will automatically switch reading from
  15. // UTF-8 to UTF-16 if a BOM is detected
  16. in.setAutoDetectUnicode( true );
  17. return in.readAll();
  18. }
  19. }