Browse Source

[cs] Applied patch from issue #1609; fixed hash on 64-bit

Caue Waneck 12 years ago
parent
commit
8f716caf5f
4 changed files with 18 additions and 68 deletions
  1. 1 1
      gencommon.ml
  2. 4 7
      std/cs/_std/Date.hx
  3. 8 58
      std/cs/_std/EReg.hx
  4. 5 2
      std/cs/system/text/regularExpressions/Regex.hx

+ 1 - 1
gencommon.ml

@@ -5942,7 +5942,7 @@ struct
     for i = 0 to String.length f - 1 do
     for i = 0 to String.length f - 1 do
       h := !h * 223 + int_of_char (String.unsafe_get f i);
       h := !h * 223 + int_of_char (String.unsafe_get f i);
     done;
     done;
-    !h
+    if Sys.word_size = 64 then Int32.to_int (Int32.shift_right (Int32.shift_left (Int32.of_int !h) 1) 1) else !h
 
 
   let hash_field ctx f pos =
   let hash_field ctx f pos =
     let h = hash f in
     let h = hash f in

+ 4 - 7
std/cs/_std/Date.hx

@@ -98,12 +98,9 @@ import haxe.Int64;
 	/**
 	/**
 		Returns the week day of the date (0-6 range).
 		Returns the week day of the date (0-6 range).
 	**/
 	**/
