Fixes #1219, Increase BibTeX read buffer and read only initial 1MB
A 1.5MB RIS file now goes through BibTeX detection in about 3 seconds instead of...longer. I'm not sure the limit really needs to be 1MB, either.
This commit is contained in:
parent
b5f3448304
commit
0f990781f1
1 changed files with 31 additions and 16 deletions
|
@ -8,32 +8,47 @@
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":200,
|
"priority":200,
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2008-11-23 21:30:00"
|
"lastUpdated":"2008-12-16 23:13:33"
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.configure("dataMode", "block");
|
Zotero.configure("dataMode", "block");
|
||||||
Zotero.addOption("exportCharset", "UTF-8");
|
Zotero.addOption("exportCharset", "UTF-8");
|
||||||
|
|
||||||
function detectImport() {
|
function detectImport() {
|
||||||
|
var maxChars = 1048576; // 1MB
|
||||||
|
|
||||||
|
var inComment = false;
|
||||||
var block = "";
|
var block = "";
|
||||||
var read;
|
var buffer = "";
|
||||||
|
var chr = "";
|
||||||
|
var charsRead = 0;
|
||||||
|
|
||||||
var re = /^\s*@[a-zA-Z]+[\(\{]/;
|
var re = /^\s*@[a-zA-Z]+[\(\{]/;
|
||||||
var lines_read = 0;
|
while((buffer = Zotero.read(4096)) && charsRead < maxChars) {
|
||||||
while(read = Zotero.read(1)) {
|
Zotero.debug("Scanning " + buffer.length + " characters for BibTeX");
|
||||||
if(read == "%") {
|
charsRead += buffer.length;
|
||||||
// read until next newline
|
for (var i=0; i<buffer.length; i++) {
|
||||||
block = "";
|
chr = buffer[i];
|
||||||
while((read = Zotero.read(1)) && read != "\r" && read != "\n") {}
|
|
||||||
} else if((read == "\n" || read == "\r") && block) {
|
|
||||||
// check if this is a BibTeX entry
|
|
||||||
if(re.test(block)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
block = "";
|
if (inComment && chr != "\r" && chr != "\n") {
|
||||||
} else if(" \n\r\t".indexOf(read) == -1) {
|
continue;
|
||||||
block += read;
|
}
|
||||||
|
inComment = false;
|
||||||
|
|
||||||
|
if(chr == "%") {
|
||||||
|
// read until next newline
|
||||||
|
block = "";
|
||||||
|
inComment = true;
|
||||||
|
} else if((chr == "\n" || chr == "\r") && block) {
|
||||||
|
// check if this is a BibTeX entry
|
||||||
|
if(re.test(block)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
block = "";
|
||||||
|
} else if(" \n\r\t".indexOf(chr) == -1) {
|
||||||
|
block += chr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue