@reportman/engine 0.0.0-stage → 4.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/data/columns.d.ts +50 -0
- package/dist/data/columns.d.ts.map +1 -0
- package/dist/data/columns.js +385 -0
- package/dist/data/columns.js.map +1 -0
- package/dist/data/databaseinfo.d.ts +41 -0
- package/dist/data/databaseinfo.d.ts.map +1 -0
- package/dist/data/databaseinfo.js +145 -0
- package/dist/data/databaseinfo.js.map +1 -0
- package/dist/data/datainfo.d.ts +82 -0
- package/dist/data/datainfo.d.ts.map +1 -0
- package/dist/data/datainfo.js +449 -0
- package/dist/data/datainfo.js.map +1 -0
- package/dist/data/errors.d.ts +8 -0
- package/dist/data/errors.d.ts.map +1 -0
- package/dist/data/errors.js +14 -0
- package/dist/data/errors.js.map +1 -0
- package/dist/data/host.d.ts +132 -0
- package/dist/data/host.d.ts.map +1 -0
- package/dist/data/host.js +108 -0
- package/dist/data/host.js.map +1 -0
- package/dist/data/op.d.ts +21 -0
- package/dist/data/op.d.ts.map +1 -0
- package/dist/data/op.js +97 -0
- package/dist/data/op.js.map +1 -0
- package/dist/data/reportdataset.d.ts +116 -0
- package/dist/data/reportdataset.d.ts.map +1 -0
- package/dist/data/reportdataset.js +396 -0
- package/dist/data/reportdataset.js.map +1 -0
- package/dist/data/transfer.d.ts +46 -0
- package/dist/data/transfer.d.ts.map +1 -0
- package/dist/data/transfer.js +100 -0
- package/dist/data/transfer.js.map +1 -0
- package/dist/data/union.d.ts +88 -0
- package/dist/data/union.d.ts.map +1 -0
- package/dist/data/union.js +733 -0
- package/dist/data/union.js.map +1 -0
- package/dist/eval/chinesetables.d.ts +5 -0
- package/dist/eval/chinesetables.d.ts.map +1 -0
- package/dist/eval/chinesetables.js +8 -0
- package/dist/eval/chinesetables.js.map +1 -0
- package/dist/eval/evaluator.d.ts +100 -0
- package/dist/eval/evaluator.d.ts.map +1 -0
- package/dist/eval/evaluator.js +667 -0
- package/dist/eval/evaluator.js.map +1 -0
- package/dist/eval/exception.d.ts +9 -0
- package/dist/eval/exception.d.ts.map +1 -0
- package/dist/eval/exception.js +15 -0
- package/dist/eval/exception.js.map +1 -0
- package/dist/eval/fields.d.ts +60 -0
- package/dist/eval/fields.d.ts.map +1 -0
- package/dist/eval/fields.js +104 -0
- package/dist/eval/fields.js.map +1 -0
- package/dist/eval/functions.d.ts +27 -0
- package/dist/eval/functions.d.ts.map +1 -0
- package/dist/eval/functions.js +810 -0
- package/dist/eval/functions.js.map +1 -0
- package/dist/eval/identifiers.d.ts +100 -0
- package/dist/eval/identifiers.d.ts.map +1 -0
- package/dist/eval/identifiers.js +195 -0
- package/dist/eval/identifiers.js.map +1 -0
- package/dist/eval/parser.d.ts +47 -0
- package/dist/eval/parser.d.ts.map +1 -0
- package/dist/eval/parser.js +336 -0
- package/dist/eval/parser.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/params/param.d.ts +92 -0
- package/dist/params/param.d.ts.map +1 -0
- package/dist/params/param.js +358 -0
- package/dist/params/param.js.map +1 -0
- package/dist/params/parameters.d.ts +87 -0
- package/dist/params/parameters.d.ts.map +1 -0
- package/dist/params/parameters.js +499 -0
- package/dist/params/parameters.js.map +1 -0
- package/dist/report/barcode/barcodeitem.d.ts +76 -0
- package/dist/report/barcode/barcodeitem.d.ts.map +1 -0
- package/dist/report/barcode/barcodeitem.js +864 -0
- package/dist/report/barcode/barcodeitem.js.map +1 -0
- package/dist/report/barcode/code128.d.ts +18 -0
- package/dist/report/barcode/code128.d.ts.map +1 -0
- package/dist/report/barcode/code128.js +187 -0
- package/dist/report/barcode/code128.js.map +1 -0
- package/dist/report/barcode/netutil.d.ts +30 -0
- package/dist/report/barcode/netutil.d.ts.map +1 -0
- package/dist/report/barcode/netutil.js +65 -0
- package/dist/report/barcode/netutil.js.map +1 -0
- package/dist/report/barcode/pdf417.d.ts +17 -0
- package/dist/report/barcode/pdf417.d.ts.map +1 -0
- package/dist/report/barcode/pdf417.js +782 -0
- package/dist/report/barcode/pdf417.js.map +1 -0
- package/dist/report/barcode/pdf417tables.d.ts +11 -0
- package/dist/report/barcode/pdf417tables.d.ts.map +1 -0
- package/dist/report/barcode/pdf417tables.js +880 -0
- package/dist/report/barcode/pdf417tables.js.map +1 -0
- package/dist/report/barcode/qrcode.d.ts +14 -0
- package/dist/report/barcode/qrcode.d.ts.map +1 -0
- package/dist/report/barcode/qrcode.js +214 -0
- package/dist/report/barcode/qrcode.js.map +1 -0
- package/dist/report/barcode/zxingwidth.d.ts +4 -0
- package/dist/report/barcode/zxingwidth.d.ts.map +1 -0
- package/dist/report/barcode/zxingwidth.js +247 -0
- package/dist/report/barcode/zxingwidth.js.map +1 -0
- package/dist/report/chart/chartidens.d.ts +70 -0
- package/dist/report/chart/chartidens.d.ts.map +1 -0
- package/dist/report/chart/chartidens.js +162 -0
- package/dist/report/chart/chartidens.js.map +1 -0
- package/dist/report/chart/chartitem.d.ts +110 -0
- package/dist/report/chart/chartitem.d.ts.map +1 -0
- package/dist/report/chart/chartitem.js +403 -0
- package/dist/report/chart/chartitem.js.map +1 -0
- package/dist/report/chart/series.d.ts +65 -0
- package/dist/report/chart/series.d.ts.map +1 -0
- package/dist/report/chart/series.js +74 -0
- package/dist/report/chart/series.js.map +1 -0
- package/dist/report/chart/vectorchart.d.ts +18 -0
- package/dist/report/chart/vectorchart.d.ts.map +1 -0
- package/dist/report/chart/vectorchart.js +356 -0
- package/dist/report/chart/vectorchart.js.map +1 -0
- package/dist/report/convert.d.ts +4 -0
- package/dist/report/convert.d.ts.map +1 -0
- package/dist/report/convert.js +162 -0
- package/dist/report/convert.js.map +1 -0
- package/dist/report/errors.d.ts +13 -0
- package/dist/report/errors.d.ts.map +1 -0
- package/dist/report/errors.js +20 -0
- package/dist/report/errors.js.map +1 -0
- package/dist/report/identifiers.d.ts +91 -0
- package/dist/report/identifiers.d.ts.map +1 -0
- package/dist/report/identifiers.js +404 -0
- package/dist/report/identifiers.js.map +1 -0
- package/dist/report/imageitem.d.ts +66 -0
- package/dist/report/imageitem.d.ts.map +1 -0
- package/dist/report/imageitem.js +190 -0
- package/dist/report/imageitem.js.map +1 -0
- package/dist/report/items.d.ts +219 -0
- package/dist/report/items.d.ts.map +1 -0
- package/dist/report/items.js +1015 -0
- package/dist/report/items.js.map +1 -0
- package/dist/report/report.d.ts +221 -0
- package/dist/report/report.d.ts.map +1 -0
- package/dist/report/report.js +1974 -0
- package/dist/report/report.js.map +1 -0
- package/dist/report/run.d.ts +87 -0
- package/dist/report/run.d.ts.map +1 -0
- package/dist/report/run.js +121 -0
- package/dist/report/run.js.map +1 -0
- package/dist/report/section.d.ts +86 -0
- package/dist/report/section.d.ts.map +1 -0
- package/dist/report/section.js +325 -0
- package/dist/report/section.js.map +1 -0
- package/dist/report/subreport.d.ts +49 -0
- package/dist/report/subreport.d.ts.map +1 -0
- package/dist/report/subreport.js +220 -0
- package/dist/report/subreport.js.map +1 -0
- package/dist/util/base64.d.ts +9 -0
- package/dist/util/base64.d.ts.map +1 -0
- package/dist/util/base64.js +60 -0
- package/dist/util/base64.js.map +1 -0
- package/dist/util/chars.d.ts +45 -0
- package/dist/util/chars.d.ts.map +1 -0
- package/dist/util/chars.js +194 -0
- package/dist/util/chars.js.map +1 -0
- package/dist/util/compositeformat.d.ts +3 -0
- package/dist/util/compositeformat.d.ts.map +1 -0
- package/dist/util/compositeformat.js +99 -0
- package/dist/util/compositeformat.js.map +1 -0
- package/dist/util/culture.d.ts +84 -0
- package/dist/util/culture.d.ts.map +1 -0
- package/dist/util/culture.js +59 -0
- package/dist/util/culture.js.map +1 -0
- package/dist/util/cultures.generated.d.ts +3 -0
- package/dist/util/cultures.generated.d.ts.map +1 -0
- package/dist/util/cultures.generated.js +1043 -0
- package/dist/util/cultures.generated.js.map +1 -0
- package/dist/util/dateformat.d.ts +21 -0
- package/dist/util/dateformat.d.ts.map +1 -0
- package/dist/util/dateformat.js +439 -0
- package/dist/util/dateformat.js.map +1 -0
- package/dist/util/dateparse.d.ts +12 -0
- package/dist/util/dateparse.d.ts.map +1 -0
- package/dist/util/dateparse.js +1212 -0
- package/dist/util/dateparse.js.map +1 -0
- package/dist/util/datetime.d.ts +70 -0
- package/dist/util/datetime.d.ts.map +1 -0
- package/dist/util/datetime.js +265 -0
- package/dist/util/datetime.js.map +1 -0
- package/dist/util/decimal.d.ts +54 -0
- package/dist/util/decimal.d.ts.map +1 -0
- package/dist/util/decimal.js +365 -0
- package/dist/util/decimal.js.map +1 -0
- package/dist/util/delphidateformat.d.ts +34 -0
- package/dist/util/delphidateformat.d.ts.map +1 -0
- package/dist/util/delphidateformat.js +247 -0
- package/dist/util/delphidateformat.js.map +1 -0
- package/dist/util/delphiformatsettings.generated.d.ts +3 -0
- package/dist/util/delphiformatsettings.generated.d.ts.map +1 -0
- package/dist/util/delphiformatsettings.generated.js +15 -0
- package/dist/util/delphiformatsettings.generated.js.map +1 -0
- package/dist/util/delphitext.d.ts +40 -0
- package/dist/util/delphitext.d.ts.map +1 -0
- package/dist/util/delphitext.js +408 -0
- package/dist/util/delphitext.js.map +1 -0
- package/dist/util/doubleutil.d.ts +30 -0
- package/dist/util/doubleutil.d.ts.map +1 -0
- package/dist/util/doubleutil.js +651 -0
- package/dist/util/doubleutil.js.map +1 -0
- package/dist/util/inflate.d.ts +7 -0
- package/dist/util/inflate.d.ts.map +1 -0
- package/dist/util/inflate.js +256 -0
- package/dist/util/inflate.js.map +1 -0
- package/dist/util/netexception.d.ts +59 -0
- package/dist/util/netexception.d.ts.map +1 -0
- package/dist/util/netexception.js +94 -0
- package/dist/util/netexception.js.map +1 -0
- package/dist/util/numberformat.d.ts +14 -0
- package/dist/util/numberformat.d.ts.map +1 -0
- package/dist/util/numberformat.js +828 -0
- package/dist/util/numberformat.js.map +1 -0
- package/dist/util/numberparse.d.ts +49 -0
- package/dist/util/numberparse.d.ts.map +1 -0
- package/dist/util/numberparse.js +568 -0
- package/dist/util/numberparse.js.map +1 -0
- package/dist/util/reportmanres.en.generated.d.ts +2 -0
- package/dist/util/reportmanres.en.generated.d.ts.map +1 -0
- package/dist/util/reportmanres.en.generated.js +2082 -0
- package/dist/util/reportmanres.en.generated.js.map +1 -0
- package/dist/util/reportmanres.es.generated.d.ts +2 -0
- package/dist/util/reportmanres.es.generated.d.ts.map +1 -0
- package/dist/util/reportmanres.es.generated.js +2082 -0
- package/dist/util/reportmanres.es.generated.js.map +1 -0
- package/dist/util/translator.d.ts +29 -0
- package/dist/util/translator.d.ts.map +1 -0
- package/dist/util/translator.js +79 -0
- package/dist/util/translator.js.map +1 -0
- package/dist/variant/coercion.d.ts +9 -0
- package/dist/variant/coercion.d.ts.map +1 -0
- package/dist/variant/coercion.js +298 -0
- package/dist/variant/coercion.js.map +1 -0
- package/dist/variant/context.d.ts +30 -0
- package/dist/variant/context.d.ts.map +1 -0
- package/dist/variant/context.js +22 -0
- package/dist/variant/context.js.map +1 -0
- package/dist/variant/variant.d.ts +193 -0
- package/dist/variant/variant.d.ts.map +1 -0
- package/dist/variant/variant.js +1235 -0
- package/dist/variant/variant.js.map +1 -0
- package/package.json +35 -4
- package/README.md +0 -3
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
// Port of Reportman.Reporting.EvalFunctions: the built-in functions of the expression language.
|
|
2
|
+
// The C# behaviours are kept as they are, including the odd ones (see the "C# parity" notes).
|
|
3
|
+
import { argumentNull, indexOfCulture, replaceNet, substringNet, toLowerNet, toUpperNet, trimNet, } from '../util/chars.js';
|
|
4
|
+
import { fromBase64String } from '../util/base64.js';
|
|
5
|
+
import { compareValue, numberToText, roundDecimalUp } from '../util/doubleutil.js';
|
|
6
|
+
import { argumentException, NamedException, nullReferenceException, UnNamedException, divideByZeroException, overflowException, NetMessages } from '../util/netexception.js';
|
|
7
|
+
import { convertDecimalToInt64, NumberStyles, parseDecimal, parseDouble, parseInt32, roundHalfEvenDouble } from '../util/numberparse.js';
|
|
8
|
+
import { parseDateTime } from '../util/dateparse.js';
|
|
9
|
+
import { DateTimeKind, RpDateTime } from '../util/datetime.js';
|
|
10
|
+
import { ansiDecode, ansiEncode, formatMaskText, indyBase64Decode, iniReadString, utf8Decode } from '../util/delphitext.js';
|
|
11
|
+
import { TO_SIMPLIFIED_FROM, TO_SIMPLIFIED_TO, TO_TRADITIONAL_FROM, TO_TRADITIONAL_TO } from './chinesetables.js';
|
|
12
|
+
import { ParamType, Variant, VariantType } from '../variant/variant.js';
|
|
13
|
+
import { IdenFalse, IdenFunction, IdenNull, IdenTrue } from './identifiers.js';
|
|
14
|
+
class BuiltinFunction extends IdenFunction {
|
|
15
|
+
constructor(evaluator, name, paramCount, model = '') {
|
|
16
|
+
super(evaluator);
|
|
17
|
+
this.setParamCount(paramCount);
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.fModel = model;
|
|
20
|
+
}
|
|
21
|
+
get ev() {
|
|
22
|
+
return this.evalObject;
|
|
23
|
+
}
|
|
24
|
+
get ctx() {
|
|
25
|
+
return this.evalObject.context;
|
|
26
|
+
}
|
|
27
|
+
typeError(name) {
|
|
28
|
+
return new NamedException(this.translate(438), name);
|
|
29
|
+
}
|
|
30
|
+
/** (string)Params[i] with the null of a non text value. */
|
|
31
|
+
str(i) {
|
|
32
|
+
return this.params[i].toImplicitString(this.ctx);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** A .NET string method called on a null string reference. */
|
|
36
|
+
function notNull(s) {
|
|
37
|
+
if (s === null)
|
|
38
|
+
throw nullReferenceException();
|
|
39
|
+
return s;
|
|
40
|
+
}
|
|
41
|
+
class IdenSinus extends BuiltinFunction {
|
|
42
|
+
constructor(e) {
|
|
43
|
+
super(e, 'SIN', 1, 'function Sin(value:double):double');
|
|
44
|
+
}
|
|
45
|
+
getValue() {
|
|
46
|
+
const p = this.params[0];
|
|
47
|
+
if (p.varType === VariantType.Null)
|
|
48
|
+
return Variant.null;
|
|
49
|
+
if (!p.isNumber())
|
|
50
|
+
throw this.typeError('SIN');
|
|
51
|
+
return Variant.fromDouble(Math.sin(p.toDouble(this.ctx)));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class IdenMax extends BuiltinFunction {
|
|
55
|
+
constructor(e) {
|
|
56
|
+
super(e, 'MAX', 2, 'function Max(value1,value2:Variant):Variant');
|
|
57
|
+
}
|
|
58
|
+
getValue() {
|
|
59
|
+
if (this.params[0].varType === VariantType.Null)
|
|
60
|
+
throw this.typeError('MAX');
|
|
61
|
+
if (this.params[1].varType === VariantType.Null)
|
|
62
|
+
throw this.typeError('MAX');
|
|
63
|
+
return Variant.greaterThan(this.params[0], this.params[1], this.ctx) ? this.params[0] : this.params[1];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class IdenUpperCase extends BuiltinFunction {
|
|
67
|
+
constructor(e) {
|
|
68
|
+
super(e, 'UPPERCASE', 1, 'function UpperCase(value:string):string');
|
|
69
|
+
}
|
|
70
|
+
getValue() {
|
|
71
|
+
const p = this.params[0];
|
|
72
|
+
if (p.varType === VariantType.Null)
|
|
73
|
+
return Variant.null;
|
|
74
|
+
if (p.varType !== VariantType.String)
|
|
75
|
+
throw this.typeError('UPPERCASE');
|
|
76
|
+
return Variant.fromString(toUpperNet(p.toString(this.ctx)));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class IdenStringToBin extends BuiltinFunction {
|
|
80
|
+
constructor(e) {
|
|
81
|
+
super(e, 'STRINGTOBIN', 1, 'function StringToBin(value:string):binary');
|
|
82
|
+
}
|
|
83
|
+
getValue() {
|
|
84
|
+
const p = this.params[0];
|
|
85
|
+
if (p.varType === VariantType.Null)
|
|
86
|
+
return Variant.null;
|
|
87
|
+
if (p.varType !== VariantType.String)
|
|
88
|
+
throw this.typeError('STRINGTOBIN');
|
|
89
|
+
return Variant.fromBinary(fromBase64String(p.toString(this.ctx)));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
class IdenDay extends BuiltinFunction {
|
|
93
|
+
constructor(e) {
|
|
94
|
+
super(e, 'DAY', 1, 'function DAY(value:DateTime):Integer');
|
|
95
|
+
}
|
|
96
|
+
getValue() {
|
|
97
|
+
const p = this.params[0];
|
|
98
|
+
if (p.varType === VariantType.Null)
|
|
99
|
+
return Variant.null;
|
|
100
|
+
if (p.varType !== VariantType.DateTime)
|
|
101
|
+
throw this.typeError('DAY');
|
|
102
|
+
return Variant.fromInteger(p.toDateTime(this.ctx).day);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
class IdenMonth extends BuiltinFunction {
|
|
106
|
+
constructor(e) {
|
|
107
|
+
super(e, 'MONTH', 1, 'function MONTH(value:DateTime):Integer');
|
|
108
|
+
}
|
|
109
|
+
getValue() {
|
|
110
|
+
const p = this.params[0];
|
|
111
|
+
if (p.varType === VariantType.Null)
|
|
112
|
+
return Variant.null;
|
|
113
|
+
if (p.varType !== VariantType.DateTime)
|
|
114
|
+
throw this.typeError('MONTH');
|
|
115
|
+
return Variant.fromInteger(p.toDateTime(this.ctx).month);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const MONTH_NAMES = {
|
|
119
|
+
0: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
|
120
|
+
1: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Setiembre', 'Octubre', 'Noviembre', 'Diciembre'],
|
|
121
|
+
2: ['Gener', 'Febrer', 'Mar\u00e7', 'Abril', 'Maig', 'Juny', 'Juliol', 'Agost', 'Setembre', 'Octubre', 'Novembre', 'Desembre'],
|
|
122
|
+
};
|
|
123
|
+
/** MonthName: the English (0), Spanish (1) or Catalan (2) name; "" otherwise. */
|
|
124
|
+
export function getMonthName(month, language) {
|
|
125
|
+
const names = MONTH_NAMES[language];
|
|
126
|
+
if (names === undefined || month < 1 || month > 12)
|
|
127
|
+
return '';
|
|
128
|
+
return names[month - 1];
|
|
129
|
+
}
|
|
130
|
+
class IdenMonthName extends BuiltinFunction {
|
|
131
|
+
constructor(e) {
|
|
132
|
+
super(e, 'MONTHNAME', 1, 'function MonthName(value:Integer,DateTime):string');
|
|
133
|
+
}
|
|
134
|
+
getValue() {
|
|
135
|
+
const p = this.params[0];
|
|
136
|
+
if (p.varType === VariantType.Null)
|
|
137
|
+
return Variant.null;
|
|
138
|
+
if (p.varType === VariantType.Integer)
|
|
139
|
+
return Variant.fromString(getMonthName(p.toInt(this.ctx), this.ev.language));
|
|
140
|
+
if (p.varType === VariantType.DateTime)
|
|
141
|
+
return Variant.fromString(getMonthName(p.toDateTime(this.ctx).month, this.ev.language));
|
|
142
|
+
throw this.typeError('MONTHNAME');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
class IdenYear extends BuiltinFunction {
|
|
146
|
+
constructor(e) {
|
|
147
|
+
super(e, 'Year', 1, 'function Year(value:DateTime):Integer');
|
|
148
|
+
}
|
|
149
|
+
getValue() {
|
|
150
|
+
const p = this.params[0];
|
|
151
|
+
if (p.varType === VariantType.Null)
|
|
152
|
+
return Variant.null;
|
|
153
|
+
if (p.varType === VariantType.DateTime)
|
|
154
|
+
return Variant.fromInteger(p.toDateTime(this.ctx).year);
|
|
155
|
+
// C# parity: the error names MONTHNAME.
|
|
156
|
+
throw this.typeError('MONTHNAME');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
class IdenFormatStr extends BuiltinFunction {
|
|
160
|
+
constructor(e) {
|
|
161
|
+
super(e, 'FORMATSTR', 2, 'function FormatStr(format:string, value:Variant):string');
|
|
162
|
+
}
|
|
163
|
+
getValue() {
|
|
164
|
+
if (this.params[0].varType !== VariantType.String)
|
|
165
|
+
throw this.typeError('FORMATSTR');
|
|
166
|
+
const format = this.str(0);
|
|
167
|
+
// C# parity: Params[0] cannot be Null here (checked above); the assignment is kept.
|
|
168
|
+
if (this.params[0].varType === VariantType.Null)
|
|
169
|
+
this.params[0] = Variant.fromString('');
|
|
170
|
+
return Variant.fromString(this.params[1].toFormatString(this.ctx, format, ParamType.Unknown, true));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
class IdenTrim extends BuiltinFunction {
|
|
174
|
+
constructor(e) {
|
|
175
|
+
super(e, 'TRIM', 1, 'function Trim(value:string):string');
|
|
176
|
+
}
|
|
177
|
+
getValue() {
|
|
178
|
+
const p = this.params[0];
|
|
179
|
+
if (p.varType === VariantType.Null)
|
|
180
|
+
return Variant.null;
|
|
181
|
+
if (p.varType !== VariantType.String)
|
|
182
|
+
throw this.typeError('TRIM');
|
|
183
|
+
return Variant.fromString(trimNet(p.toString(this.ctx)));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
class IdenLeft extends BuiltinFunction {
|
|
187
|
+
constructor(e) {
|
|
188
|
+
super(e, 'Left', 2, 'function Left(value:string, count:integer):string');
|
|
189
|
+
}
|
|
190
|
+
getValue() {
|
|
191
|
+
if (this.params[0].varType === VariantType.Null)
|
|
192
|
+
return Variant.null;
|
|
193
|
+
const astring = this.str(0);
|
|
194
|
+
let count = this.params[1].toInt(this.ctx);
|
|
195
|
+
const s = notNull(astring);
|
|
196
|
+
if (s.length < count)
|
|
197
|
+
count = s.length;
|
|
198
|
+
return Variant.fromString(substringNet(s, 0, count));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
class IdenReplaceStr extends BuiltinFunction {
|
|
202
|
+
constructor(e) {
|
|
203
|
+
super(e, 'REPLACESTR', 3, 'function Replace(const S:string, OldPattern,NewPattern: string):string');
|
|
204
|
+
}
|
|
205
|
+
getValue() {
|
|
206
|
+
if (this.params[0].varType !== VariantType.String)
|
|
207
|
+
throw this.typeError('S');
|
|
208
|
+
if (this.params[1].varType !== VariantType.String)
|
|
209
|
+
throw this.typeError('OldPattern');
|
|
210
|
+
if (this.params[2].varType !== VariantType.String)
|
|
211
|
+
throw this.typeError('NewPattern');
|
|
212
|
+
const source = this.params[0].toString(this.ctx);
|
|
213
|
+
const oldpattern = this.params[1].toString(this.ctx);
|
|
214
|
+
const newpattern = this.params[2].toString(this.ctx);
|
|
215
|
+
return Variant.fromString(replaceNet(source, oldpattern, newpattern));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
class IdenRight extends BuiltinFunction {
|
|
219
|
+
constructor(e) {
|
|
220
|
+
super(e, 'Right', 2, 'function Right(value:string, count:integer):string');
|
|
221
|
+
}
|
|
222
|
+
getValue() {
|
|
223
|
+
if (this.params[0].varType === VariantType.Null)
|
|
224
|
+
return Variant.null;
|
|
225
|
+
const astring = this.str(0);
|
|
226
|
+
let count = this.params[1].toInt(this.ctx);
|
|
227
|
+
const s = notNull(astring);
|
|
228
|
+
if (s.length < count)
|
|
229
|
+
count = s.length;
|
|
230
|
+
return Variant.fromString(substringNet(s, s.length - count, count));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
class IdenLength extends BuiltinFunction {
|
|
234
|
+
constructor(e) {
|
|
235
|
+
super(e, 'Length', 1, 'function Length(value:string):integer');
|
|
236
|
+
}
|
|
237
|
+
getValue() {
|
|
238
|
+
const p = this.params[0];
|
|
239
|
+
if (p.varType === VariantType.Null)
|
|
240
|
+
return Variant.fromInteger(0);
|
|
241
|
+
if (p.varType !== VariantType.String)
|
|
242
|
+
throw this.typeError('LENGTH');
|
|
243
|
+
return Variant.fromInteger(notNull(this.str(0)).length);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
class IdenIsInteger extends BuiltinFunction {
|
|
247
|
+
constructor(e) {
|
|
248
|
+
super(e, 'IsInteger', 1, 'function IsInteger(value:string):boolean');
|
|
249
|
+
}
|
|
250
|
+
getValue() {
|
|
251
|
+
if (this.params[0].varType !== VariantType.String)
|
|
252
|
+
throw this.typeError('ISINTEGER');
|
|
253
|
+
try {
|
|
254
|
+
parseInt32(this.str(0), NumberStyles.Integer, this.ctx.culture.number);
|
|
255
|
+
return Variant.fromBoolean(true);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return Variant.fromBoolean(false);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class IdenIsNumeric extends BuiltinFunction {
|
|
263
|
+
constructor(e) {
|
|
264
|
+
super(e, 'IsNumeric', 1, 'function IsNumeric(value:string):boolean');
|
|
265
|
+
}
|
|
266
|
+
getValue() {
|
|
267
|
+
if (this.params[0].varType !== VariantType.String)
|
|
268
|
+
throw this.typeError('ISNUMERIC');
|
|
269
|
+
try {
|
|
270
|
+
parseDouble(this.str(0), NumberStyles.Float | NumberStyles.AllowThousands, this.ctx.culture.number);
|
|
271
|
+
return Variant.fromBoolean(true);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return Variant.fromBoolean(false);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
class IdenIsValidDateTime extends BuiltinFunction {
|
|
279
|
+
constructor(e) {
|
|
280
|
+
super(e, 'IsValidDateTime', 1, 'function IsValidDateTime(value:string):boolean');
|
|
281
|
+
}
|
|
282
|
+
getValue() {
|
|
283
|
+
if (this.params[0].varType !== VariantType.String)
|
|
284
|
+
throw this.typeError('ISVALIDDATETIME');
|
|
285
|
+
try {
|
|
286
|
+
parseDateTime(this.str(0), this.ctx.culture, this.ctx.now(), this.ctx.timeZone);
|
|
287
|
+
return Variant.fromBoolean(true);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return Variant.fromBoolean(false);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
class IdenCheckExpression extends BuiltinFunction {
|
|
295
|
+
constructor(e) {
|
|
296
|
+
super(e, 'CheckExpression', 2, 'function CheckExpression(value:string):boolean');
|
|
297
|
+
}
|
|
298
|
+
getValue() {
|
|
299
|
+
if (this.params[0].varType !== VariantType.String)
|
|
300
|
+
throw this.typeError('CHECKEXPRESSION');
|
|
301
|
+
if (this.params[1].varType !== VariantType.String)
|
|
302
|
+
throw this.typeError('CHECKEXPRESSION');
|
|
303
|
+
const aresult = this.ev.evaluateText(this.str(0));
|
|
304
|
+
if (Variant.equals(aresult, Variant.fromBoolean(false), this.ctx))
|
|
305
|
+
throw new UnNamedException(this.str(1));
|
|
306
|
+
return aresult;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
class IdenPos extends BuiltinFunction {
|
|
310
|
+
constructor(e) {
|
|
311
|
+
super(e, 'POS', 2, 'function Pos(substring,fullstring:string):integer');
|
|
312
|
+
}
|
|
313
|
+
getValue() {
|
|
314
|
+
if (this.params[0].varType === VariantType.Null)
|
|
315
|
+
return Variant.null;
|
|
316
|
+
const substring = this.str(0);
|
|
317
|
+
const fullstring = notNull(this.str(1));
|
|
318
|
+
if (substring === null)
|
|
319
|
+
throw argumentNull('value');
|
|
320
|
+
return Variant.fromInteger(indexOfCulture(fullstring, substring) + 1);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
class IdenSubStr extends BuiltinFunction {
|
|
324
|
+
constructor(e) {
|
|
325
|
+
super(e, 'SubStr', 3, 'function SubStr(value:string, index,count:integer):string');
|
|
326
|
+
}
|
|
327
|
+
getValue() {
|
|
328
|
+
if (this.params[0].varType === VariantType.Null)
|
|
329
|
+
return Variant.null;
|
|
330
|
+
const astring = notNull(this.str(0));
|
|
331
|
+
if (astring.length === 0)
|
|
332
|
+
return Variant.fromString('');
|
|
333
|
+
const index = this.params[1].toInt(this.ctx);
|
|
334
|
+
let count = this.params[2].toInt(this.ctx);
|
|
335
|
+
if (astring.length < ((count - index) | 0))
|
|
336
|
+
count = astring.length;
|
|
337
|
+
if (count <= 0)
|
|
338
|
+
return Variant.fromString('');
|
|
339
|
+
// SafeSubstring: Skip(startIndex).Take(length) over the UTF-16 code units.
|
|
340
|
+
const start = Math.max(0, (index - 1) | 0);
|
|
341
|
+
return Variant.fromString(astring.substring(start, Math.min(astring.length, start + count)));
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
class IdenLowerCase extends BuiltinFunction {
|
|
345
|
+
constructor(e) {
|
|
346
|
+
super(e, 'LOWERCASE', 1);
|
|
347
|
+
}
|
|
348
|
+
getValue() {
|
|
349
|
+
const p = this.params[0];
|
|
350
|
+
if (p.varType === VariantType.Null)
|
|
351
|
+
return Variant.null;
|
|
352
|
+
if (p.varType !== VariantType.String)
|
|
353
|
+
throw this.typeError('LOWERCASE');
|
|
354
|
+
return Variant.fromString(toLowerNet(p.toString(this.ctx)));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
class IdenFileExists extends BuiltinFunction {
|
|
358
|
+
constructor(e) {
|
|
359
|
+
super(e, 'FILEEXISTS', 1);
|
|
360
|
+
}
|
|
361
|
+
getValue() {
|
|
362
|
+
const p = this.params[0];
|
|
363
|
+
if (p.varType === VariantType.Null)
|
|
364
|
+
return Variant.fromBoolean(false);
|
|
365
|
+
if (p.varType !== VariantType.String)
|
|
366
|
+
throw new NamedException(this.translate(438), this.name);
|
|
367
|
+
const path = p.toString(this.ctx);
|
|
368
|
+
// new FileInfo("") throws
|
|
369
|
+
if (path.length === 0)
|
|
370
|
+
throw argumentException("The path is empty. (Parameter 'path')");
|
|
371
|
+
return Variant.fromBoolean(this.ev.host.fileExists(path));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
class IdenToday extends BuiltinFunction {
|
|
375
|
+
constructor(e) {
|
|
376
|
+
super(e, 'TODAY', 0);
|
|
377
|
+
}
|
|
378
|
+
getValue() {
|
|
379
|
+
return Variant.fromDateTime(this.ev.host.now().date.withKind(DateTimeKind.Local));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
class IdenNow extends BuiltinFunction {
|
|
383
|
+
constructor(e) {
|
|
384
|
+
super(e, 'NOW', 0);
|
|
385
|
+
}
|
|
386
|
+
getValue() {
|
|
387
|
+
return Variant.fromDateTime(this.ev.host.now().withKind(DateTimeKind.Local));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
class IdenStr extends BuiltinFunction {
|
|
391
|
+
constructor(e) {
|
|
392
|
+
super(e, 'STR', 1);
|
|
393
|
+
}
|
|
394
|
+
getValue() {
|
|
395
|
+
const p = this.params[0];
|
|
396
|
+
if (p.varType !== VariantType.Null)
|
|
397
|
+
return Variant.fromString(p.toString(this.ctx));
|
|
398
|
+
return Variant.fromString('');
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
class IdenFloatToDateTime extends BuiltinFunction {
|
|
402
|
+
constructor(e) {
|
|
403
|
+
super(e, 'FloatToDateTime', 1, 'function FloatToDateTime(value:double):DateTime');
|
|
404
|
+
}
|
|
405
|
+
getValue() {
|
|
406
|
+
// As Delphi (TIdenFloatToDateTime): a number is the date of its OLE value (the days since
|
|
407
|
+
// 30/12/1899, the time the fraction), a date is itself and null is null
|
|
408
|
+
const p = this.params[0];
|
|
409
|
+
if (p.varType === VariantType.DateTime)
|
|
410
|
+
return p;
|
|
411
|
+
if (p.varType === VariantType.Null)
|
|
412
|
+
return Variant.null;
|
|
413
|
+
if (!p.isNumber())
|
|
414
|
+
throw this.typeError('FloatToDateTime');
|
|
415
|
+
return Variant.fromDateTime(RpDateTime.fromOADate(p.toDouble(this.ctx)));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
class IdenRound extends BuiltinFunction {
|
|
419
|
+
constructor(e) {
|
|
420
|
+
super(e, 'Round', 2, 'function Round(num:double,r:double):double');
|
|
421
|
+
}
|
|
422
|
+
getValue() {
|
|
423
|
+
if (this.params[0].isNull)
|
|
424
|
+
return Variant.null;
|
|
425
|
+
if (!this.params[0].isNumber())
|
|
426
|
+
throw this.typeError('Round');
|
|
427
|
+
const num = this.params[0].toDecimal(this.ctx);
|
|
428
|
+
if (!this.params[1].isNumber())
|
|
429
|
+
throw this.typeError('Round');
|
|
430
|
+
// C# parity: the multiple is read from Params[0], not Params[1].
|
|
431
|
+
const r = this.params[0].toDecimal(this.ctx);
|
|
432
|
+
return Variant.fromDecimal(roundDecimalUp(num, r));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
class IdenRoundToInteger extends BuiltinFunction {
|
|
436
|
+
constructor(e) {
|
|
437
|
+
super(e, 'RoundToInteger', 1, 'function RoundToInteger(num:double):integer');
|
|
438
|
+
}
|
|
439
|
+
getValue() {
|
|
440
|
+
if (!this.params[0].isNumber())
|
|
441
|
+
throw this.typeError('RoundToInteger');
|
|
442
|
+
const num = this.params[0].toDecimal(this.ctx);
|
|
443
|
+
return Variant.fromLong(convertDecimalToInt64(num.round()));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
class IdenAbs extends BuiltinFunction {
|
|
447
|
+
constructor(e) {
|
|
448
|
+
super(e, 'Abs', 1, 'function Abs(num:double):double');
|
|
449
|
+
}
|
|
450
|
+
getValue() {
|
|
451
|
+
if (!this.params[0].isNumber())
|
|
452
|
+
throw this.typeError('Abs');
|
|
453
|
+
return this.params[0].abs(this.ctx);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
class IdenCompareValue extends BuiltinFunction {
|
|
457
|
+
constructor(e) {
|
|
458
|
+
super(e, 'CompareValue', 3, 'function CompareValue(p1,p2,epsilon:double):integer');
|
|
459
|
+
}
|
|
460
|
+
getValue() {
|
|
461
|
+
if (!this.params[0].isNumber())
|
|
462
|
+
throw this.typeError('CompareValue');
|
|
463
|
+
if (!this.params[1].isNumber())
|
|
464
|
+
throw this.typeError('CompareValue');
|
|
465
|
+
if (!this.params[2].isNumber())
|
|
466
|
+
throw this.typeError('CompareValue');
|
|
467
|
+
const p1 = this.params[0].toDecimal(this.ctx);
|
|
468
|
+
const p2 = this.params[1].toDecimal(this.ctx);
|
|
469
|
+
const p3 = this.params[2].toDecimal(this.ctx);
|
|
470
|
+
return Variant.fromInteger(compareValue(p1, p2, p3));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
class IdenInt extends BuiltinFunction {
|
|
474
|
+
constructor(e) {
|
|
475
|
+
super(e, 'Int', 1, 'function Int(num:double):integer');
|
|
476
|
+
}
|
|
477
|
+
getValue() {
|
|
478
|
+
if (!this.params[0].isNumber())
|
|
479
|
+
throw this.typeError('Int');
|
|
480
|
+
const num = this.params[0].toDecimal(this.ctx);
|
|
481
|
+
return Variant.fromLong(convertDecimalToInt64(num.truncate()));
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
class IdenVal extends BuiltinFunction {
|
|
485
|
+
constructor(e) {
|
|
486
|
+
super(e, 'Val', 1, 'function Val(s:string):double');
|
|
487
|
+
}
|
|
488
|
+
getValue() {
|
|
489
|
+
// As Delphi (TIdenVal): a number is itself, a text is converted (VAL('12') is 12)
|
|
490
|
+
if (this.params[0].isNumber())
|
|
491
|
+
return this.params[0];
|
|
492
|
+
if (!this.params[0].isString())
|
|
493
|
+
throw this.typeError('Val');
|
|
494
|
+
const astring = notNull(this.str(0));
|
|
495
|
+
if (astring.length < 1)
|
|
496
|
+
return Variant.fromInteger(0);
|
|
497
|
+
return Variant.fromDecimal(parseDecimal(astring, NumberStyles.Number, this.ctx.culture.number));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
class IdenModul extends BuiltinFunction {
|
|
501
|
+
constructor(e) {
|
|
502
|
+
super(e, 'Mod', 2, 'function Mod(d1,d2:integer):integer');
|
|
503
|
+
}
|
|
504
|
+
getValue() {
|
|
505
|
+
if (!this.params[0].isInteger())
|
|
506
|
+
throw this.typeError('Mod');
|
|
507
|
+
if (!this.params[1].isInteger())
|
|
508
|
+
throw this.typeError('Mod');
|
|
509
|
+
const d1 = this.params[0].toLong(this.ctx);
|
|
510
|
+
const d2 = this.params[1].toLong(this.ctx);
|
|
511
|
+
if (d2 === 0n)
|
|
512
|
+
throw divideByZeroException();
|
|
513
|
+
if (d2 === -1n && d1 === -9223372036854775808n)
|
|
514
|
+
throw overflowException(NetMessages.arithmeticOverflow);
|
|
515
|
+
return Variant.fromLong(d1 % d2);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
class IdenEvalText extends BuiltinFunction {
|
|
519
|
+
constructor(e) {
|
|
520
|
+
super(e, 'Evaltext', 1, 'function EvalText(expression:string):Variant');
|
|
521
|
+
}
|
|
522
|
+
getValue() {
|
|
523
|
+
if (!this.params[0].isString())
|
|
524
|
+
throw this.typeError('EvalText');
|
|
525
|
+
return this.ev.evaluateText(this.str(0));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
class IdenNumToText extends BuiltinFunction {
|
|
529
|
+
constructor(e) {
|
|
530
|
+
super(e, 'NumToText', 2, 'function NumToText(num:double, female:boolean):string');
|
|
531
|
+
}
|
|
532
|
+
getValue() {
|
|
533
|
+
if (!this.params[0].isNumber())
|
|
534
|
+
throw this.typeError('NumToText');
|
|
535
|
+
if (!this.params[1].isBoolean())
|
|
536
|
+
throw this.typeError('NumToText');
|
|
537
|
+
const num = this.params[0].toDecimal(this.ctx);
|
|
538
|
+
return Variant.fromString(numberToText(num, this.params[1].toBool(this.ctx), this.ev.language));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
// The functions of the Delphi engine (rpevalfunc.pas) that the C# engine has too
|
|
542
|
+
// (EvalFunctionsDelphi.cs), with the results of the Delphi evaluator.
|
|
543
|
+
/** (long)Math.Round(x) of .NET 9 and later: NaN is 0 and a value out of range saturates. */
|
|
544
|
+
function saturatingLong(x) {
|
|
545
|
+
if (Number.isNaN(x))
|
|
546
|
+
return 0n;
|
|
547
|
+
if (x >= 9223372036854775807)
|
|
548
|
+
return 9223372036854775807n;
|
|
549
|
+
if (x <= -9223372036854775808)
|
|
550
|
+
return -9223372036854775808n;
|
|
551
|
+
return BigInt(roundHalfEvenDouble(x));
|
|
552
|
+
}
|
|
553
|
+
/** TIME: the time of now without a date (day 0001-01-01, as a time column gives it). */
|
|
554
|
+
export class IdenTime extends BuiltinFunction {
|
|
555
|
+
constructor(e) {
|
|
556
|
+
super(e, 'Time', 0, 'function Time:time');
|
|
557
|
+
}
|
|
558
|
+
getValue() {
|
|
559
|
+
return Variant.fromDateTime(RpDateTime.fromTicks(BigInt(this.ev.host.now().tickOfDay)));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
class IdenSqrt extends BuiltinFunction {
|
|
563
|
+
constructor(e) {
|
|
564
|
+
super(e, 'Sqrt', 1, 'function Sqrt(num:double):double');
|
|
565
|
+
}
|
|
566
|
+
getValue() {
|
|
567
|
+
if (!this.params[0].isNumber())
|
|
568
|
+
throw this.typeError(this.name);
|
|
569
|
+
return Variant.fromDouble(Math.sqrt(this.params[0].toDouble(this.ctx)));
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
class IdenHourMinSec extends BuiltinFunction {
|
|
573
|
+
constructor(e) {
|
|
574
|
+
super(e, 'HourMinSec', 4, 'function HourMinSec(h:Double, idenH:string, idenM:string, idenS:string):string');
|
|
575
|
+
}
|
|
576
|
+
getValue() {
|
|
577
|
+
for (let i = 1; i <= 3; i++)
|
|
578
|
+
if (this.params[i].varType !== VariantType.String)
|
|
579
|
+
throw this.typeError(this.name);
|
|
580
|
+
if (!this.params[0].isNumber())
|
|
581
|
+
throw this.typeError(this.name);
|
|
582
|
+
const hours = this.params[0].toDouble(this.ctx);
|
|
583
|
+
const whole = Math.trunc(hours);
|
|
584
|
+
const minutes = (hours - whole) * 60;
|
|
585
|
+
const seconds = (minutes - Math.trunc(minutes)) * 60;
|
|
586
|
+
// As Delphi: the hours an Integer, the minutes and seconds a Word (a negative one wraps)
|
|
587
|
+
const h = Number(BigInt.asIntN(32, saturatingLong(whole)));
|
|
588
|
+
const m = Number(BigInt.asUintN(16, saturatingLong(Math.trunc(minutes))));
|
|
589
|
+
const s = Number(BigInt.asUintN(16, saturatingLong(seconds)));
|
|
590
|
+
const two = (v) => (v < 10 ? '0' + String(v) : String(v));
|
|
591
|
+
return Variant.fromString(String(h) + this.params[1].toString(this.ctx) + two(m) + this.params[2].toString(this.ctx) + two(s) + this.params[3].toString(this.ctx));
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
class IdenFormatMask extends BuiltinFunction {
|
|
595
|
+
constructor(e) {
|
|
596
|
+
super(e, 'FormatMask', 2, 'function FormatMask(format:string,v:string):string');
|
|
597
|
+
}
|
|
598
|
+
getValue() {
|
|
599
|
+
if (this.params[0].varType !== VariantType.String || this.params[1].varType !== VariantType.String)
|
|
600
|
+
throw this.typeError(this.name);
|
|
601
|
+
const date = this.ctx.culture.date;
|
|
602
|
+
return Variant.fromString(formatMaskText(this.params[0].toString(this.ctx), this.params[1].toString(this.ctx), date.dateSeparator, date.timeSeparator));
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* CHSTOCHT and CHTTOCHS of the Delphi engine: a text in simplified Chinese to traditional and the
|
|
607
|
+
* other way round, as LCMapString of Windows does it for the locale zh-CN, one character for one
|
|
608
|
+
* (chinesetables.ts). A value that is not a string is a type error, NULL too, as in Delphi.
|
|
609
|
+
*/
|
|
610
|
+
class IdenChineseConversion extends BuiltinFunction {
|
|
611
|
+
toTraditional;
|
|
612
|
+
static traditional;
|
|
613
|
+
static simplified;
|
|
614
|
+
constructor(e, toTraditional) {
|
|
615
|
+
super(e, toTraditional ? 'ChsToCht' : 'ChtToChs', 1, 'function ' + (toTraditional ? 'ChsToCht' : 'ChtToChs') + '(expr:string):String');
|
|
616
|
+
this.toTraditional = toTraditional;
|
|
617
|
+
}
|
|
618
|
+
static table(from, to) {
|
|
619
|
+
const map = new Map();
|
|
620
|
+
for (let i = 0; i < from.length; i++)
|
|
621
|
+
map.set(from[i], to[i]);
|
|
622
|
+
return map;
|
|
623
|
+
}
|
|
624
|
+
getValue() {
|
|
625
|
+
if (this.params[0].varType !== VariantType.String)
|
|
626
|
+
throw this.typeError(this.name);
|
|
627
|
+
const map = this.toTraditional
|
|
628
|
+
? (IdenChineseConversion.traditional ??= IdenChineseConversion.table(TO_TRADITIONAL_FROM, TO_TRADITIONAL_TO))
|
|
629
|
+
: (IdenChineseConversion.simplified ??= IdenChineseConversion.table(TO_SIMPLIFIED_FROM, TO_SIMPLIFIED_TO));
|
|
630
|
+
const text = this.params[0].toString(this.ctx);
|
|
631
|
+
let r = '';
|
|
632
|
+
for (let i = 0; i < text.length; i++)
|
|
633
|
+
r += map.get(text[i]) ?? text[i];
|
|
634
|
+
return Variant.fromString(r);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
class IdenAsc2 extends BuiltinFunction {
|
|
638
|
+
constructor(e) {
|
|
639
|
+
super(e, 'ASC2', 1, 'function ASC2:string');
|
|
640
|
+
}
|
|
641
|
+
getValue() {
|
|
642
|
+
const text = this.params[0].varType === VariantType.Null ? '' : this.params[0].toString(this.ctx);
|
|
643
|
+
let r = '';
|
|
644
|
+
for (let i = 0; i < text.length; i++) {
|
|
645
|
+
const code = text.charCodeAt(i);
|
|
646
|
+
if (code >= 192 && code <= 198)
|
|
647
|
+
r += 'A';
|
|
648
|
+
else if (code >= 224 && code <= 230)
|
|
649
|
+
r += 'a';
|
|
650
|
+
else if (code >= 200 && code <= 203)
|
|
651
|
+
r += 'E';
|
|
652
|
+
else if (code >= 232 && code <= 235)
|
|
653
|
+
r += 'e';
|
|
654
|
+
else if (code >= 204 && code <= 207)
|
|
655
|
+
r += 'I';
|
|
656
|
+
else if (code >= 236 && code <= 239)
|
|
657
|
+
r += 'i';
|
|
658
|
+
else if (code >= 210 && code <= 214)
|
|
659
|
+
r += 'O';
|
|
660
|
+
else if (code >= 242 && code <= 246)
|
|
661
|
+
r += 'o';
|
|
662
|
+
else if (code >= 217 && code <= 220)
|
|
663
|
+
r += 'U';
|
|
664
|
+
else if (code >= 249 && code <= 252)
|
|
665
|
+
r += 'u';
|
|
666
|
+
else if (code === 199)
|
|
667
|
+
r += 'C';
|
|
668
|
+
else if (code === 231)
|
|
669
|
+
r += 'c';
|
|
670
|
+
else if (code === 209)
|
|
671
|
+
r += 'N';
|
|
672
|
+
else if (code === 241)
|
|
673
|
+
r += 'n';
|
|
674
|
+
else if (code === 176 || code === 186)
|
|
675
|
+
r += 'o';
|
|
676
|
+
else if (code === 170)
|
|
677
|
+
r += 'a';
|
|
678
|
+
else
|
|
679
|
+
r += text[i];
|
|
680
|
+
}
|
|
681
|
+
return Variant.fromString(r);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
class IdenDecode64 extends BuiltinFunction {
|
|
685
|
+
constructor(e) {
|
|
686
|
+
super(e, 'Decode64', 1, 'function Decode64(s:string):string');
|
|
687
|
+
}
|
|
688
|
+
getValue() {
|
|
689
|
+
if (this.params[0].varType !== VariantType.String)
|
|
690
|
+
throw this.typeError(this.name);
|
|
691
|
+
return Variant.fromString(indyBase64Decode(this.params[0].toString(this.ctx)));
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
class IdenUtf8ToWideString extends BuiltinFunction {
|
|
695
|
+
constructor(e) {
|
|
696
|
+
super(e, 'UTF8ToWideString', 1, 'function UTF8ToWideString(value:string):WideString');
|
|
697
|
+
}
|
|
698
|
+
getValue() {
|
|
699
|
+
if (this.params[0].varType === VariantType.Null)
|
|
700
|
+
return Variant.fromString('');
|
|
701
|
+
// The ANSI bytes of the text read as UTF-8 (an invalid sequence gives U+FFFD)
|
|
702
|
+
return Variant.fromString(utf8Decode(ansiEncode(this.params[0].toString(this.ctx))));
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
class IdenIdentExists extends BuiltinFunction {
|
|
706
|
+
constructor(e) {
|
|
707
|
+
super(e, 'IdentExists', 1, 'function IdentExists(s:String)');
|
|
708
|
+
}
|
|
709
|
+
getValue() {
|
|
710
|
+
if (this.params[0].varType !== VariantType.String)
|
|
711
|
+
throw this.typeError(this.name);
|
|
712
|
+
return Variant.fromBoolean(this.ev.searchIdentifier(this.params[0].toString(this.ctx)) !== null);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/** Evaluator.CheckFileFunctions: LOADFILE and GETINIVALUE read files only when the host allows it. */
|
|
716
|
+
function checkFileFunctions(e, name) {
|
|
717
|
+
if (e.host.fileFunctions !== true)
|
|
718
|
+
throw new NamedException('Reading files from expressions is not allowed (the fileFunctions of the host; allowFileAccess in @reportman/node): ' + name, name);
|
|
719
|
+
}
|
|
720
|
+
class IdenLoadFile extends BuiltinFunction {
|
|
721
|
+
constructor(e) {
|
|
722
|
+
super(e, 'LoadFile', 1, 'function LoadFile(s:string):string');
|
|
723
|
+
}
|
|
724
|
+
getValue() {
|
|
725
|
+
if (this.params[0].varType !== VariantType.String)
|
|
726
|
+
throw this.typeError(this.name);
|
|
727
|
+
checkFileFunctions(this.ev, this.name);
|
|
728
|
+
const path = this.params[0].toString(this.ctx);
|
|
729
|
+
const bytes = path.length === 0 ? undefined : this.ev.host.readFile?.(path);
|
|
730
|
+
if (bytes === undefined)
|
|
731
|
+
throw new NamedException('File not found:' + path, this.name);
|
|
732
|
+
// The bytes as ANSI characters, as the Delphi engine loads a file into a string
|
|
733
|
+
return Variant.fromString(ansiDecode(bytes));
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
class IdenGetIniValue extends BuiltinFunction {
|
|
737
|
+
constructor(e) {
|
|
738
|
+
super(e, 'GetINIValue', 4, 'function GetINIValue(file, section, name, default : string):String');
|
|
739
|
+
}
|
|
740
|
+
getValue() {
|
|
741
|
+
for (let i = 0; i < 4; i++)
|
|
742
|
+
if (this.params[i].varType !== VariantType.String)
|
|
743
|
+
throw this.typeError(this.name);
|
|
744
|
+
checkFileFunctions(this.ev, this.name);
|
|
745
|
+
const path = this.params[0].toString(this.ctx);
|
|
746
|
+
const bytes = path.length === 0 ? undefined : this.ev.host.readFile?.(path);
|
|
747
|
+
return Variant.fromString(iniReadString(bytes, this.params[1].toString(this.ctx), this.params[2].toString(this.ctx), this.params[3].toString(this.ctx)));
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Evaluator.AddIdentifiers: the constants and built-in functions, in the C# order (TRUE, FALSE,
|
|
752
|
+
* FALSO and CIERTO first; NULL between FILEEXISTS and TODAY).
|
|
753
|
+
*/
|
|
754
|
+
export function addBuiltinIdentifiers(add, e) {
|
|
755
|
+
add('TRUE', new IdenTrue(e));
|
|
756
|
+
add('FALSE', new IdenFalse(e));
|
|
757
|
+
add('FALSO', new IdenFalse(e));
|
|
758
|
+
add('CIERTO', new IdenTrue(e));
|
|
759
|
+
add('UPPERCASE', new IdenUpperCase(e));
|
|
760
|
+
add('STRINGTOBIN', new IdenStringToBin(e));
|
|
761
|
+
add('DAY', new IdenDay(e));
|
|
762
|
+
add('MONTH', new IdenMonth(e));
|
|
763
|
+
add('MONTHNAME', new IdenMonthName(e));
|
|
764
|
+
add('YEAR', new IdenYear(e));
|
|
765
|
+
add('TRIM', new IdenTrim(e));
|
|
766
|
+
add('FORMATSTR', new IdenFormatStr(e));
|
|
767
|
+
add('FORMATNUM', new IdenFormatStr(e));
|
|
768
|
+
add('LEFT', new IdenLeft(e));
|
|
769
|
+
add('REPLACESTR', new IdenReplaceStr(e));
|
|
770
|
+
add('RIGHT', new IdenRight(e));
|
|
771
|
+
add('LENGTH', new IdenLength(e));
|
|
772
|
+
add('POS', new IdenPos(e));
|
|
773
|
+
add('SUBSTR', new IdenSubStr(e));
|
|
774
|
+
add('LOWERCASE', new IdenLowerCase(e));
|
|
775
|
+
add('STR', new IdenStr(e));
|
|
776
|
+
add('FILEEXISTS', new IdenFileExists(e));
|
|
777
|
+
add('NULL', new IdenNull(e));
|
|
778
|
+
add('TODAY', new IdenToday(e));
|
|
779
|
+
add('NOW', new IdenNow(e));
|
|
780
|
+
add('SIN', new IdenSinus(e));
|
|
781
|
+
add('MAX', new IdenMax(e));
|
|
782
|
+
add('ISINTEGER', new IdenIsInteger(e));
|
|
783
|
+
add('ISNUMERIC', new IdenIsNumeric(e));
|
|
784
|
+
add('ISVALIDDATETIME', new IdenIsValidDateTime(e));
|
|
785
|
+
add('CHECKEXPRESSION', new IdenCheckExpression(e));
|
|
786
|
+
add('FLOATTODATETIME', new IdenFloatToDateTime(e));
|
|
787
|
+
add('ROUND', new IdenRound(e));
|
|
788
|
+
add('ROUNDTOINTEGER', new IdenRoundToInteger(e));
|
|
789
|
+
add('ABS', new IdenAbs(e));
|
|
790
|
+
add('COMPAREVALUE', new IdenCompareValue(e));
|
|
791
|
+
add('INT', new IdenInt(e));
|
|
792
|
+
add('VAL', new IdenVal(e));
|
|
793
|
+
add('MOD', new IdenModul(e));
|
|
794
|
+
add('EVALTEXT', new IdenEvalText(e));
|
|
795
|
+
add('NUMTOTEXT', new IdenNumToText(e));
|
|
796
|
+
// The functions of the Delphi engine
|
|
797
|
+
add('TIME', new IdenTime(e));
|
|
798
|
+
add('SQRT', new IdenSqrt(e));
|
|
799
|
+
add('ASC2', new IdenAsc2(e));
|
|
800
|
+
add('CHSTOCHT', new IdenChineseConversion(e, true));
|
|
801
|
+
add('CHTTOCHS', new IdenChineseConversion(e, false));
|
|
802
|
+
add('IDENTEXISTS', new IdenIdentExists(e));
|
|
803
|
+
add('GETINIVALUE', new IdenGetIniValue(e));
|
|
804
|
+
add('DECODE64', new IdenDecode64(e));
|
|
805
|
+
add('LOADFILE', new IdenLoadFile(e));
|
|
806
|
+
add('FORMATMASK', new IdenFormatMask(e));
|
|
807
|
+
add('HOURMINSEC', new IdenHourMinSec(e));
|
|
808
|
+
add('UTF8TOWIDESTRING', new IdenUtf8ToWideString(e));
|
|
809
|
+
}
|
|
810
|
+
//# sourceMappingURL=functions.js.map
|