diff options
author | Slávek Banko <[email protected]> | 2014-03-03 13:46:44 +0100 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2014-03-03 13:46:44 +0100 |
commit | 2e02da046d3e56cdf4744f644af35ad07424f48b (patch) | |
tree | f2dcf353aa2338eae1c2ff2c41af971c580c2762 /src/translators/bibteximporter.cpp | |
parent | 3c13229d98167ae4ae0710d5eeef23fef5005bf0 (diff) | |
download | tellico-2e02da046d3e56cdf4744f644af35ad07424f48b.tar.gz tellico-2e02da046d3e56cdf4744f644af35ad07424f48b.zip |
Update to upstream version 1.3.6
Diffstat (limited to 'src/translators/bibteximporter.cpp')
-rw-r--r-- | src/translators/bibteximporter.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/translators/bibteximporter.cpp b/src/translators/bibteximporter.cpp index fb52f95..d3668d4 100644 --- a/src/translators/bibteximporter.cpp +++ b/src/translators/bibteximporter.cpp @@ -308,5 +308,47 @@ TQWidget* BibtexImporter::widget(TQWidget* parent_, const char* name_/*=0*/) { return m_widget; } +bool BibtexImporter::maybeBibtex(const KURL& url_) { + TQString text = FileHandler::readTextFile(url_, true /*quiet*/); + if(text.isEmpty()) { + return false; + } + + bt_initialize(); + TQRegExp rx(TQString::fromLatin1("[{}]")); + + ushort bt_options = 0; // ushort is defined in btparse.h + boolean ok; // boolean is defined in btparse.h as an int + bool foundOne = false; + int brace = 0; + int startpos = 0; + int pos = text.find(rx, 0); + while(pos > 0) { + if(text[pos] == '{') { + ++brace; + } else if(text[pos] == '}' && brace > 0) { + --brace; + } + if(brace == 0) { + TQString entry = text.mid(startpos, pos-startpos+1).stripWhiteSpace(); + // All the downstream text processing on the AST node will assume utf-8 + AST* node = bt_parse_entry_s(const_cast<char*>(entry.utf8().data()), + const_cast<char*>(url_.fileName().local8Bit().data()), + 0, bt_options, &ok); + if(ok && node) { + foundOne = true; + break; + } + startpos = pos+1; + } + pos = text.find(rx, pos+1); + } + if(foundOne) { + // clean up some structures + bt_parse_entry_s(0, 0, 1, 0, 0); + } + bt_cleanup(); + return foundOne; +} #include "bibteximporter.moc" |