[ticket/9574] Add pcre_utf8_support() function

Refactor the check for PCRE UTF-8 support into a new pcre_utf8_support()
function.

PHPBB3-9574
This commit is contained in:
Igor Wiedler 2010-06-25 19:09:17 +02:00
parent eda9fbbb63
commit 6b4d0a2542
5 changed files with 21 additions and 11 deletions

View file

@ -317,13 +317,7 @@ class acp_bbcodes
$bbcode_tpl = trim($bbcode_tpl); $bbcode_tpl = trim($bbcode_tpl);
$utf8 = strpos($bbcode_match, 'INTTEXT') !== false; $utf8 = strpos($bbcode_match, 'INTTEXT') !== false;
// make sure we have utf8 support $utf8_pcre_properties = pcre_utf8_support();
// PHP may not be linked with the bundled PCRE lib and instead with an older version
$utf8_pcre_properties = false;
if (@preg_match('/\p{L}/u', 'a') !== false)
{
$utf8_pcre_properties = true;
}
$fp_match = preg_quote($bbcode_match, '!'); $fp_match = preg_quote($bbcode_match, '!');
$fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match); $fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match);

View file

@ -82,7 +82,7 @@ class cache extends acm
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$censors = array(); $censors = array();
$unicode = (@preg_match('/\p{L}/u', 'a') !== false) ? true : false; $unicode = pcre_utf8_support();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {

View file

@ -4507,3 +4507,19 @@ function phpbb_user_session_handler()
return; return;
} }
/**
* Check if PCRE has UTF-8 support
* PHP may not be linked with the bundled PCRE lib and instead with an older version
*
* @return bool Returns true if PCRE (the regular expressions library) supports UTF-8 encoding
*/
function pcre_utf8_support()
{
static $utf8_pcre_properties = null;
if (is_null($utf8_pcre_properties))
{
$utf8_pcre_properties = (@preg_match('/\p{L}/u', 'a') !== false);
}
return $utf8_pcre_properties;
}

View file

@ -1490,7 +1490,7 @@ function validate_username($username, $allowed_username = false)
$mbstring = $pcre = false; $mbstring = $pcre = false;
// generic UTF-8 character types supported? // generic UTF-8 character types supported?
if (@preg_match('/\p{L}/u', 'a') !== false) if (pcre_utf8_support())
{ {
$pcre = true; $pcre = true;
} }
@ -1626,7 +1626,7 @@ function validate_password($password)
$pcre = $mbstring = false; $pcre = $mbstring = false;
// generic UTF-8 character types supported? // generic UTF-8 character types supported?
if (@preg_match('/\p{L}/u', 'a') !== false) if (pcre_utf8_support())
{ {
$upp = '\p{Lu}'; $upp = '\p{Lu}';
$low = '\p{Ll}'; $low = '\p{Ll}';

View file

@ -43,7 +43,7 @@ class fulltext_mysql extends search_backend
$this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']); $this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']);
// PHP may not be linked with the bundled PCRE lib and instead with an older version // PHP may not be linked with the bundled PCRE lib and instead with an older version
if (@preg_match('/\p{L}/u', 'a') !== false) if (pcre_utf8_support())
{ {
$this->pcre_properties = true; $this->pcre_properties = true;
} }