+
+/**
+ * Wrapper that is used to switch between vanilla and multibyte substr
+ * functions.
+ * @param string $string
+ * @param integer $start
+ * @param integer $length
+ * @param string $charset
+ * @return string
+ * @since 1.5.1
+ * @link http://www.php.net/substr
+ * @link http://www.php.net/mb_substr
+ */
+function sq_substr($string,$start,$length,$charset='auto') {
+ // use automatic charset detection, if function call asks for it
+ if ($charset=='auto') {
+ global $default_charset, $squirrelmail_language;
+ set_my_charset();
+ $charset=$default_charset;
+ if ($squirrelmail_language=='ja_JP') $charset='euc-jp';
+ }
+ $charset = strtolower($charset);
+ if (function_exists('mb_internal_encoding') &&
+ in_array($charset,sq_mb_list_encodings())) {
+ return mb_substr($string,$start,$length,$charset);
+ }
+ // TODO: add mbstring independent code
+
+ // use vanilla string functions as last option
+ return substr($string,$start,$length);
+}
+
+/**
+ * Wrapper that is used to switch between vanilla and multibyte strpos
+ * functions.
+ * @param string $haystack
+ * @param mixed $needle
+ * @param integer $offset
+ * @param string $charset
+ * @return string
+ * @since 1.5.1
+ * @link http://www.php.net/strpos
+ * @link http://www.php.net/mb_strpos
+ */
+function sq_strpos($haystack,$needle,$offset,$charset='auto') {
+ // use automatic charset detection, if function call asks for it
+ if ($charset=='auto') {
+ global $default_charset, $squirrelmail_language;
+ set_my_charset();
+ $charset=$default_charset;
+ if ($squirrelmail_language=='ja_JP') $charset='euc-jp';
+ }
+ $charset = strtolower($charset);
+ if (function_exists('mb_internal_encoding') &&
+ in_array($charset,sq_mb_list_encodings())) {
+ return mb_strpos($haystack,$needle,$offset,$charset);
+ }
+ // TODO: add mbstring independent code
+
+ // use vanilla string functions as last option
+ return strpos($haystack,$needle,$offset);
+}
+
+/**
+ * Wrapper that is used to switch between vanilla and multibyte strtoupper
+ * functions.
+ * @param string $string
+ * @param string $charset
+ * @return string
+ * @since 1.5.1
+ * @link http://www.php.net/strtoupper
+ * @link http://www.php.net/mb_strtoupper
+ */
+function sq_strtoupper($string,$charset='auto') {
+ // use automatic charset detection, if function call asks for it
+ if ($charset=='auto') {
+ global $default_charset,$squirrelmail_language;
+ set_my_charset();
+ $charset=$default_charset;
+ if ($squirrelmail_language=='ja_JP') $charset='euc-jp';
+ }
+ $charset = strtolower($charset);
+ if (function_exists('mb_strtoupper') &&
+ in_array($charset,sq_mb_list_encodings())) {
+ return mb_strtoupper($string,$charset);
+ }
+ // TODO: add mbstring independent code
+
+ // use vanilla string functions as last option
+ return strtoupper($string);
+}
+
+/**
+ * Counts 8bit bytes in string
+ * @param string $string tested string
+ * @return integer number of 8bit bytes
+ */
+function sq_count8bit($string) {
+ $count=0;
+ for ($i=0; $i<strlen($string); $i++) {
+ if (ord($string[$i]) > 127) $count++;
+ }
+ return $count;
+}
+
+?>