-
Notifications
You must be signed in to change notification settings - Fork 987
/
em_core_helper.php
3236 lines (3082 loc) · 131 KB
/
em_core_helper.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* LimeSurvey
* Copyright (C) 2007-2013 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/
/**
* Description of ExpressionManager
* (1) Does safe evaluation of PHP expressions. Only registered Functions, and known Variables are allowed.
* (a) Functions include any math, string processing, conditional, formatting, etc. functions
* (2) This class replaces LimeSurvey's <= 1.91+ process of resolving strings that contain LimeReplacementFields
* (a) String is split by expressions (by curly braces, but safely supporting strings and escaped curly braces)
* (b) Expressions (things surrounded by curly braces) are evaluated - thereby doing LimeReplacementField substitution and/or more complex calculations
* (c) Non-expressions are left intact
* (d) The array of stringParts are re-joined to create the desired final string.
* (3) The core of ExpressionScript Engine is a Recursive Descent Parser (RDP), based off of one build via JavaCC by TMSWhite in 1999.
* (a) Functions that start with RDP_ should not be touched unless you really understand compiler design.
*
* @author LimeSurvey Team (limesurvey.org)
* @author Thomas M. White (TMSWhite)
*/
class ExpressionManager
{
// These are the allowable variable suffixes for variables - each represents an attribute of a variable that can be updated on same page
private $aRDP_regexpVariableAttribute = array(
'code',
'NAOK',
'relevanceStatus',
'shown',
'valueNAOK',
'value',
);
// These are the allowable static suffixes for variables - each represents an attribute of a variable that can not be updated on same page
private $aRDP_regexpStaticAttribute = array(
'qid',
'grelevance',
'gseq',
'jsName',
'mandatory',
'qid',
'qseq',
'question',
'relevance',
'rowdivid',
'sgqa',
'type',
);
// These three variables are effectively static once constructed
private $RDP_ExpressionRegex;
private $RDP_TokenType;
private $RDP_TokenizerRegex;
private $RDP_CategorizeTokensRegex;
private $RDP_ValidFunctions; // names and # params of valid functions
// Thes variables are used while processing the equation
private $RDP_expr; // the source expression
private $RDP_tokens; // the list of generated tokens
private $RDP_count; // total number of $RDP_tokens
private $RDP_pos; // position within the $token array while processing equation
/** @var array[] informations about current errors : array with string, $token (EM internal array). Resetted in RDP_Evaluate (and only in RDP_Evaluate) */
private $RDP_errs;
/** @var array[] informations about current warnings : array with string, $token (EM internal array) and optional link Resetted in RDP_Evaluate or manually */
private $RDP_warnings = array();
private $RDP_onlyparse;
private $RDP_stack; // stack of intermediate results
private $RDP_result; // final result of evaluating the expression;
private $RDP_evalStatus; // true if $RDP_result is a valid result, and there are no serious errors
private $varsUsed; // list of variables referenced in the equation
// These variables are only used by sProcessStringContainingExpressions
private $allVarsUsed; // full list of variables used within the string, even if contains multiple expressions
private $prettyPrintSource; // HTML formatted output of running sProcessStringContainingExpressions
private $substitutionNum; // Keeps track of number of substitions performed XXX
/**
* @var array
*/
private $substitutionInfo; // array of JavaScripts to managing dynamic substitution
private $jsExpression; // caches computation of JavaScript equivalent for an Expression
private $questionSeq; // sequence order of question - so can detect if try to use variable before it is set
private $groupSeq; // sequence order of groups - so can detect if try to use variable before it is set
private $surveyMode = 'group';
// The following are only needed to enable click on variable names within pretty print and open new window to edit them
private $sid = null; // the survey ID
private $hyperlinkSyntaxHighlighting = true; // TODO - change this back to false
private $sgqaNaming = false;
function __construct()
{
/* EM core string must be in adminlang : keep the actual for resetting at end. See bug #12208 */
/**
* @var string|null $baseLang set the previous language if need to be set
*/
$baseLang = null;
if (Yii::app() instanceof CWebApplication && Yii::app()->session['adminlang']) {
$baseLang = Yii::app()->getLanguage();
Yii::app()->setLanguage(Yii::app()->session['adminlang']);
}
// List of token-matching regular expressions
// Note, this is effectively a Lexer using Regular Expressions. Don't change this unless you understand compiler design.
$RDP_regex_dq_string = '(?<!\\\\)".*?(?<!\\\\)"';
$RDP_regex_sq_string = '(?<!\\\\)\'.*?(?<!\\\\)\'';
$RDP_regex_whitespace = '\s+';
$RDP_regex_lparen = '\(';
$RDP_regex_rparen = '\)';
$RDP_regex_comma = ',';
$RDP_regex_not = '!';
$RDP_regex_inc_dec = '\+\+|--';
$RDP_regex_binary = '[+*/-]';
$RDP_regex_compare = '<=|<|>=|>|==|!=|\ble\b|\blt\b|\bge\b|\bgt\b|\beq\b|\bne\b';
$RDP_regex_assign = '='; // '=|\+=|-=|\*=|/=';
$RDP_regex_sgqa = '(?:INSERTANS:)?[0-9]+X[0-9]+X[0-9]+[A-Z0-9_]*\#?[01]?(?:\.(?:[a-zA-Z0-9_]*))?';
$RDP_regex_word = '(?:TOKEN:)?(?:[A-Z][A-Z0-9_]*)?(?:\.(?:[A-Z][A-Z0-9_]*))*(?:\.(?:[a-zA-Z0-9_]*))?';
$RDP_regex_number = '[0-9]+\.?[0-9]*|\.[0-9]+';
$RDP_regex_andor = '\band\b|\bor\b|&&|\|\|';
$RDP_regex_lcb = '{';
$RDP_regex_rcb = '}';
$RDP_regex_sq = '\'';
$RDP_regex_dq = '"';
$RDP_regex_bs = '\\\\';
$RDP_StringSplitRegex = array(
$RDP_regex_lcb,
$RDP_regex_rcb,
$RDP_regex_sq,
$RDP_regex_dq,
$RDP_regex_bs,
);
// RDP_ExpressionRegex is the regular expression that splits apart strings that contain curly braces in order to find expressions
$this->RDP_ExpressionRegex = '#(' . implode('|', $RDP_StringSplitRegex) . ')#i';
// asTokenRegex and RDP_TokenType must be kept in sync (same number and order)
$RDP_TokenRegex = array(
$RDP_regex_dq_string,
$RDP_regex_sq_string,
$RDP_regex_whitespace,
$RDP_regex_lparen,
$RDP_regex_rparen,
$RDP_regex_comma,
$RDP_regex_andor,
$RDP_regex_compare,
$RDP_regex_sgqa,
$RDP_regex_word,
$RDP_regex_number,
$RDP_regex_not,
$RDP_regex_inc_dec,
$RDP_regex_assign,
$RDP_regex_binary,
);
$this->RDP_TokenType = array(
'DQ_STRING',
'SQ_STRING',
'SPACE',
'LP',
'RP',
'COMMA',
'AND_OR',
'COMPARE',
'SGQA',
'WORD',
'NUMBER',
'NOT',
'OTHER',
'ASSIGN',
'BINARYOP',
);
// $RDP_TokenizerRegex - a single regex used to split and equation into tokens
$this->RDP_TokenizerRegex = '#(' . implode('|', $RDP_TokenRegex) . ')#i';
// $RDP_CategorizeTokensRegex - an array of patterns so can categorize the type of token found - would be nice if could get this from preg_split
// Adding ability to capture 'OTHER' type, which indicates an error - unsupported syntax element
$this->RDP_CategorizeTokensRegex = preg_replace("#^(.*)$#", "#^$1$#i", $RDP_TokenRegex);
$this->RDP_CategorizeTokensRegex[] = '/.+/';
$this->RDP_TokenType[] = 'OTHER';
// Each allowed function is a mapping from local name to external name + number of arguments
// Functions can have a list of serveral allowable #s of arguments.
// If the value is -1, the function must have a least one argument but can have an unlimited number of them
// -2 means that at least one argument is required. -3 means at least two arguments are required, etc.
$this->RDP_ValidFunctions = array(
'abs' => array('abs', 'Decimal.asNum.abs', gT('Absolute value'), 'number abs(number)', 'http://php.net/abs', 1),
'acos' => array('acos', 'Decimal.asNum.acos', gT('Arc cosine'), 'number acos(number)', 'http://php.net/acos', 1),
'addslashes' => array('addslashes', gT('addslashes'), 'Quote string with slashes', 'string addslashes(string)', 'http://php.net/addslashes', 1),
'asin' => array('asin', 'Decimal.asNum.asin', gT('Arc sine'), 'number asin(number)', 'http://php.net/asin', 1),
'atan' => array('atan', 'Decimal.asNum.atan', gT('Arc tangent'), 'number atan(number)', 'http://php.net/atan', 1),
'atan2' => array('atan2', 'Decimal.asNum.atan2', gT('Arc tangent of two variables'), 'number atan2(number, number)', 'http://php.net/atan2', 2),
'ceil' => array('ceil', 'Decimal.asNum.ceil', gT('Round fractions up'), 'number ceil(number)', 'http://php.net/ceil', 1),
'checkdate' => array('checkdate', 'checkdate', gT('Returns true(1) if it is a valid date in gregorian calendar'), 'bool checkdate(month,day,year)', 'http://php.net/checkdate', 3),
'cos' => array('cos', 'Decimal.asNum.cos', gT('Cosine'), 'number cos(number)', 'http://php.net/cos', 1),
'count' => array('exprmgr_count', 'LEMcount', gT('Count the number of answered questions in the list'), 'number count(arg1, arg2, ... argN)', '', -1),
'countif' => array('exprmgr_countif', 'LEMcountif', gT('Count the number of answered questions in the list equal the first argument'), 'number countif(matches, arg1, arg2, ... argN)', '', -2),
'countifop' => array('exprmgr_countifop', 'LEMcountifop', gT('Count the number of answered questions in the list which pass the critiera (arg op value)'), 'number countifop(op, value, arg1, arg2, ... argN)', '', -3),
'date' => array('exprmgr_date', 'date', gT('Format a local date/time'), 'string date(format [, timestamp=time()])', 'http://php.net/date', 1, 2),
'exp' => array('exp', 'Decimal.asNum.exp', gT('Calculates the exponent of e'), 'number exp(number)', 'http://php.net/exp', 1),
'fixnum' => array('exprmgr_fixnum', 'LEMfixnum', gT('Display numbers with comma as decimal separator, if needed'), 'string fixnum(number)', '', 1),
'floatval' => array('floatval', 'LEMfloatval', gT('Get float value of a variable'), 'number floatval(number)', 'http://php.net/floatval', 1),
'floor' => array('floor', 'Decimal.asNum.floor', gT('Round fractions down'), 'number floor(number)', 'http://php.net/floor', 1),
'gmdate' => array('gmdate', 'gmdate', gT('Format a GMT date/time'), 'string gmdate(format [, timestamp=time()])', 'http://php.net/gmdate', 1, 2),
'html_entity_decode' => array('html_entity_decode', 'html_entity_decode', gT('Convert all HTML entities to their applicable characters (always uses ENT_QUOTES and UTF-8)'), 'string html_entity_decode(string)', 'http://php.net/html-entity-decode', 1),
'htmlentities' => array('htmlentities', 'htmlentities', gT('Convert all applicable characters to HTML entities (always uses ENT_QUOTES and UTF-8)'), 'string htmlentities(string)', 'http://php.net/htmlentities', 1),
'htmlspecialchars' => array('expr_mgr_htmlspecialchars', 'htmlspecialchars', gT('Convert special characters to HTML entities (always uses ENT_QUOTES and UTF-8)'), 'string htmlspecialchars(string)', 'http://php.net/htmlspecialchars', 1),
'htmlspecialchars_decode' => array('expr_mgr_htmlspecialchars_decode', 'htmlspecialchars_decode', gT('Convert special HTML entities back to characters (always uses ENT_QUOTES and UTF-8)'), 'string htmlspecialchars_decode(string)', 'http://php.net/htmlspecialchars-decode', 1),
'idate' => array('idate', 'idate', gT('Format a local time/date as integer'), 'string idate(string [, timestamp=time()])', 'http://php.net/idate', 1, 2),
'if' => array('exprmgr_if', 'LEMif', gT('Conditional processing'), 'if(test,result_if_true[,result_if_false = \'\'])', '', 2, 3),
'implode' => array('exprmgr_implode', 'LEMimplode', gT('Join array elements with a string'), 'string implode(glue,arg1,arg2,...,argN)', 'http://php.net/implode', -2),
'intval' => array('intval', 'LEMintval', gT('Get the integer value of a variable'), 'int intval(number [, base=10])', 'http://php.net/intval', 1, 2),
'is_empty' => array('exprmgr_empty', 'LEMempty', gT('Determine whether a variable is considered to be empty'), 'bool is_empty(var)', 'http://php.net/empty', 1),
'is_float' => array('is_float', 'LEMis_float', gT('Finds whether the type of a variable is float'), 'bool is_float(var)', 'http://php.net/is-float', 1),
'is_int' => array('exprmgr_int', 'LEMis_int', gT('Check if the content of a variable is a valid integer value'), 'bool is_int(var)', 'http://php.net/is-int', 1),
'is_nan' => array('is_nan', 'isNaN', gT('Finds whether a value is not a number'), 'bool is_nan(var)', 'http://php.net/is-nan', 1),
'is_null' => array('is_null', 'LEMis_null', gT('Finds whether a variable is NULL'), 'bool is_null(var)', 'http://php.net/is-null', 1),
'is_numeric' => array('is_numeric', 'LEMis_numeric', gT('Finds whether a variable is a number or a numeric string'), 'bool is_numeric(var)', 'http://php.net/is-numeric', 1),
'is_string' => array('is_string', 'LEMis_string', gT('Find whether the type of a variable is string'), 'bool is_string(var)', 'http://php.net/is-string', 1),
'join' => array('exprmgr_join', 'LEMjoin', gT('Join strings, return joined string.This function is an alias of implode("",argN)'), 'string join(arg1,arg2,...,argN)', '', -1),
'list' => array('exprmgr_list', 'LEMlist', gT('Return comma-separated list of values'), 'string list(arg1, arg2, ... argN)', '', -2),
'listifop' => array('exprmgr_listifop', 'LEMlistifop', gT('Return a list of retAttr from sgqa1...sgqaN which pass the criteria (cmpAttr op value)'), 'string listifop(cmpAttr, op, value, retAttr, glue, sgqa1, sgqa2,...,sgqaN)', '', -6),
'log' => array('exprmgr_log', 'LEMlog', gT('The logarithm of number to base, if given, or the natural logarithm. '), 'number log(number,base=e)', 'http://php.net/log', -2),
'ltrim' => array('ltrim', 'ltrim', gT('Strip whitespace (or other characters) from the beginning of a string'), 'string ltrim(string [, charlist])', 'http://php.net/ltrim', 1, 2),
'max' => array('max', 'LEMmax', gT('Find highest value'), 'number|string max(arg1, arg2, ... argN)', 'http://php.net/max', -2),
'min' => array('min', 'LEMmin', gT('Find lowest value'), 'number|string min(arg1, arg2, ... argN)', 'http://php.net/min', -2),
'mktime' => array('exprmgr_mktime', 'mktime', gT('Get UNIX timestamp for a date (each of the 6 arguments are optional)'), 'number mktime([hour [, minute [, second [, month [, day [, year ]]]]]])', 'http://php.net/mktime', 0, 1, 2, 3, 4, 5, 6),
'nl2br' => array('nl2br', 'nl2br', gT('Inserts HTML line breaks before all newlines in a string'), 'string nl2br(string)', 'http://php.net/nl2br', 1, 1),
'number_format' => array('number_format', 'number_format', gT('Format a number with grouped thousands'), 'string number_format(number)', 'http://php.net/number-format', 1),
'pi' => array('pi', 'LEMpi', gT('Get value of pi'), 'number pi()', '', 0),
'pow' => array('pow', 'Decimal.asNum.pow', gT('Exponential expression'), 'number pow(base, exp)', 'http://php.net/pow', 2),
'quoted_printable_decode' => array('quoted_printable_decode', 'quoted_printable_decode', gT('Convert a quoted-printable string to an 8 bit string'), 'string quoted_printable_decode(string)', 'http://php.net/quoted-printable-decode', 1),
'quoted_printable_encode' => array('quoted_printable_encode', 'quoted_printable_encode', gT('Convert a 8 bit string to a quoted-printable string'), 'string quoted_printable_encode(string)', 'http://php.net/quoted-printable-encode', 1),
'quotemeta' => array('quotemeta', 'quotemeta', gT('Quote meta characters'), 'string quotemeta(string)', 'http://php.net/quotemeta', 1),
'rand' => array('rand', 'rand', gT('Generate a random integer'), 'int rand() OR int rand(min, max)', 'http://php.net/rand', 0, 2),
'regexMatch' => array('exprmgr_regexMatch', 'LEMregexMatch', gT('Compare a string to a regular expression pattern'), 'bool regexMatch(pattern,input)', '', 2),
'round' => array('round', 'round', gT('Rounds a number to an optional precision'), 'number round(val [, precision])', 'http://php.net/round', 1, 2),
'rtrim' => array('rtrim', 'rtrim', gT('Strip whitespace (or other characters) from the end of a string'), 'string rtrim(string [, charlist])', 'http://php.net/rtrim', 1, 2),
'sin' => array('sin', 'Decimal.asNum.sin', gT('Sine'), 'number sin(arg)', 'http://php.net/sin', 1),
'sprintf' => array('sprintf', 'sprintf', gT('Return a formatted string'), 'string sprintf(format, arg1, arg2, ... argN)', 'http://php.net/sprintf', -2),
'sqrt' => array('sqrt', 'Decimal.asNum.sqrt', gT('Square root'), 'number sqrt(arg)', 'http://php.net/sqrt', 1),
'stddev' => array('exprmgr_stddev', 'LEMstddev', gT('Calculate the Sample Standard Deviation for the list of numbers'), 'number stddev(arg1, arg2, ... argN)', '', -2),
'str_pad' => array('str_pad', 'str_pad', gT('Pad a string to a certain length with another string'), 'string str_pad(input, pad_length [, pad_string])', 'http://php.net/str-pad', 2, 3),
'str_repeat' => array('str_repeat', 'str_repeat', gT('Repeat a string'), 'string str_repeat(input, multiplier)', 'http://php.net/str-repeat', 2),
'str_replace' => array('str_replace', 'LEMstr_replace', gT('Replace all occurrences of the search string with the replacement string'), 'string str_replace(search, replace, subject)', 'http://php.net/str-replace', 3),
'strcasecmp' => array('strcasecmp', 'strcasecmp', gT('Binary safe case-insensitive string comparison'), 'int strcasecmp(str1, str2)', 'http://php.net/strcasecmp', 2),
'strcmp' => array('strcmp', 'strcmp', gT('Binary safe string comparison'), 'int strcmp(str1, str2)', 'http://php.net/strcmp', 2),
'strip_tags' => array('strip_tags', 'strip_tags', gT('Strip HTML and PHP tags from a string'), 'string strip_tags(str, allowable_tags)', 'http://php.net/strip-tags', 1, 2),
'stripos' => array('exprmgr_stripos', 'stripos', gT('Find position of first occurrence of a case-insensitive string'), 'int stripos(haystack, needle [, offset=0])', 'http://php.net/stripos', 2, 3),
'stripslashes' => array('stripslashes', 'stripslashes', gT('Un-quotes a quoted string'), 'string stripslashes(string)', 'http://php.net/stripslashes', 1),
'stristr' => array('exprmgr_stristr', 'stristr', gT('Case-insensitive strstr'), 'string stristr(haystack, needle [, before_needle=false])', 'http://php.net/stristr', 2, 3),
'strlen' => array('exprmgr_strlen', 'LEMstrlen', gT('Get string length'), 'int strlen(string)', 'http://php.net/strlen', 1),
'strpos' => array('exprmgr_strpos', 'LEMstrpos', gT('Find position of first occurrence of a string'), 'int strpos(haystack, needle [ offset=0])', 'http://php.net/strpos', 2, 3),
'strrev' => array('strrev', 'strrev', gT('Reverse a string'), 'string strrev(string)', 'http://php.net/strrev', 1),
'strstr' => array('exprmgr_strstr', 'strstr', gT('Find first occurrence of a string'), 'string strstr(haystack, needle [, before_needle=false])', 'http://php.net/strstr', 2, 3),
'strtolower' => array('exprmgr_strtolower', 'LEMstrtolower', gT('Make a string lowercase'), 'string strtolower(string)', 'http://php.net/strtolower', 1),
'strtotime' => array('strtotime', 'strtotime', gT('Convert a date/time string to unix timestamp'), 'int strtotime(string)', 'http://php.net/manual/de/function.strtotime', 1),
'strtoupper' => array('exprmgr_strtoupper', 'LEMstrtoupper', gT('Make a string uppercase'), 'string strtoupper(string)', 'http://php.net/strtoupper', 1),
'substr' => array('exprmgr_substr', 'substr', gT('Return part of a string'), 'string substr(string, start [, length])', 'http://php.net/substr', 2, 3),
'sum' => array('array_sum', 'LEMsum', gT('Calculate the sum of values in an array'), 'number sum(arg1, arg2, ... argN)', '', -2),
'sumifop' => array('exprmgr_sumifop', 'LEMsumifop', gT('Sum the values of answered questions in the list which pass the critiera (arg op value)'), 'number sumifop(op, value, arg1, arg2, ... argN)', '', -3),
'tan' => array('tan', 'Decimal.asNum.tan', gT('Tangent'), 'number tan(arg)', 'http://php.net/tan', 1),
'convert_value' => array('exprmgr_convert_value', 'LEMconvert_value', gT('Convert a numerical value using a inputTable and outputTable of numerical values'), 'number convert_value(fValue, iStrict, sTranslateFromList, sTranslateToList)', '', 4),
'time' => array('time', 'time', gT('Return current UNIX timestamp'), 'number time()', 'http://php.net/time', 0),
'trim' => array('trim', 'trim', gT('Strip whitespace (or other characters) from the beginning and end of a string'), 'string trim(string [, charlist])', 'http://php.net/trim', 1, 2),
'ucwords' => array('ucwords', 'ucwords', gT('Uppercase the first character of each word in a string'), 'string ucwords(string)', 'http://php.net/ucwords', 1),
'unique' => array('exprmgr_unique', 'LEMunique', gT('Returns true if all non-empty responses are unique'), 'boolean unique(arg1, ..., argN)', '', -1),
);
/* Reset the language */
if ($baseLang) {
Yii::app()->setLanguage($baseLang);
}
}
/**
* Since this class can be get by session, need to add a call the «start» event manually
* @return void
*/
public function ExpressionManagerStartEvent()
{
if (Yii::app() instanceof CConsoleApplication) {
return;
}
$event = new \LimeSurvey\PluginManager\PluginEvent('ExpressionManagerStart');
$result = App()->getPluginManager()->dispatchEvent($event);
$newValidFunctions = $result->get('functions', array());
$newPackages = $result->get('packages', array()); // package added to expression-extend['depends'] : maybe don't add it in event, but add an helper ?
$this->RegisterFunctions($newValidFunctions); // No validation : plugin dev can break all easily
foreach ($newPackages as $name => $definition) {
$this->addPackageForExpressionManager($name, $definition);
}
App()->getClientScript()->registerPackage('expression-extend');
}
/**
* Add a package for expression
* @param string $name of package
* @param array $definition @see https://www.yiiframework.com/doc/api/1.1/CClientScript#packages-detail
* @return void
*/
public function addPackageForExpressionManager($name, $definition)
{
Yii::app()->clientScript->addPackage($name, $definition);
array_push(Yii::app()->clientScript->packages['expression-extend']['depends'], $name);
}
/**
* Add an error to the error log
*
* @param string $errMsg
* @param array|null $token
* @return void
*/
private function RDP_AddError($errMsg, $token)
{
$this->RDP_errs[] = array($errMsg, $token);
}
/**
* Add a warning to the error log
*
* @param EMWarningInterface $warning
* @return void
*/
private function RDP_AddWarning(EMWarningInterface $warning)
{
$this->RDP_warnings[] = $warning;
}
/**
* @return array
*/
public function RDP_GetErrors()
{
return $this->RDP_errs;
}
/**
* Get informatin about type mismatch between arguments.
* @param Token $arg1
* @param Token $arg2
* @return boolean[] Like (boolean $bMismatchType, boolean $bBothNumeric, boolean $bBothString)
*/
private function getMismatchInformation(array $arg1, array $arg2)
{
/* When value come from DB : it's set to 1.000000 (DECIMAL) : must be fixed see #11163. Response::model() must fix this . or not ? */
/* Don't return true always : user can entre non numeric value in a numeric value : we must compare as string then */
$arg1[0] = ($arg1[2] == "NUMBER" && strpos($arg1[0], ".")) ? rtrim(rtrim($arg1[0], "0"), ".") : $arg1[0];
$arg2[0] = ($arg2[2] == "NUMBER" && strpos($arg2[0], ".")) ? rtrim(rtrim($arg2[0], "0"), ".") : $arg2[0];
$bNumericArg1 = $arg1[0] !== "" && (!$arg1[0] || strval(floatval($arg1[0])) == strval($arg1[0]));
$bNumericArg2 = $arg2[0] !== "" && (!$arg2[0] || strval(floatval($arg2[0])) == strval($arg2[0]));
$bStringArg1 = !$arg1[0] || !$bNumericArg1;
$bStringArg2 = !$arg2[0] || !$bNumericArg2;
$bBothNumeric = ($bNumericArg1 && $bNumericArg2);
$bBothString = ($bStringArg1 && $bStringArg2);
$bMismatchType = (!$bBothNumeric && !$bBothString);
return array($bMismatchType, $bBothNumeric, $bBothString);
}
/**
* RDP_EvaluateBinary() computes binary expressions, such as (a or b), (c * d), popping the top two entries off the
* stack and pushing the result back onto the stack.
*
* @param array $token
* @return boolean - false if there is any error, else true
*/
public function RDP_EvaluateBinary(array $token)
{
if (count($this->RDP_stack) < 2) {
$this->RDP_AddError(self::gT("Unable to evaluate binary operator - fewer than 2 entries on stack"), $token);
return false;
}
$arg2 = $this->RDP_StackPop();
$arg1 = $this->RDP_StackPop();
if (is_null($arg1) or is_null($arg2)) {
$this->RDP_AddError(self::gT("Invalid value(s) on the stack"), $token);
return false;
}
list($bMismatchType, $bBothNumeric, $bBothString) = $this->getMismatchInformation($arg1, $arg2);
$isForcedString = false;
/* @var array argument as forced string, arg type is at 2.
* Question can return NUMBER or WORD : DQ and SQ is string entered by user, STRING is WORD with +""
*/
$aForceStringArray = array('DQ_STRING', 'SQ_STRING', 'STRING'); //
if (in_array($arg1[2], $aForceStringArray) || in_array($arg2[2], $aForceStringArray)) {
$isForcedString = true;
// Set bBothString if one is forced to be string, only if both can be numeric. Mimic JS and PHP
if ($bBothNumeric) {
$bBothNumeric = false;
$bBothString = true;
$bMismatchType = false;
$arg1[0] = strval($arg1[0]);
$arg2[0] = strval($arg2[0]);
}
}
switch (strtolower($token[0])) {
case 'or':
case '||':
$result = array(($arg1[0] or $arg2[0]), $token[1], 'NUMBER');
break;
case 'and':
case '&&':
$result = array(($arg1[0] and $arg2[0]), $token[1], 'NUMBER');
break;
case '==':
case 'eq':
$result = array(($arg1[0] == $arg2[0]), $token[1], 'NUMBER');
break;
case '!=':
case 'ne':
$result = array(($arg1[0] != $arg2[0]), $token[1], 'NUMBER');
break;
case '<':
case 'lt':
if ($bMismatchType) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(false, $token[1], 'NUMBER');
} elseif (!$bBothNumeric && $bBothString) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(strcmp($arg1[0], $arg2[0]) < 0, $token[1], 'NUMBER');
} else {
$result = array(($arg1[0] < $arg2[0]), $token[1], 'NUMBER');
}
break;
case '<=';
case 'le':
if ($bMismatchType) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(false, $token[1], 'NUMBER');
} else {
// Need this explicit comparison in order to be in agreement with JavaScript
if (($arg1[0] == '0' && $arg2[0] == '') || ($arg1[0] == '' && $arg2[0] == '0')) {
$result = array(true, $token[1], 'NUMBER');
} elseif (!$bBothNumeric && $bBothString) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(strcmp($arg1[0], $arg2[0]) <= 0, $token[1], 'NUMBER');
} else {
$result = array(($arg1[0] <= $arg2[0]), $token[1], 'NUMBER');
}
}
break;
case '>':
case 'gt':
if ($bMismatchType) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(false, $token[1], 'NUMBER');
} else {
// Need this explicit comparison in order to be in agreement with JavaScript : still needed since we use ==='' ?
if (($arg1[0] == '0' && $arg2[0] == '') || ($arg1[0] == '' && $arg2[0] == '0')) {
$result = array(false, $token[1], 'NUMBER');
} elseif (!$bBothNumeric && $bBothString) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(strcmp($arg1[0], $arg2[0]) > 0, $token[1], 'NUMBER');
} else {
$result = array(($arg1[0] > $arg2[0]), $token[1], 'NUMBER');
}
}
break;
case '>=';
case 'ge':
if ($bMismatchType) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(false, $token[1], 'NUMBER');
} elseif (!$bBothNumeric && $bBothString) {
if ($isForcedString) {
$this->RDP_AddWarning(new EMWarningInvalidComparison($token));
}
$result = array(strcmp($arg1[0], $arg2[0]) >= 0, $token[1], 'NUMBER');
} else {
$result = array(($arg1[0] >= $arg2[0]), $token[1], 'NUMBER');
}
break;
case '+':
if ($bBothNumeric) {
$this->RDP_AddWarning(new EMWarningPlusOperator($token));
$result = array(($arg1[0] + $arg2[0]), $token[1], 'NUMBER');
} else {
$this->RDP_AddWarning(new EMWarningPlusOperator($token));
$result = array($arg1[0] . $arg2[0], $token[1], 'STRING');
}
break;
case '-':
if ($bBothNumeric) {
$result = array(($arg1[0] - $arg2[0]), $token[1], 'NUMBER');
} else {
$result = array(NAN, $token[1], 'NUMBER');
}
break;
case '*':
if ($bBothNumeric) {
$result = array((doubleVal($arg1[0]) * doubleVal($arg2[0])), $token[1], 'NUMBER');
} else {
$result = array(NAN, $token[1], 'NUMBER');
}
break;
case '/';
if ($bBothNumeric) {
if ($arg2[0] == 0) {
$result = array(NAN, $token[1], 'NUMBER');
} else {
$result = array(($arg1[0] / $arg2[0]), $token[1], 'NUMBER');
}
} else {
$result = array(NAN, $token[1], 'NUMBER');
}
break;
}
$this->RDP_StackPush($result);
return true;
}
/**
* Processes operations like +a, -b, !c
* @param array $token
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateUnary(array $token)
{
if (count($this->RDP_stack) < 1) {
$this->RDP_AddError(self::gT("Unable to evaluate unary operator - no entries on stack"), $token);
return false;
}
$arg1 = $this->RDP_StackPop();
if (is_null($arg1)) {
$this->RDP_AddError(self::gT("Invalid value(s) on the stack"), $token);
return false;
}
// TODO: try to determine datatype?
switch ($token[0]) {
case '+':
$result = array((+$arg1[0]), $token[1], 'NUMBER');
break;
case '-':
$result = array((-$arg1[0]), $token[1], 'NUMBER');
break;
case '!';
$result = array((!$arg1[0]), $token[1], 'NUMBER');
break;
}
$this->RDP_StackPush($result);
return true;
}
/**
* Main entry function
* @param string $expr
* @param boolean $onlyparse - if true, then validate the syntax without computing an answer
* @return boolean - true if success, false if any error occurred
*/
public function RDP_Evaluate($expr, $onlyparse = false)
{
$this->RDP_expr = $expr;
$this->RDP_tokens = $this->RDP_Tokenize($expr);
$this->RDP_count = count($this->RDP_tokens);
$this->RDP_pos = -1; // starting position within array (first act will be to increment it)
$this->RDP_errs = array();
$this->RDP_warnings = array();
$this->RDP_onlyparse = $onlyparse;
$this->RDP_stack = array();
$this->RDP_evalStatus = false;
$this->RDP_result = null;
$this->varsUsed = array();
$this->jsExpression = null;
if ($this->HasSyntaxErrors()) {
return false;
} elseif ($this->RDP_EvaluateExpressions()) {
if ($this->RDP_pos < $this->RDP_count) {
$this->RDP_AddError(self::gT("Extra tokens found"), $this->RDP_tokens[$this->RDP_pos]);
return false;
}
$this->RDP_result = $this->RDP_StackPop();
if (is_null($this->RDP_result)) {
return false;
}
if (count($this->RDP_stack) == 0) {
$this->RDP_evalStatus = true;
return true;
} else {
$this->RDP_AddError(self::gT("Unbalanced equation - values left on stack"), null);
return false;
}
} else {
$this->RDP_AddError(self::gT("Not a valid expression"), null);
return false;
}
}
/**
* Process "a op b" where op in (+,-,concatenate)
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateAdditiveExpression()
{
if (!$this->RDP_EvaluateMultiplicativeExpression()) {
return false;
}
while (($this->RDP_pos + 1) < $this->RDP_count) {
$token = $this->RDP_tokens[++$this->RDP_pos];
if ($token[2] == 'BINARYOP') {
switch ($token[0]) {
case '+':
case '-';
if ($this->RDP_EvaluateMultiplicativeExpression()) {
if (!$this->RDP_EvaluateBinary($token)) {
return false;
}
// else continue;
} else {
return false;
}
break;
default:
--$this->RDP_pos;
return true;
}
} else {
--$this->RDP_pos;
return true;
}
}
return true;
}
/**
* Process a Constant (number of string), retrieve the value of a known variable, or process a function, returning result on the stack.
* @return boolean|null - true if success, false if any error occurred
*/
private function RDP_EvaluateConstantVarOrFunction()
{
if ($this->RDP_pos + 1 >= $this->RDP_count) {
$this->RDP_AddError(self::gT("Poorly terminated expression - expected a constant or variable"), null);
return false;
}
$token = $this->RDP_tokens[++$this->RDP_pos];
switch ($token[2]) {
case 'NUMBER':
case 'DQ_STRING':
case 'SQ_STRING':
$this->RDP_StackPush($token);
return true;
// NB: No break needed
case 'WORD':
case 'SGQA':
if (($this->RDP_pos + 1) < $this->RDP_count and $this->RDP_tokens[($this->RDP_pos + 1)][2] == 'LP') {
return $this->RDP_EvaluateFunction();
} else {
if ($this->RDP_isValidVariable($token[0])) {
$this->varsUsed[] = $token[0]; // add this variable to list of those used in this equation
if (preg_match("/\.(" . $this->getRegexpStaticValidAttributes() . ")$/", $token[0])) {
$relStatus = 1; // static, so always relevant
} else {
$relStatus = $this->GetVarAttribute($token[0], 'relevanceStatus', 1);
}
if ($relStatus == 1) {
$argtype = ($this->GetVarAttribute($token[0], 'onlynum', 0)) ? "NUMBER" : "WORD";
$result = array($this->GetVarAttribute($token[0], null, ''), $token[1], $argtype);
} else {
$result = array(null, $token[1], 'NUMBER'); // was 0 instead of NULL
}
$this->RDP_StackPush($result);
return true;
} else {
$this->RDP_AddError(self::gT("Undefined variable"), $token);
return false;
}
}
// NB: No break needed
case 'COMMA':
--$this->RDP_pos;
$this->RDP_AddError("Should never get to this line?", $token);
return false;
// NB: No break needed
default:
return false;
// NB: No break needed
}
}
/**
* Process "a == b", "a eq b", "a != b", "a ne b"
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateEqualityExpression()
{
if (!$this->RDP_EvaluateRelationExpression()) {
return false;
}
while (($this->RDP_pos + 1) < $this->RDP_count) {
$token = $this->RDP_tokens[++$this->RDP_pos];
switch (strtolower($token[0])) {
case '==':
case 'eq':
case '!=':
case 'ne':
if ($this->RDP_EvaluateRelationExpression()) {
if (!$this->RDP_EvaluateBinary($token)) {
return false;
}
// else continue;
} else {
return false;
}
break;
default:
--$this->RDP_pos;
return true;
}
}
return true;
}
/**
* Process a single expression (e.g. without commas)
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateExpression()
{
if ($this->RDP_pos + 2 < $this->RDP_count) {
$token1 = $this->RDP_tokens[++$this->RDP_pos];
$token2 = $this->RDP_tokens[++$this->RDP_pos];
if ($token2[2] == 'ASSIGN') {
if ($this->RDP_isValidVariable($token1[0])) {
$this->varsUsed[] = $token1[0]; // add this variable to list of those used in this equation
if ($this->RDP_isWritableVariable($token1[0])) {
$evalStatus = $this->RDP_EvaluateLogicalOrExpression();
if ($evalStatus) {
$result = $this->RDP_StackPop();
if (!is_null($result)) {
$newResult = $token2;
$newResult[2] = 'NUMBER';
$newResult[0] = $this->RDP_SetVariableValue($token2[0], $token1[0], $result[0]);
$this->RDP_StackPush($newResult);
} else {
$evalStatus = false;
}
}
$this->RDP_AddWarning(new EMWarningAssignment($token2));
return $evalStatus;
} else {
$this->RDP_AddError(self::gT('The value of this variable can not be changed'), $token1);
return false;
}
} else {
$this->RDP_AddError(self::gT('Only variables can be assigned values'), $token1);
return false;
}
} else {
// not an assignment expression, so try something else
$this->RDP_pos -= 2;
return $this->RDP_EvaluateLogicalOrExpression();
}
} else {
return $this->RDP_EvaluateLogicalOrExpression();
}
}
/**
* Process "expression [, expression]*
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateExpressions()
{
$evalStatus = $this->RDP_EvaluateExpression();
if (!$evalStatus) {
return false;
}
while (++$this->RDP_pos < $this->RDP_count) {
$token = $this->RDP_tokens[$this->RDP_pos];
if ($token[2] == 'RP') {
return true; // presumbably the end of an expression
} elseif ($token[2] == 'COMMA') {
if ($this->RDP_EvaluateExpression()) {
$secondResult = $this->RDP_StackPop();
$firstResult = $this->RDP_StackPop();
if (is_null($firstResult)) {
return false;
}
$this->RDP_StackPush($secondResult);
$evalStatus = true;
} else {
return false; // an error must have occurred
}
} else {
$this->RDP_AddError(self::gT("Expected expressions separated by commas"), $token);
$evalStatus = false;
break;
}
}
while (++$this->RDP_pos < $this->RDP_count) {
$token = $this->RDP_tokens[$this->RDP_pos];
$this->RDP_AddError(self::gT("Extra token found after expressions"), $token);
$evalStatus = false;
}
return $evalStatus;
}
/**
* Process a function call
* @return boolean|null - true if success, false if any error occurred
*/
private function RDP_EvaluateFunction()
{
$funcNameToken = $this->RDP_tokens[$this->RDP_pos]; // note that don't need to increment position for functions
$funcName = $funcNameToken[0];
if (!$this->RDP_isValidFunction($funcName)) {
$this->RDP_AddError(self::gT("Undefined function"), $funcNameToken);
return false;
}
$token2 = $this->RDP_tokens[++$this->RDP_pos];
if ($token2[2] != 'LP') {
$this->RDP_AddError(self::gT("Expected left parentheses after function name"), $funcNameToken);
}
$params = array(); // will just store array of values, not tokens
while ($this->RDP_pos + 1 < $this->RDP_count) {
$token3 = $this->RDP_tokens[$this->RDP_pos + 1];
if (count($params) > 0) {
// should have COMMA or RP
if ($token3[2] == 'COMMA') {
++$this->RDP_pos; // consume the token so can process next clause
if ($this->RDP_EvaluateExpression()) {
$value = $this->RDP_StackPop();
if (is_null($value)) {
return false;
}
$params[] = $value[0];
continue;
} else {
$this->RDP_AddError(self::gT("Extra comma found in function"), $token3);
return false;
}
}
}
if ($token3[2] == 'RP') {
++$this->RDP_pos; // consume the token so can process next clause
return $this->RDP_RunFunction($funcNameToken, $params);
} else {
if ($this->RDP_EvaluateExpression()) {
$value = $this->RDP_StackPop();
if (is_null($value)) {
return false;
}
$params[] = $value[0];
continue;
} else {
return false;
}
}
}
}
/**
* Process "a && b" or "a and b"
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateLogicalAndExpression()
{
if (!$this->RDP_EvaluateEqualityExpression()) {
return false;
}
while (($this->RDP_pos + 1) < $this->RDP_count) {
$token = $this->RDP_tokens[++$this->RDP_pos];
switch (strtolower($token[0])) {
case '&&':
case 'and':
if ($this->RDP_EvaluateEqualityExpression()) {
if (!$this->RDP_EvaluateBinary($token)) {
return false;
}
// else continue
} else {
return false; // an error must have occurred
}
break;
default:
--$this->RDP_pos;
return true;
}
}
return true;
}
/**
* Process "a || b" or "a or b"
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateLogicalOrExpression()
{
if (!$this->RDP_EvaluateLogicalAndExpression()) {
return false;
}
while (($this->RDP_pos + 1) < $this->RDP_count) {
$token = $this->RDP_tokens[++$this->RDP_pos];
switch (strtolower($token[0])) {
case '||':
case 'or':
if ($this->RDP_EvaluateLogicalAndExpression()) {
if (!$this->RDP_EvaluateBinary($token)) {
return false;
}
// else continue
} else {
// an error must have occurred
return false;
}
break;
default:
// no more expressions being ORed together, so continue parsing
--$this->RDP_pos;
return true;
}
}
// no more tokens to parse
return true;
}
/**
* Process "a op b" where op in (*,/)
* @return boolean - true if success, false if any error occurred
*/
private function RDP_EvaluateMultiplicativeExpression()
{
if (!$this->RDP_EvaluateUnaryExpression()) {
return false;
}
while (($this->RDP_pos + 1) < $this->RDP_count) {
$token = $this->RDP_tokens[++$this->RDP_pos];
if ($token[2] == 'BINARYOP') {
switch ($token[0]) {
case '*':
case '/';
if ($this->RDP_EvaluateUnaryExpression()) {
if (!$this->RDP_EvaluateBinary($token)) {
return false;
}
// else continue
} else {
// an error must have occurred
return false;
}
break;
default:
--$this->RDP_pos;
return true;
}
} else {
--$this->RDP_pos;
return true;
}
}
return true;
}
/**
* Process expressions including functions and parenthesized blocks
* @return boolean|null - true if success, false if any error occurred
*/
private function RDP_EvaluatePrimaryExpression()
{
if (($this->RDP_pos + 1) >= $this->RDP_count) {
$this->RDP_AddError(self::gT("Poorly terminated expression - expected a constant or variable"), null);
return false;
}