Method for reversing the case of a string, for use in comparisons where lower-case/upper-case is reversed

This commit is contained in:
MarkBaker 2015-01-18 12:31:18 +00:00
parent c089cfd53f
commit dc137c293a
3 changed files with 44 additions and 11 deletions

View File

@ -3641,21 +3641,19 @@ class PHPExcel_Calculation {
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result)); $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
// And push the result onto the stack // And push the result onto the stack
$stack->push('Value',$result); $stack->push('Value',$result);
return TRUE; return true;
} // function _executeBinaryComparisonOperation() }
/** /**
* Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters * Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters
* @param string $str1 * @param string $str1 First string value for the comparison
* @param string $str2 * @param string $str2 Second string value for the comparison
* @return integer * @return integer
*/ */
private function strcmpLowercaseFirst($str1, $str2) private function strcmpLowercaseFirst($str1, $str2)
{ {
$from = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $inversedStr1 = PHPExcel_Shared_String::StrCaseReverse($str1);
$to = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $inversedStr2 = PHPExcel_Shared_String::StrCaseReverse($str2);
$inversedStr1 = strtr($str1, $from, $to);
$inversedStr2 = strtr($str2, $from, $to);
return strcmp($inversedStr1, $inversedStr2); return strcmp($inversedStr1, $inversedStr2);
} }

View File

@ -626,6 +626,41 @@ class PHPExcel_Shared_String
return ucwords($pValue); return ucwords($pValue);
} }
public static function mb_is_upper($char)
{
return mb_strtolower($char, "UTF-8") != $char;
}
public static function mb_str_split($string)
{
# Split at all position not after the start: ^
# and not before the end: $
return preg_split('/(?<!^)(?!$)/u', $string );
}
/**
* Reverse the case of a string, so that all uppercase characters become lowercase
* and all lowercase characters become uppercase
*
* @param string $pValue UTF-8 encoded string
* @return string
*/
public static function StrCaseReverse($pValue = '')
{
if (self::getIsMbstringEnabled()) {
$characters = self::mb_str_split($pValue);
foreach($characters as &$character) {
if(self::mb_is_upper($character)) {
$character = mb_strtolower($character, 'UTF-8');
} else {
$character = mb_strtoupper($character, 'UTF-8');
}
}
return implode('', $characters);
}
return strtolower($pValue) ^ strtoupper($pValue) ^ $pValue;
}
/** /**
* Identify whether a string contains a fractional numeric value, * Identify whether a string contains a fractional numeric value,
* and convert it to a numeric if it is * and convert it to a numeric if it is

View File

@ -257,7 +257,7 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule
* *
* @var string * @var string
*/ */
private $_operator = ''; private $_operator = self::AUTOFILTER_COLUMN_RULE_EQUAL;
/** /**
* DateTimeGrouping Group Value * DateTimeGrouping Group Value