MSIBuild/String.js
Simon Rozman ac5ec66f3e Switch to SPDX license notice
Signed-off-by: Simon Rozman <simon@rozman.si>
2021-11-22 13:02:04 +01:00

156 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 1991-2021 Amebis
Copyright © 2016 GÉANT
*/
/*@cc_on @*/
/*@if (! @__STRING_JS__) @*/
/*@set @__STRING_JS__ = true @*/
var _S_stat = null;
function _S(str)
{
if (!_S_stat) {
_S_stat = {
"re_apost": new RegExp("'", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(_S_stat.re_apost, "''");
}
var _MSI_stat = null;
function _MSI(str)
{
if (!_MSI_stat) {
_MSI_stat = {
"re_nonid": new RegExp("[^a-zA-Z0-9_\\.]", "g"),
"re_noninitial": new RegExp("^([^a-zA-Z_])", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(_MSI_stat.re_nonid, "_").replace(_MSI_stat.re_noninitial, "_\\1");
}
var LF2CRLF_stat = null;
function LF2CRLF(str)
{
if (!LF2CRLF_stat) {
LF2CRLF_stat = {
"re_lf": new RegExp("\n", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(LF2CRLF_stat.re_lf, "\r\n");
}
var CRLF2LF_stat = null;
function CRLF2LF(str)
{
if (!CRLF2LF_stat) {
CRLF2LF_stat = {
"re_crlf": new RegExp("\r\n", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(CRLF2LF_stat.re_crlf, "\n");
}
var Trim_stat = null;
function Trim(str)
{
if (!Trim_stat) {
Trim_stat = {
"re_lspace": new RegExp("\\s+$", "g"),
"re_rspace": new RegExp("^\\s+", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(Trim_stat.re_lspace, "").replace(Trim_stat.re_rspace, "");
}
function Time2Str(date)
{
var
time = new Array(date.getHours(), date.getMinutes(), date.getSeconds()),
i, str = "";
for (i = 0; i < 3; i++) {
if (i) str += ":";
if (time[i] < 10) str += "0";
str += time[i];
}
return str;
}
function CodePageToId(codepage)
{
switch (codepage) {
case 0: {
var wsh = new ActiveXObject("WScript.Shell");
return CodePageToId(parseInt(wsh.RegRead("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP"), 10));
}
case 932 : return "shift-jis";
case 936 : return "gb2312";
case 949 : return "euc-kr";
case 950 : return "big5";
case 874 :
case 1250 :
case 1251 :
case 1252 :
case 1253 :
case 1254 :
case 1255 :
case 1256 :
case 1257 :
case 1258 : return "windows-" + codepage.toString(10);
case 65001: return "utf-8";
default : throw new Error("Unsupported code page.");
}
}
/*@end @*/