1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
|
|
|
4 |
|
|
|
5 |
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
|
|
6 |
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
|
|
7 |
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
|
|
8 |
|
|
|
9 |
class CaseConvert
|
|
|
10 |
{
|
|
|
11 |
use ArrayEnabled;
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* LOWERCASE.
|
|
|
15 |
*
|
|
|
16 |
* Converts a string value to upper case.
|
|
|
17 |
*
|
|
|
18 |
* @param mixed $mixedCaseValue The string value to convert to lower case
|
|
|
19 |
* Or can be an array of values
|
|
|
20 |
*
|
|
|
21 |
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
|
|
|
22 |
* with the same dimensions
|
|
|
23 |
*/
|
|
|
24 |
public static function lower(mixed $mixedCaseValue): array|string
|
|
|
25 |
{
|
|
|
26 |
if (is_array($mixedCaseValue)) {
|
|
|
27 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
try {
|
|
|
31 |
$mixedCaseValue = Helpers::extractString($mixedCaseValue, true);
|
|
|
32 |
} catch (CalcExp $e) {
|
|
|
33 |
return $e->getMessage();
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
return StringHelper::strToLower($mixedCaseValue);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* UPPERCASE.
|
|
|
41 |
*
|
|
|
42 |
* Converts a string value to upper case.
|
|
|
43 |
*
|
|
|
44 |
* @param mixed $mixedCaseValue The string value to convert to upper case
|
|
|
45 |
* Or can be an array of values
|
|
|
46 |
*
|
|
|
47 |
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
|
|
|
48 |
* with the same dimensions
|
|
|
49 |
*/
|
|
|
50 |
public static function upper(mixed $mixedCaseValue): array|string
|
|
|
51 |
{
|
|
|
52 |
if (is_array($mixedCaseValue)) {
|
|
|
53 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
try {
|
|
|
57 |
$mixedCaseValue = Helpers::extractString($mixedCaseValue, true);
|
|
|
58 |
} catch (CalcExp $e) {
|
|
|
59 |
return $e->getMessage();
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
return StringHelper::strToUpper($mixedCaseValue);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* PROPERCASE.
|
|
|
67 |
*
|
|
|
68 |
* Converts a string value to proper or title case.
|
|
|
69 |
*
|
|
|
70 |
* @param mixed $mixedCaseValue The string value to convert to title case
|
|
|
71 |
* Or can be an array of values
|
|
|
72 |
*
|
|
|
73 |
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
|
|
|
74 |
* with the same dimensions
|
|
|
75 |
*/
|
|
|
76 |
public static function proper(mixed $mixedCaseValue): array|string
|
|
|
77 |
{
|
|
|
78 |
if (is_array($mixedCaseValue)) {
|
|
|
79 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
try {
|
|
|
83 |
$mixedCaseValue = Helpers::extractString($mixedCaseValue, true);
|
|
|
84 |
} catch (CalcExp $e) {
|
|
|
85 |
return $e->getMessage();
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
return StringHelper::strToTitle($mixedCaseValue);
|
|
|
89 |
}
|
|
|
90 |
}
|