From 76a429e7e9dbfcd71fb7b6ce70e389da91bf394c Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Tue, 26 May 2009 12:08:34 +0000 Subject: [PATCH] +! Experimental support for UTF-8 in .bgl files added. --- src/bgl_babylon.cc | 14 ++++++++++++++ src/bgl_babylon.hh | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bgl_babylon.cc b/src/bgl_babylon.cc index 37011d82..2c7812a5 100644 --- a/src/bgl_babylon.cc +++ b/src/bgl_babylon.cc @@ -155,6 +155,8 @@ bool Babylon::read(std::string &source_charset, std::string &target_charset) std::string headword; std::string definition; + bool isUtf8File = false; + m_sourceCharset = source_charset; m_targetCharset = target_charset; m_numEntries = 0; @@ -234,6 +236,10 @@ bool Babylon::read(std::string &source_charset, std::string &target_charset) icon.resize( block.length - 2 ); memcpy( &icon.front(), &(block.data[ 2 ]), icon.size() ); break; + case 17: + if ( block.length >= 5 && (unsigned char) block.data[ 4 ] == 0x80 ) + isUtf8File = true; + break; case 26: type = (unsigned int)block.data[2]; if( type > 64 ) type -= 65; @@ -261,6 +267,14 @@ bool Babylon::read(std::string &source_charset, std::string &target_charset) } gzseek( file, 0, SEEK_SET ); + if ( isUtf8File ) + { + //fprintf( stderr, "%s: utf8 file.\n", m_title.c_str() ); + m_defaultCharset = "UTF-8"; + m_sourceCharset = "UTF-8"; + m_targetCharset = "UTF-8"; + } + convertToUtf8( m_title, TARGET_CHARSET ); convertToUtf8( m_author, TARGET_CHARSET ); convertToUtf8( m_email, TARGET_CHARSET ); diff --git a/src/bgl_babylon.hh b/src/bgl_babylon.hh index 524dc633..f0bde85a 100644 --- a/src/bgl_babylon.hh +++ b/src/bgl_babylon.hh @@ -193,7 +193,7 @@ public: enum { - ParserVersion = 5 + ParserVersion = 6 }; private: