ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\StringUtil Class Reference

String utility. More...

+ Collaboration diagram for Sabre\DAV\StringUtil:

Static Public Member Functions

static textMatch ($haystack, $needle, $collation, $matchType='contains')
 Checks if a needle occurs in a haystack ;) More...
 
static ensureUTF8 ($input)
 This method takes an input string, checks if it's not valid UTF-8 and attempts to convert it to UTF-8 if it's not. More...
 

Detailed Description

String utility.

This class is mainly used to implement the 'text-match' filter, used by both the CalDAV calendar-query REPORT, and CardDAV addressbook-query REPORT. Because they both need it, it was decided to put it in Sabre\DAV instead.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 16 of file StringUtil.php.

Member Function Documentation

◆ ensureUTF8()

static Sabre\DAV\StringUtil::ensureUTF8 (   $input)
static

This method takes an input string, checks if it's not valid UTF-8 and attempts to convert it to UTF-8 if it's not.

Note that currently this can only convert ISO-8559-1 to UTF-8 (latin-1), anything else will likely fail.

Parameters
string$input
Returns
string

Definition at line 79 of file StringUtil.php.

79 {
80
81 $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true);
82
83 if ($encoding === 'ISO-8859-1') {
84 return utf8_encode($input);
85 } else {
86 return $input;
87 }
88
89 }

References $input.

Referenced by Sabre\CardDAV\AddressBook\createFile(), Sabre\CardDAV\Card\put(), Sabre\DAV\StringUtilTest\testEnsureUTF8_ascii(), Sabre\DAV\StringUtilTest\testEnsureUTF8_latin1(), and Sabre\DAV\StringUtilTest\testEnsureUTF8_utf8().

+ Here is the caller graph for this function:

◆ textMatch()

static Sabre\DAV\StringUtil::textMatch (   $haystack,
  $needle,
  $collation,
  $matchType = 'contains' 
)
static

Checks if a needle occurs in a haystack ;)

Parameters
string$haystack
string$needle
string$collation
string$matchType
Returns
bool

Definition at line 27 of file StringUtil.php.

27 {
28
29 switch ($collation) {
30
31 case 'i;ascii-casemap' :
32 // default strtolower takes locale into consideration
33 // we don't want this.
34 $haystack = str_replace(range('a', 'z'), range('A', 'Z'), $haystack);
35 $needle = str_replace(range('a', 'z'), range('A', 'Z'), $needle);
36 break;
37
38 case 'i;octet' :
39 // Do nothing
40 break;
41
42 case 'i;unicode-casemap' :
43 $haystack = mb_strtoupper($haystack, 'UTF-8');
44 $needle = mb_strtoupper($needle, 'UTF-8');
45 break;
46
47 default :
48 throw new Exception\BadRequest('Collation type: ' . $collation . ' is not supported');
49
50 }
51
52 switch ($matchType) {
53
54 case 'contains' :
55 return strpos($haystack, $needle) !== false;
56 case 'equals' :
57 return $haystack === $needle;
58 case 'starts-with' :
59 return strpos($haystack, $needle) === 0;
60 case 'ends-with' :
61 return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle);
62 default :
63 throw new Exception\BadRequest('Match-type: ' . $matchType . ' is not supported');
64
65 }
66
67 }

Referenced by Sabre\DAV\StringUtilTest\testBadCollation(), Sabre\DAV\StringUtilTest\testBadMatchType(), Sabre\DAV\StringUtilTest\testTextMatch(), Sabre\CardDAV\Plugin\validateParamFilters(), Sabre\CalDAV\CalendarQueryValidator\validateTextMatch(), and Sabre\CardDAV\Plugin\validateTextMatches().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: