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

Useful utilities for working with various strings. More...

+ Collaboration diagram for Sabre\VObject\StringUtil:

Static Public Member Functions

static isUTF8 ($str)
 Returns true or false depending on if a string is valid UTF-8. More...
 
static convertToUTF8 ($str)
 This method tries its best to convert the input string to UTF-8. More...
 

Detailed Description

Useful utilities for working with various strings.

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

Definition at line 12 of file StringUtil.php.

Member Function Documentation

◆ convertToUTF8()

static Sabre\VObject\StringUtil::convertToUTF8 (   $str)
static

This method tries its best to convert the input string to UTF-8.

Currently only ISO-5991-1 input and UTF-8 input is supported, but this may be expanded upon if we receive other examples.

Parameters
string$str
Returns
string

Definition at line 42 of file StringUtil.php.

42 {
43
44 $encoding = mb_detect_encoding($str, ['UTF-8', 'ISO-8859-1', 'WINDOWS-1252'], true);
45
46 switch ($encoding) {
47 case 'ISO-8859-1' :
48 $newStr = utf8_encode($str);
49 break;
50 /* Unreachable code. Not sure yet how we can improve this
51 * situation.
52 case 'WINDOWS-1252' :
53 $newStr = iconv('cp1252', 'UTF-8', $str);
54 break;
55 */
56 default :
57 $newStr = $str;
58
59 }
60
61 // Removing any control characters
62 return (preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $newStr));
63
64 }

Referenced by Sabre\VObject\StringUtilTest\testConvertToUTF8ControlChar(), Sabre\VObject\StringUtilTest\testConvertToUTF8IsUTF8(), Sabre\VObject\StringUtilTest\testConvertToUTF8nonUTF8(), and Sabre\VObject\Property\validate().

+ Here is the caller graph for this function:

◆ isUTF8()

static Sabre\VObject\StringUtil::isUTF8 (   $str)
static

Returns true or false depending on if a string is valid UTF-8.

Parameters
string$str
Returns
bool

Definition at line 21 of file StringUtil.php.

21 {
22
23 // Control characters
24 if (preg_match('%[\x00-\x08\x0B-\x0C\x0E\x0F]%', $str)) {
25 return false;
26 }
27
28 return (bool)preg_match('%%u', $str);
29
30 }

Referenced by Sabre\VObject\StringUtilTest\testIsUTF8(), Sabre\VObject\StringUtilTest\testNonUTF8(), Sabre\VObject\StringUtilTest\testUTF8ControlChar(), and Sabre\VObject\Property\validate().

+ Here is the caller graph for this function:

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