Clazz.declarePackage("J.adapter.readers.cif");
Clazz.load(["JU.CifDataParser"], "J.adapter.readers.cif.Cif2DataParser", ["java.util.Hashtable", "JU.PT"], function(){
var c$ = Clazz.declareType(J.adapter.readers.cif, "Cif2DataParser", JU.CifDataParser);
Clazz.overrideMethod(c$, "getVersion", 
function(){
return 2;
});
Clazz.overrideMethod(c$, "toUnicode", 
function(data){
return data;
}, "~S");
Clazz.overrideMethod(c$, "isQuote", 
function(ch){
switch ((ch).charCodeAt(0)) {
case 1:
case 39:
case 34:
case 91:
case 93:
case 123:
case 125:
case 59:
return true;
}
return false;
}, "~S");
Clazz.overrideMethod(c$, "getQuotedStringOrObject", 
function(ch){
return this.processQuotedString();
}, "~S");
Clazz.overrideMethod(c$, "preprocessString", 
function(){
this.line = (this.ich == 0 ? this.str : this.str.substring(this.ich));
return this.setString(this.processSemiString());
});
Clazz.defineMethod(c$, "processQuotedString", 
function(){
var str = null;
var quoteChar = this.str.charAt(this.ich);
var tripleChar = null;
try {
switch ((quoteChar).charCodeAt(0)) {
case 1:
str = this.str.substring(1, (this.ich = this.str.indexOf("\1", this.ich + 1)));
this.ich++;
break;
case 91:
return this.readList();
case 93:
this.ich++;
return "]";
case 123:
return this.readTable();
case 125:
this.ich++;
return "}";
case 39:
case 34:
if (this.str.indexOf("'''") == this.ich) tripleChar = "'''";
 else if (this.str.indexOf("\"\"\"") == this.ich) tripleChar = "\"\"\"";
var nchar = (tripleChar == null ? 1 : 3);
var pt = this.ich + nchar;
var pt1 = 0;
while ((pt1 = (tripleChar == null ? this.str.indexOf(quoteChar, pt) : this.str.indexOf(tripleChar, pt))) < 0) {
if (this.readLine() == null) break;
this.str += this.line;
}
this.ich = pt1 + nchar;
this.cch = this.str.length;
str = this.str.substring(pt, pt1);
break;
}
} catch (e) {
if (Clazz.exceptionOf(e, Exception)){
System.out.println("exception in Cif2DataParser ; " + e);
} else {
throw e;
}
}
return (this.cterm == '\0' || this.asObject ? str : JU.PT.esc(str));
});
Clazz.defineMethod(c$, "processSemiString", 
function(){
var pt1;
var pt2;
var str = this.preprocessSemiString();
if (str.indexOf(';') != 1 && (pt1 = str.indexOf('\\')) > 1 && ((pt2 = str.indexOf('\n')) > pt1 || pt2 < 0)) {
var prefix = str.substring(1, pt1);
str = JU.PT.rep(str, "\n" + prefix, "\n");
str = "\1" + str.substring(str.charAt(pt1 + 1) == '\\' ? pt1 + 1 : pt2 < 0 ? str.length - 1 : pt2 + 1);
}this.ich = 0;
return this.fixLineFolding(str);
});
Clazz.defineMethod(c$, "readTable", 
function(){
this.ich++;
var cterm0 = this.cterm;
this.cterm = '}';
var ns = this.nullString;
this.nullString = null;
var map = (this.asObject ?  new java.util.Hashtable() : null);
var n = 0;
var str = "";
while (true) {
var key = this.getNextToken();
if (key == null || key.equals("}")) break;
while (this.isSpaceOrColon(this.ich)) this.ich++;

if (this.asObject) {
map.put(key, this.getNextTokenObject());
} else {
if (n++ > 0) str += ",";
str += key + " : " + this.getNextToken();
}}
this.cterm = cterm0;
this.nullString = ns;
return (this.asObject ? map : "{" + str + "}");
});
Clazz.defineMethod(c$, "isSpaceOrColon", 
function(ich){
if (ich < this.cch) switch ((this.line.charAt(ich)).charCodeAt(0)) {
case 32:
case 9:
case 10:
case 58:
return true;
}
return false;
}, "~N");
Clazz.overrideMethod(c$, "unquoted", 
function(s){
if (this.cterm == '\0' && !this.asObject) return s;
var n = s.length;
if (n > 0) {
var c = s.charAt(0);
if (JU.PT.isDigit(c) || c == '-' || c == '.' && n > 1) {
var pt = s.indexOf('(');
var isFloat = (s.indexOf(".") >= 0);
if (n > 1 && pt > 0 && s.indexOf(')', pt + 1) == n - 1) s = s.substring(0, pt);
try {
if (isFloat) {
var f = Float.parseFloat(s);
if (this.asObject) return Float.$valueOf(f);
s = "" + f;
if (s.indexOf(".") < 0 && s.indexOf("E") < 0) s += ".0";
return s;
}var i = Integer.parseInt(s);
return (this.asObject ? Integer.$valueOf(i) : "" + i);
} catch (e) {
}
}}return (this.asObject ? s : JU.PT.esc(s));
}, "~S");
Clazz.defineMethod(c$, "fixLineFolding", 
function(str){
if (str.indexOf('\\') < 0) return str;
var n = str.length;
if (str.endsWith("\\\1")) str = str.substring(0, n - 1) + "\n\1";
var pt = 0;
while ((pt = str.indexOf('\\', pt + 1)) >= 0) {
var eol = str.indexOf('\n', pt);
if (eol < 0) break;
for (var i = eol; --i > pt; ) {
var ch = str.charAt(i);
if (!JU.PT.isWhitespace(ch)) {
if (ch == '\\') {
pt = i;
break;
}pt = eol;
break;
}}
if (pt < eol) str = str.substring(0, pt) + str.substring(eol + 1);
}
return str;
}, "~S");
c$.getArrayFromStringList = Clazz.defineMethod(c$, "getArrayFromStringList", 
function(s, n){
var f =  Clazz.newFloatArray (n, 0);
JU.PT.parseFloatArrayInfested(JU.PT.getTokens(s.$replace(',', ' ').$replace('[', ' ')), f);
var d =  Clazz.newDoubleArray (n, 0);
for (var i = 0; i < n; i++) d[i] = f[i];

return d;
}, "~S,~N");
c$.getIntArrayFromStringList = Clazz.defineMethod(c$, "getIntArrayFromStringList", 
function(s, n){
var f =  Clazz.newFloatArray (n, 0);
JU.PT.parseFloatArrayInfested(JU.PT.getTokens(s.$replace(',', ' ').$replace('[', ' ')), f);
var a =  Clazz.newIntArray (n, 0);
for (var i = 0; i < n; i++) a[i] = Clazz.floatToInt(f[i]);

return a;
}, "~S,~N");
});
;//5.0.1-v2 Tue Jul 23 17:25:20 CDT 2024
