// Roman Numerals Column function OnInit(initData) { initData.name = "Roman Numerals Column"; initData.desc = "A column showing file names with roman numerals converted to numbers"; initData.version = "1.0"; initData.default_enable = true; var col = initData.AddColumn(); col.name = "RomanNumerals"; col.method = "OnRomanNumerals"; col.label = "Roman Numerals"; col.justify = "left"; col.autogroup = true; col.namerefresh = true; col.autorefresh = false; } // Implement the RomanNumerals column function OnRomanNumerals(scriptColData) { if (scriptColData.col != "RomanNumerals") return; scriptColData.value = deromWords(scriptColData.item.name_stem) + scriptColData.item.ext; } function deromWords(str) { var out = ""; var num; var words = str.split(" "); for (var widx in words) { if (widx > 0) out += " "; num = deromanize(words[widx]); if (num == 0) out += words[widx]; else out += num; } return out; } function deromanize(str) { var str = str.toUpperCase(), validator = /^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/, token = /[MDLV]|C[MD]?|X[CL]?|I[XV]?/g, key = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}, num = 0, m; if (!(str && validator.test(str))) return 0; while (m = token.exec(str)) num += key[m[0]]; if (num > 0) { num = String(num); while (num.length < 4) num = "0" + num; } return num; }