Forráskód Böngészése

2007-03-15 Igor Zelmanovich <[email protected]>

	* VirtualPathUtility.cs: refactoring: class is shared with 1.x.

svn path=/trunk/mcs/; revision=74372
Igor Zelmanovich 19 éve
szülő
commit
64f6d6228f

+ 34 - 0
mcs/class/System.Web/System.Web.Util/StrUtils.cs

@@ -95,6 +95,40 @@ namespace System.Web.Util {
 				return sb.ToString ();
 			return attributeValue;
 		}
+
+		public static bool IsNullOrEmpty (string value)
+		{
+#if NET_2_0
+			return String.IsNullOrEmpty (value);
+#else
+			return value == null || value.Length == 0;
+#endif
+		}
+
+		public static string [] SplitRemoveEmptyEntries (string value, char [] separator)
+		{
+#if NET_2_0
+			return value.Split (separator, StringSplitOptions.RemoveEmptyEntries);
+#else
+			string [] parts = value.Split (separator);
+			int delta = 0;
+			for (int i = 0; i < parts.Length; i++) {
+				if (IsNullOrEmpty (parts [i])) {
+					delta++;
+				}
+				else {
+					if (delta > 0)
+						parts [i - delta] = parts [i];
+				}
+			}
+			if (delta == 0)
+				return parts;
+
+			string [] parts_copy = new string [parts.Length - delta];
+			Array.Copy (parts, parts_copy, parts_copy.Length);
+			return parts_copy;
+#endif
+		}
 	}
 }
 

+ 4 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,7 @@
+2007-03-15 Igor Zelmanovich <[email protected]>
+
+	* VirtualPathUtility.cs: refactoring: class is shared with 1.x.
+
 2007-03-15  Marek Habersack  <[email protected]>
 
 	* XmlSiteMapProvider.cs: add support for the enableLocalization

+ 10 - 13
mcs/class/System.Web/System.Web/VirtualPathUtility.cs

@@ -29,14 +29,16 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 
 using System.Web.Util;
 using System.Text;
 
 namespace System.Web {
 
-	public static class VirtualPathUtility
+#if NET_2_0
+	public
+#endif
+	static class VirtualPathUtility
 	{
 		public static string AppendTrailingSlash (string virtualPath)
 		{
@@ -122,7 +124,7 @@ namespace System.Web {
 
 		public static bool IsAbsolute (string virtualPath)
 		{
-			if (String.IsNullOrEmpty (virtualPath))
+			if (StrUtils.IsNullOrEmpty (virtualPath))
 				throw new ArgumentNullException ("virtualPath");
 
 			return (virtualPath [0] == '/');
@@ -130,7 +132,7 @@ namespace System.Web {
 
 		public static bool IsAppRelative (string virtualPath)
 		{
-			if (String.IsNullOrEmpty (virtualPath))
+			if (StrUtils.IsNullOrEmpty (virtualPath))
 				throw new ArgumentNullException ("virtualPath");
 
 			if (virtualPath.Length == 1 && virtualPath [0] == '~')
@@ -214,10 +216,10 @@ namespace System.Web {
 		// Not rooted, the ToAbsolute method raises an ArgumentOutOfRangeException exception.
 		public static string ToAbsolute (string virtualPath, string applicationPath)
 		{
-			if (String.IsNullOrEmpty (applicationPath))
+			if (StrUtils.IsNullOrEmpty (applicationPath))
 				throw new ArgumentNullException ("applicationPath");
 
-			if (String.IsNullOrEmpty (virtualPath))
+			if (StrUtils.IsNullOrEmpty (virtualPath))
 				throw new ArgumentNullException ("virtualPath");
 
 			if (IsAppRelative(virtualPath)) {
@@ -298,7 +300,7 @@ namespace System.Web {
 			if (path [path.Length - 1] == '/')
 				ends_with_slash = true;
 
-			string [] parts = path.Split (path_sep, StringSplitOptions.RemoveEmptyEntries);
+			string [] parts = StrUtils.SplitRemoveEmptyEntries (path, path_sep);
 			int end = parts.Length;
 
 			int dest = 0;
@@ -317,7 +319,7 @@ namespace System.Web {
 					if (starts_with_tilda) {
 						if (apppath_parts == null) {
 							string apppath = HttpRuntime.AppDomainAppVirtualPath;
-							apppath_parts = apppath.Split (path_sep, StringSplitOptions.RemoveEmptyEntries);
+							apppath_parts = StrUtils.SplitRemoveEmptyEntries (apppath, path_sep);
 						}
 
 						if ((apppath_parts.Length + dest) >= 0)
@@ -398,8 +400,3 @@ namespace System.Web {
 
 	}
 }
-
-#endif
-
-
-