소스 검색

impl sum & translate

svn path=/trunk/mcs/; revision=18161
Ben Maurer 22 년 전
부모
커밋
0488e87a2e
2개의 변경된 파일35개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 0
      mcs/class/System.XML/System.Xml.XPath/ChangeLog
  2. 31 4
      mcs/class/System.XML/System.Xml.XPath/DefaultContext.cs

+ 4 - 0
mcs/class/System.XML/System.Xml.XPath/ChangeLog

@@ -1,3 +1,7 @@
+2003-09-17 Ben Maurer  <[email protected]>
+
+	* DefaultContext.cs: implement sum () and translate ().
+
 2003-09-13 Ben Maurer  <[email protected]>
 
 	* XPathNavigator.cs: Make methods where you pass in the context,

+ 31 - 4
mcs/class/System.XML/System.Xml.XPath/DefaultContext.cs

@@ -81,6 +81,15 @@ namespace System.Xml.XPath
 				return Convert.ToDouble ((bool) arg);
 			throw new ArgumentException ();
 		}
+		
+		public static double ToNumber (string arg)
+		{
+			try {
+				return XmlConvert.ToDouble ((string) arg);	// TODO: spec? convert string to number
+			} catch (System.FormatException) {
+				return double.NaN;
+			}
+		}
 	}
 
 	internal abstract class XPathFunction : Expression
@@ -571,10 +580,23 @@ namespace System.Xml.XPath
 		
 		public override XPathResultType ReturnType { get { return XPathResultType.String; }}
 		
-		[MonoTODO]
 		public override object Evaluate (BaseIterator iter)
 		{
-			throw new NotImplementedException ();
+			string s0 = arg0.EvaluateString (iter);
+			string s1 = arg1.EvaluateString (iter);
+			string s2 = arg2.EvaluateString (iter);
+			
+			StringBuilder ret = new StringBuilder (s0.Length);
+				
+			int pos = 0, len = s0.Length, s2Len = s2.Length;
+			
+			while (pos < len) {
+				int idx = s1.IndexOf (s0 [pos], 0, s2Len);
+				ret.Append (idx != -1 ? s2 [idx] : s0 [pos]);
+				pos++;
+			}
+			
+			return ret.ToString ();
 		}
 	}
 
@@ -716,10 +738,15 @@ namespace System.Xml.XPath
 		
 		public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
 
-		[MonoTODO]
 		public override object Evaluate (BaseIterator iter)
 		{
-			throw new NotImplementedException ();
+			XPathNodeIterator itr = arg0.EvaluateNodeSet (iter);
+			
+			double sum = 0;
+			while (itr.MoveNext ())
+				sum += XPathFunctions.ToNumber (itr.Current.Value);
+			
+			return sum;
 		}
 	}