summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorrojaro <>2009-11-01 21:02:35 +0000
committerrojaro <>2009-11-01 21:02:35 +0000
commit0c3d50c302422a9d735e8532bddb1ba588bf9d2f (patch)
treec26b125a086796c629f4952972504b0c645a924c /framework
parent65dda2deb497d86ae96e12e62258776b71ebc7dc (diff)
merged quotestring utf8 patch ... see http://www.pradosoft.com/forum/index.php?topic=11700.msg51530;topicseen#msg51530
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/Javascripts/TJavaScript.php35
1 files changed, 31 insertions, 4 deletions
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index 2134c2d1..2b2a2529 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -84,10 +84,37 @@ class TJavaScript
*/
public static function quoteString($js,$forUrl=false)
{
- if($forUrl)
- return strtr($js,array('%'=>'%25',"\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\'));
- else
- return strtr($js,array("\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\'));
+ return self::quoteUTF8(($forUrl) ? strtr($js,array('%'=>'%25',"\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\')) : strtr($js,array("\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\')));
+ }
+
+ public static function quoteUTF8($str)
+ {
+ $entities = '';
+ $length = strlen($str);
+ $lookingFor = 1;
+ $unicode = array();
+ $values = array();
+
+ for($i=0;$i<$length;$i++) {
+ $thisValue = ord($str[$i]);
+ if($thisValue < 128)
+ $unicode[] = $thisValue;
+ else {
+ if(count($values)==0)
+ $lookingFor = ($thisValue<224) ? 2 : 3;
+ $values[] = $thisValue;
+ if(count($values)==$lookingFor) {
+ $unicode[] = ($lookingFor == 3) ? (($values[0]%16)*4096)+(($values[1]%64)*64)+($values[2]%64) : (($values[0]%32)*64)+($values[1]%64);
+ $values = array();
+ $lookingFor = 1;
+ }
+ }
+ }
+
+ foreach($unicode as $value)
+ $entities .= ($value < 128) ? chr($value) : '\u'.str_pad(dechex($value), 4, '0', STR_PAD_LEFT);
+
+ return $entities;
}
/**