-	public function getDay() : Int
+	public inline function getDay() : Int
 	{
 	{
-		var ret = cast(date.DayOfWeek, Int) - 1;
-		if (ret == -1)
-			ret = 6;
-		return ret;
+		return cast(date.DayOfWeek, Int);
 	}
 	}
 
 
 	/**
 	/**
@@ -143,7 +140,7 @@ import haxe.Int64;
 	static public function fromTime( t : Float ) : Date
 	static public function fromTime( t : Float ) : Date
 	{
 	{
 		var d = new Date(0, 0, 0, 0, 0, 0);
 		var d = new Date(0, 0, 0, 0, 0, 0);
-		d.date = new DateTime(cast(t, Int64));
+		d.date = new DateTime(cast(t * TimeSpan.TicksPerMillisecond, Int64));
 		return d;
 		return d;
 	}
 	}
 
 
@@ -180,4 +177,4 @@ import haxe.Int64;
 		date.date = d;
 		date.date = d;
 		return date;
 		return date;
 	}
 	}
-}
+}

+ 8 - 58
std/cs/_std/EReg.hx

@@ -27,7 +27,6 @@ class EReg {
 	private var m : Match;
 	private var m : Match;
 	private var isGlobal : Bool;
 	private var isGlobal : Bool;
 	private var cur : String;
 	private var cur : String;
-	private var sub : Int;
 
 
 	public function new( r : String, opt : String ) : Void {
 	public function new( r : String, opt : String ) : Void {
 		var opts:Int = cast CultureInvariant;
 		var opts:Int = cast CultureInvariant;
@@ -49,7 +48,6 @@ class EReg {
 	}
 	}
 
 
 	public function match( s : String ) : Bool {
 	public function match( s : String ) : Bool {
-		sub = 0;
 		m = regex.Match(s);
 		m = regex.Match(s);
 		cur = s;
 		cur = s;
 		return m.Success;
 		return m.Success;
@@ -58,25 +56,24 @@ class EReg {
 	public function matched( n : Int ) : String {
 	public function matched( n : Int ) : String {
 		if (m == null || cast(n, UInt) > m.Groups.Count)
 		if (m == null || cast(n, UInt) > m.Groups.Count)
 			throw "EReg::matched";
 			throw "EReg::matched";
+		if (!m.Groups[n].Success) return null;
 		return m.Groups[n].Value;
 		return m.Groups[n].Value;
 	}
 	}
 
 
 	public function matchedLeft() : String {
 	public function matchedLeft() : String {
-		return untyped cur.Substring(0, sub + m.Index);
+		return untyped cur.Substring(0, m.Index);
 	}
 	}
 
 
 	public function matchedRight() : String {
 	public function matchedRight() : String {
-		return untyped cur.Substring(sub + m.Index + m.Length);
+		return untyped cur.Substring(m.Index + m.Length);
 	}
 	}
 
 
 	public function matchedPos() : { pos : Int, len : Int } {
 	public function matchedPos() : { pos : Int, len : Int } {
-		return { pos : sub + m.Index, len : m.Length };
+		return { pos : m.Index, len : m.Length };
 	}
 	}
 
 
 	public function matchSub( s : String, pos : Int, len : Int = -1):Bool {
 	public function matchSub( s : String, pos : Int, len : Int = -1):Bool {
-		var s2 = (len < 0 ? s.substr(pos) : s.substr(pos, len));
-		sub = pos;
-		m = regex.Match(s2);
+		m= if (len<0) regex.Match(s,pos) else regex.Match(s, pos, len);
 		cur = s;
 		cur = s;
 		return m.Success;
 		return m.Success;
 	}
 	}
@@ -85,12 +82,13 @@ class EReg {
 		if (isGlobal)
 		if (isGlobal)
 			return cs.Lib.array(regex.Split(s));
 			return cs.Lib.array(regex.Split(s));
 		var m = regex.Match(s);
 		var m = regex.Match(s);
+		if (!m.Success) return [s];
 		return untyped [s.Substring(0, m.Index), s.Substring(m.Index + m.Length)];
 		return untyped [s.Substring(0, m.Index), s.Substring(m.Index + m.Length)];
 	}
 	}
 
 
 	inline function start(group:Int)
 	inline function start(group:Int)
 	{
 	{
-		return m.Groups[group].Index + sub;
+		return m.Groups[group].Index;
 	}
 	}
 
 
 	inline function len(group:Int)
 	inline function len(group:Int)
@@ -100,55 +98,7 @@ class EReg {
 
 
 	public function replace( s : String, by : String ) : String
 	public function replace( s : String, by : String ) : String
 	{
 	{
-      var b = new StringBuf();
-      var pos = 0;
-      var len = s.length;
-      var a = by.split("$");
-      var first = true;
-      do {
-        if( !matchSub(s,pos,len) )
-          break;
-        var p = matchedPos();
-        if( p.len == 0 && !first ) {
-          if( p.pos == s.length )
-            break;
-          p.pos += 1;
-        }
-        b.addSub(s,pos,p.pos-pos);
-        if( a.length > 0 )
-          b.add(a[0]);
-        var i = 1;
-        while( i < a.length ) {
-          var k = a[i];
-          var c = k.charCodeAt(0);
-          // 1...9
-          if( c >= 49 && c <= 57 ) {
-						try {
-							var ppos = start( c-48 ), plen = this.len( c-48 );
-							b.addSub(s, ppos, plen);
-						}
-						catch(e:Dynamic)
-						{
-							b.add("$");
-							b.add(k);
-						}
-          } else if( c == null ) {
-            b.add("$");
-            i++;
-            var k2 = a[i];
-            if( k2 != null && k2.length > 0 )
-              b.add(k2);
-          } else
-            b.add("$"+k);
-          i++;
-        }
-        var tot = p.pos + p.len - pos;
-        pos += tot;
-        len -= tot;
-        first = false;
-      } while( isGlobal );
-      b.addSub(s,pos,len);
-      return b.toString();
+      return (isGlobal) ? regex.Replace(s, by): regex.Replace(s,by,1);
 	}
 	}
 
 
 	public function map( s : String, f : EReg -> String ) : String {
 	public function map( s : String, f : EReg -> String ) : String {

+ 5 - 2
std/cs/system/text/regularExpressions/Regex.hx

@@ -22,11 +22,14 @@
 package cs.system.text.regularExpressions;
 package cs.system.text.regularExpressions;
 import cs.NativeArray;
 import cs.NativeArray;
 
 
-@:native('System.Text.RegularExpressions.Regex') extern class Regex 
+@:native('System.Text.RegularExpressions.Regex') extern class Regex
 {
 {
 	function new(pattern:String, options:RegexOptions):Void;
 	function new(pattern:String, options:RegexOptions):Void;
+	@:overload(function(input:String, startPos:Int, len:Int):Match{})
+	@:overload(function(input:String, startPos:Int):Match{})
 	function Match(input:String):Match;
 	function Match(input:String):Match;
 	function Split(input:String):NativeArray<String>;
 	function Split(input:String):NativeArray<String>;
+	@:overload(function(input:String, replacement:String,max:Int):String{})
 	function Replace(input:String, replacement:String):String;
 	function Replace(input:String, replacement:String):String;
 }
 }
 
 
@@ -70,4 +73,4 @@ import cs.NativeArray;
 @:native("System.Text.RegularExpressions.GroupCollection") extern class GroupCollection implements ArrayAccess<Group>
 @:native("System.Text.RegularExpressions.GroupCollection") extern class GroupCollection implements ArrayAccess<Group>
 {
 {
 	var Count(default, null):Int;
 	var Count(default, null):Int;
-}
+}