From 5e7ae71389cafffe340185e9911219ee6997c18a Mon Sep 17 00:00:00 2001 From: braverock Date: Sun, 6 Jun 2004 18:46:38 +0000 Subject: [PATCH] - add sm_ctype_space and function_exists check to support PHP without ctype - sm_ctype_space function contributed by Tomas Kuliavas git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7608 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/strings.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/functions/strings.php b/functions/strings.php index 27dfa8a1..238d04e6 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -74,6 +74,37 @@ function sqMakeNewLine (&$str, $citeLevel, &$column) { } } +/** + * Checks for spaces in strings - only used if PHP doesn't have native ctype support + * + * @author Tomas Kuliavas + * According to Tomas: + * You might be able to rewrite the function by adding short evaluation form + * or using preg_match instead of ereg. It is possible that you must use + * preg_match for binary safe comparison. + * + * possible problems: + * - iso-2022-xx charsets - hex 20 might be part of other symbol. I might + * be wrong. 0x20 is not used in iso-2022-jp. I haven't checked iso-2022-kr + * and iso-2022-cn mappings. + * + * - no-break space ( ) - it is 8bit symbol, that depends on charset. + * there are at least three different charset groups that have nbsp in + * different places. + * + * I don't see any charset/nbsp options in php ctype either. + * + * @param string $string tested string + * @return bool true when space symbols are present in test string + */ +function sm_ctype_space($string) { + if ( ereg("[\11-\15]", $string) || ereg("[\40]", $string) ) { + return true; + } else { + return false; + } +} + /** * Wraps text at $wrap characters. While sqWordWrap takes * a single line of text and wraps it, this function works @@ -87,6 +118,13 @@ function sqMakeNewLine (&$str, $citeLevel, &$column) { * @return string the wrapped text */ function &sqBodyWrap (&$body, $wrap) { + //check for ctype support, and fake it if it doesn't exist + if (!function_exists('ctype_space')) { + function ctype_space ($string) { + return sm_ctype_space($string); + } + } + // the newly wrapped text $outString = ''; // current column since the last newline in the outstring -- 2.25.1