PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Calculation / TextData / Concatenate.php

Concatenate.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php

138 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
4
5 use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7 use PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue;
8 use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
9 use PhpOffice\PhpSpreadsheet\Cell\DataType;
10 use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
11
12 class Concatenate
13 {
14 use ArrayEnabled;
15
16 /**
17 * CONCATENATE.
18 *
19 * @param array $args
20 */
21 public static function CONCATENATE(...$args): string
22 {
23 $returnValue = '';
24
25 // Loop through arguments
26 $aArgs = Functions::flattenArray($args);
27
28 foreach ($aArgs as $arg) {
29 $value = Helpers::extractString($arg);
30 if (ErrorValue::isError($value)) {
31 $returnValue = $value;
32
33 break;
34 }
35 $returnValue .= Helpers::extractString($arg);
36 if (StringHelper::countCharacters($returnValue) > DataType::MAX_STRING_LENGTH) {
37 $returnValue = ExcelError::CALC();
38
39 break;
40 }
41 }
42
43 return $returnValue;
44 }
45
46 /**
47 * TEXTJOIN.
48 *
49 * @param mixed $delimiter The delimter to use between the joined arguments
50 * Or can be an array of values
51 * @param mixed $ignoreEmpty true/false Flag indicating whether empty arguments should be skipped
52 * Or can be an array of values
53 * @param mixed $args The values to join
54 *
55 * @return array|string The joined string
56 * If an array of values is passed for the $delimiter or $ignoreEmpty arguments, then the returned result
57 * will also be an array with matching dimensions
58 */
59 public static function TEXTJOIN($delimiter = '', $ignoreEmpty = true, ...$args)
60 {
61 if (is_array($delimiter) || is_array($ignoreEmpty)) {
62 return self::evaluateArrayArgumentsSubset(
63 [self::class, __FUNCTION__],
64 2,
65 $delimiter,
66 $ignoreEmpty,
67 ...$args
68 );
69 }
70
71 $delimiter ??= '';
72 $ignoreEmpty ??= true;
73 $aArgs = Functions::flattenArray($args);
74 $returnValue = self::evaluateTextJoinArray($ignoreEmpty, $aArgs);
75
76 $returnValue ??= implode($delimiter, $aArgs);
77 if (StringHelper::countCharacters($returnValue) > DataType::MAX_STRING_LENGTH) {
78 $returnValue = ExcelError::CALC();
79 }
80
81 return $returnValue;
82 }
83
84 private static function evaluateTextJoinArray(bool $ignoreEmpty, array &$aArgs): ?string
85 {
86 foreach ($aArgs as $key => &$arg) {
87 $value = Helpers::extractString($arg);
88 if (ErrorValue::isError($value)) {
89 return $value;
90 }
91
92 if ($ignoreEmpty === true && ((is_string($arg) && trim($arg) === '') || $arg === null)) {
93 unset($aArgs[$key]);
94 } elseif (is_bool($arg)) {
95 $arg = Helpers::convertBooleanValue($arg);
96 }
97 }
98
99 return null;
100 }
101
102 /**
103 * REPT.
104 *
105 * Returns the result of builtin function round after validating args.
106 *
107 * @param mixed $stringValue The value to repeat
108 * Or can be an array of values
109 * @param mixed $repeatCount The number of times the string value should be repeated
110 * Or can be an array of values
111 *
112 * @return array|string The repeated string
113 * If an array of values is passed for the $stringValue or $repeatCount arguments, then the returned result
114 * will also be an array with matching dimensions
115 */
116 public static function builtinREPT($stringValue, $repeatCount)
117 {
118 if (is_array($stringValue) || is_array($repeatCount)) {
119 return self::evaluateArrayArguments([self::class, __FUNCTION__], $stringValue, $repeatCount);
120 }
121
122 $stringValue = Helpers::extractString($stringValue);
123
124 if (!is_numeric($repeatCount) || $repeatCount < 0) {
125 $returnValue = ExcelError::VALUE();
126 } elseif (ErrorValue::isError($stringValue)) {
127 $returnValue = $stringValue;
128 } else {
129 $returnValue = str_repeat($stringValue, (int) $repeatCount);
130 if (StringHelper::countCharacters($returnValue) > DataType::MAX_STRING_LENGTH) {
131 $returnValue = ExcelError::VALUE(); // note VALUE not CALC
132 }
133 }
134
135 return $returnValue;
136 }
137 }
138