Browse Source

[cs] fixed some minor C# API errors. Fixed Issue #810 , implemented most of the StringTools API in an optimized way, and added missing StdTypes to cs.StdTypes

Caue Waneck 13 years ago
parent
commit
60b7ee0470
4 changed files with 136 additions and 11 deletions
  1. 29 6
      std/StringTools.hx
  2. 6 5
      std/cs/StdTypes.hx
  3. 0 0
      std/cs/_std/Array.hx
  4. 101 0
      std/cs/_std/String.hx

+ 29 - 6
std/StringTools.hx

@@ -50,6 +50,8 @@ class StringTools {
 			return s.__URLEncode();
 		#elseif java
 			return untyped __java__("java.net.URLEncoder.encode(s)");
+		#elseif cs
+			return untyped __cs__("System.Uri.EscapeUriString(s)");
 		#else
 			return null;
 		#end
@@ -73,6 +75,8 @@ class StringTools {
 			return s.__URLDecode();
 		#elseif java
 			return untyped __java__("java.net.URLDecoder.decode(s)");
+		#elseif cs
+			return untyped __cs__("System.Uri.UnescapeDataString(s)");
 		#else
 			return null;
 		#end
@@ -99,9 +103,11 @@ class StringTools {
 	/**
 		Tells if the string [s] starts with the string [start].
 	**/
-	public static #if java inline #end function startsWith( s : String, start : String ) {
+	public static #if (java || cs) inline #end function startsWith( s : String, start : String ) {
 		#if java
 		return untyped s.startsWith(start);
+		#elseif cs
+		return untyped s.StartsWith(start);
 		#else
 		return( s.length >= start.length && s.substr(0, start.length) == start );
 		#end
@@ -110,9 +116,11 @@ class StringTools {
 	/**
 		Tells if the string [s] ends with the string [end].
 	**/
-	public static #if java inline #end function endsWith( s : String, end : String ) {
+	public static #if (java || cs) inline #end function endsWith( s : String, end : String ) {
 		#if java
 		return untyped s.endsWith(end);
+		#elseif cs
+		return untyped s.EndsWith(end);
 		#else
 		var elen = end.length;
 		var slen = s.length;
@@ -131,9 +139,11 @@ class StringTools {
 	/**
 		Removes spaces at the left of the String [s].
 	**/
-	public #if php inline #end static function ltrim( s : String ) : String {
+	public #if (php || cs) inline #end static function ltrim( s : String ) : String {
 		#if php
 		return untyped __call__("ltrim", s);
+		#elseif cs
+		return untyped s.TrimStart();
 		#else
 		var l = s.length;
 		var r = 0;
@@ -150,9 +160,11 @@ class StringTools {
 	/**
 		Removes spaces at the right of the String [s].
 	**/
-	public #if php inline #end static function rtrim( s : String ) : String {
+	public #if (php || cs) inline #end static function rtrim( s : String ) : String {
 		#if php
 		return untyped __call__("rtrim", s);
+		#elseif cs
+		return untyped s.TrimEnd();
 		#else
 		var l = s.length;
 		var r = 0;
@@ -170,9 +182,11 @@ class StringTools {
 	/**
 		Removes spaces at the beginning and the end of the String [s].
 	**/
-	public #if php inline #end static function trim( s : String ) : String {
+	public #if (php || cs) inline #end static function trim( s : String ) : String {
 		#if php
 		return untyped __call__("trim", s);
+		#elseif cs
+		return untyped s.Trim();
 		#else
 		return ltrim(rtrim(s));
 		#end
@@ -233,6 +247,8 @@ class StringTools {
 		return untyped __call__("str_replace", sub, by, s);
 		#elseif java
 		return untyped s.replace(sub, by);
+		#elseif cs
+		return untyped s.Replace(sub, by);
 		#else
 		return s.split(sub).join(by);
 		#end
@@ -264,7 +280,7 @@ class StringTools {
 		Provides a fast native string charCodeAt access. Since the EOF value might vary depending on the platforms, always test with StringTools.isEOF.
 		Only guaranteed to work if index in [0,s.length] range. Might not work with strings containing \0 char.
 	**/
-	public static inline function fastCodeAt( s : String, index : Int ) : Int untyped {
+		public static #if !cs inline #end function fastCodeAt( s : String, index : Int ) : Int untyped {
 		#if neko
 		return untyped __dollar__sget(s.__s, index);
 		#elseif cpp
@@ -275,6 +291,11 @@ class StringTools {
 		return s["cca"](index);
 		#elseif java
 		return s.charCodeAt(index);
+		#elseif cs
+		if (cast(index, UInt) >= s.length)
+			return 0;
+		else
+			return cast(untyped s[index], Int);
 		#else
 		return s.cca(index);
 		#end
@@ -292,6 +313,8 @@ class StringTools {
 		return c != c; // fast NaN
 		#elseif neko
 		return c == null;
+		#elseif cs
+		return c == 0;
 		#else
 		return false;
 		#end

+ 6 - 5
std/cs/StdTypes.hx

@@ -1,8 +1,9 @@
 package cs;
 
-/**
- * ...
- * @author waneck
- */
-
+typedef Int8 = Int;
+typedef UInt8 = Int;
+typedef Int16 = Int;
+typedef UInt16 = Int;
+//UInt is top-level
+typedef UInt64 = haxe.Int64;
 typedef Char16 = Int;

File diff suppressed because it is too large
+ 0 - 0
std/cs/_std/Array.hx


+ 101 - 0
std/cs/_std/String.hx

@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+import cs.StdTypes;
+
+/**
+	The basic String class.
+**/
+extern class String implements ArrayAccess<Char16> {
+
+	/**
+		The number of characters in the String.
+	**/
+	var length(default,null) : Int;
+
+	/**
+		Creates a copy from a given String.
+	**/
+	function new(string:String) : Void;
+
+	/**
+		Returns an String where all characters have been uppercased.
+	**/
+	function toUpperCase() : String;
+
+	/**
+		Returns an String where all characters have been lowercased.
+	**/
+	function toLowerCase() : String;
+
+	/**
+		Returns the character at the given position.
+		Returns the empty String if outside of String bounds.
+	**/
+	function charAt( index : Int) : String;
+
+	/**
+		Returns the character code at the given position.
+		Returns [null] if outside of String bounds.
+	**/
+	function charCodeAt( index : Int) : Null<Int>;
+
+	/**
+		Returns the index of first occurence of [value]
+		Returns [1-1] if [value] is not found.
+		The optional [startIndex] parameter allows you to specify at which character to start searching.
+		The position returned is still relative to the beginning of the string.
+	**/
+	function indexOf( str : String, ?startIndex : Int ) : Int;
+
+	/**
+		Similar to [indexOf] but returns the latest index.
+	**/
+	function lastIndexOf( str : String, ?startIndex : Int ) : Int;
+
+	/**
+		Split the string using the specified delimiter.
+	**/
+	function split( delimiter : String ) : Array<String>;
+
+	/**
+		Returns a part of the String, taking [len] characters starting from [pos].
+		If [len] is not specified, it takes all the remaining characters.
+	**/
+	function substr( pos : Int, ?len : Int ) : String;
+
+	/**
+		Returns the String itself.
+	**/
+	function toString() : String;
+
+	static function fromCharCode( code : Int ) : String;
+	
+	private function Replace(oldValue:String, newValue:String):String;
+	private function StartsWith(value:String):Bool;
+	private function EndsWith(value:String):Bool;
+	private function TrimStart():String;
+	private function TrimEnd():String;
+
+}

Some files were not shown because too many files changed in this diff