ludc
2023-08-24 56c45e1f4be85d6bbfb3a03437021c6742b32ad9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var attregexg=/\b[\w:-]+=["'][^"]*['"]/g;
var tagregex=/<[^>]*>/g;
var nsregex=/<\w*:/, nsregex2 = /<(\/?)\w+:/;
function parsexmltag(tag, skip_root) {
    var z = [];
    var eq = 0, c = 0;
    for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
    if(!skip_root) z[0] = tag.substr(0, eq);
    if(eq === tag.length) return z;
    var m = tag.match(attregexg), j=0, w="", v="", i=0, q="", cc="";
    if(m) for(i = 0; i != m.length; ++i) {
        cc = m[i];
        for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
        q = cc.substr(0,c); v = cc.substring(c+2, cc.length-1);
        for(j=0;j!=q.length;++j) if(q.charCodeAt(j) === 58) break;
        if(j===q.length) z[q] = v;
        else z[(j===5 && q.substr(0,5)==="xmlns"?"xmlns":"")+q.substr(j+1)] = v;
    }
    return z;
}
function strip_ns(x) { return x.replace(nsregex2, "<$1"); }
 
var encodings = {
    '&quot;': '"',
    '&apos;': "'",
    '&gt;': '>',
    '&lt;': '<',
    '&amp;': '&'
};
var rencoding = {
    '"': '&quot;',
    "'": '&apos;',
    '>': '&gt;',
    '<': '&lt;',
    '&': '&amp;'
};
var rencstr = "&<>'\"".split("");
 
// TODO: CP remap (need to read file version to determine OS)
var encregex = /&[a-z]*;/g, coderegex = /_x([\da-fA-F]+)_/g;
function unescapexml(text){
    var s = text + '';
    return s.replace(encregex, function($$) { return encodings[$$]; }).replace(coderegex,function(m,c) {return String.fromCharCode(parseInt(c,16));});
}
var decregex=/[&<>'"]/g, charegex = /[\u0000-\u0008\u000b-\u001f]/g;
function escapexml(text){
    var s = text + '';
    return s.replace(decregex, function(y) { return rencoding[y]; }).replace(charegex,function(s) { return "_x" + ("000"+s.charCodeAt(0).toString(16)).substr(-4) + "_";});
}
 
function parsexmlbool(value, tag) {
    switch(value) {
        case '1': case 'true': case 'TRUE': return true;
        /* case '0': case 'false': case 'FALSE':*/
        default: return false;
    }
}
 
function datenum(v) {
    var epoch = Date.parse(v);
    return (epoch + 2209161600000) / (24 * 60 * 60 * 1000);
}
 
/* ISO 8601 Duration */
function parse_isodur(s) {
    var sec = 0, mt = 0, time = false;
    var m = s.match(/P([0-9\.]+Y)?([0-9\.]+M)?([0-9\.]+D)?T([0-9\.]+H)?([0-9\.]+M)?([0-9\.]+S)?/);
    if(!m) throw new Error("|" + s + "| is not an ISO8601 Duration");
    for(var i = 1; i != m.length; ++i) {
        if(!m[i]) continue;
        mt = 1;
        if(i > 3) time = true;
        switch(m[i].substr(m[i].length-1)) {
            case 'Y':
                throw new Error("Unsupported ISO Duration Field: " + m[i].substr(m[i].length-1));
            case 'D': mt *= 24;
                /* falls through */
            case 'H': mt *= 60;
                /* falls through */
            case 'M':
                if(!time) throw new Error("Unsupported ISO Duration Field: M");
                else mt *= 60;
                /* falls through */
            case 'S': break;
        }
        sec += mt * parseInt(m[i], 10);
    }
    return sec;
}