Browse Source

[Php] String.charAt now returns "" if index < 0

Simon Krajewski 12 years ago
parent
commit
0f46ac69d5
1 changed files with 9 additions and 4 deletions
  1. 9 4
      std/php/Boot.hx

+ 9 - 4
std/php/Boot.hx

@@ -233,7 +233,12 @@ function _hx_cast($v, $type) {
 	}
 	}
 }
 }
 
 
-function _hx_char_at($o, $i) { $c = substr($o, $i, 1); return FALSE === $c ? '' : $c; }
+function _hx_char_at($o, $i) {
+	if ($i < 0)
+		return '';
+	$c = substr($o, $i, 1);
+	return FALSE === $c ? '' : $c;
+}
 
 
 function _hx_char_code_at($s, $pos) {
 function _hx_char_code_at($s, $pos) {
 	if($pos < 0 || $pos >= strlen($s)) return null;
 	if($pos < 0 || $pos >= strlen($s)) return null;
@@ -265,7 +270,7 @@ function _hx_mod($x, $y) {
 	}
 	}
 	if (!is_nan($x) && !is_nan($y) && !is_finite($y) && is_finite($x)) {
 	if (!is_nan($x) && !is_nan($y) && !is_finite($y) && is_finite($x)) {
 		return $x;
 		return $x;
-	} 
+	}
 	return fmod($x, $y);
 	return fmod($x, $y);
 }
 }
 
 
@@ -641,12 +646,12 @@ function _hx_substring($s, $startIndex, $endIndex) {
 		$endIndex = 0;
 		$endIndex = 0;
 	else if ($endIndex > $len)
 	else if ($endIndex > $len)
 		$endIndex  = $len;
 		$endIndex  = $len;
-		
+
 	if ($startIndex < 0)
 	if ($startIndex < 0)
 		$startIndex = 0;
 		$startIndex = 0;
 	else if ($startIndex > $len)
 	else if ($startIndex > $len)
 		$startIndex = $len;
 		$startIndex = $len;
-		
+
 	if ($startIndex > $endIndex) {
 	if ($startIndex > $endIndex) {
 		$tmp = $startIndex;
 		$tmp = $startIndex;
 		$startIndex = $endIndex;
 		$startIndex = $endIndex;