diff options
author | redmatrix <git@macgirvin.com> | 2016-05-10 17:26:44 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-10 17:26:44 -0700 |
commit | 0b02a6d123b2014705998c94ddf3d460948d3eac (patch) | |
tree | 78ff2cab9944a4f5ab3f80ec93cbe1120de90bb2 /vendor/sabre/vobject/lib/StringUtil.php | |
parent | 40b5b6e9d2da7ab65c8b4d38cdceac83a4d78deb (diff) | |
download | volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.tar.gz volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.tar.bz2 volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.zip |
initial sabre upgrade (needs lots of work - to wit: authentication, redo the browser interface, and rework event export/import)
Diffstat (limited to 'vendor/sabre/vobject/lib/StringUtil.php')
-rw-r--r-- | vendor/sabre/vobject/lib/StringUtil.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/sabre/vobject/lib/StringUtil.php b/vendor/sabre/vobject/lib/StringUtil.php new file mode 100644 index 000000000..b8615f2ba --- /dev/null +++ b/vendor/sabre/vobject/lib/StringUtil.php @@ -0,0 +1,66 @@ +<?php + +namespace Sabre\VObject; + +/** + * Useful utilities for working with various strings. + * + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + */ +class StringUtil { + + /** + * Returns true or false depending on if a string is valid UTF-8. + * + * @param string $str + * + * @return bool + */ + static function isUTF8($str) { + + // Control characters + if (preg_match('%[\x00-\x08\x0B-\x0C\x0E\x0F]%', $str)) { + return false; + } + + return (bool)preg_match('%%u', $str); + + } + + /** + * 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. + * + * @param string $str + * + * @return string + */ + static function convertToUTF8($str) { + + $encoding = mb_detect_encoding($str, ['UTF-8', 'ISO-8859-1', 'WINDOWS-1252'], true); + + switch ($encoding) { + case 'ISO-8859-1' : + $newStr = utf8_encode($str); + break; + /* Unreachable code. Not sure yet how we can improve this + * situation. + case 'WINDOWS-1252' : + $newStr = iconv('cp1252', 'UTF-8', $str); + break; + */ + default : + $newStr = $str; + + } + + // Removing any control characters + return (preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $newStr)); + + } + +} |