From f2da7e0bcc3c9c38f4b14e42b4632291343bf343 Mon Sep 17 00:00:00 2001
From: Andreas Haerter <netzmeister@andreas-haerter.de>
Date: Fri, 24 Jul 2009 10:40:09 +0200
Subject: [PATCH] Much faster version of utf8_isASCII()

Ignore-this: 1adbc2b33e76b3a76e650c340e9644e6
This version uses a non-capturing regular expression instead of looping through
all characters of the string.

darcs-hash:20090724084009-2cb76-ad1630c7aca53f0bdb596525b0693304a9b4cc88.gz
---
 inc/utf8.php | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/inc/utf8.php b/inc/utf8.php
index e2f016942..85e5f4f7e 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -62,13 +62,10 @@ if(!function_exists('utf8_isASCII')){
     /**
      * Checks if a string contains 7bit ASCII only
      *
-     * @author Andreas Gohr <andi@splitbrain.org>
+     * @author Andreas Haerter <netzmeister@andreas-haerter.de>
      */
     function utf8_isASCII($str){
-      for($i=0; $i<strlen($str); $i++){
-        if(ord($str{$i}) >127) return false;
-      }
-      return true;
+        return (preg_match('/(?:[^\x00-\x7F])/', $str) !== 1);
     }
 }
 
-- 
GitLab