コード例 #1
0
        public void SparqlExpressionsXPathReplaceNullInCanParallelise2()
        {
            // when
            var             find    = new VariableTerm("find");
            var             replace = new ConstantTerm(new StringNode(null, "replacement"));
            ReplaceFunction func    = new ReplaceFunction(new VariableTerm("term"), find, replace);

            // then
            var canParallelise = func.CanParallelise;
        }
コード例 #2
0
        public void TestNullEmptyBefore()
        {
            var function = new ReplaceFunction();

            try
            {
                function.Evaluate("abcdef", null, "-");
                Assert.Fail("Expected exception");
            }
            catch (ArgumentException)
            {
                //oke
            }
        }
コード例 #3
0
        public void TestNullAll()
        {
            var function = new ReplaceFunction();

            try
            {
                function.Evaluate(null, null, null);
                Assert.Fail("Expected exception");
            }
            catch (ArgumentException)
            {
                //oke
            }
        }
コード例 #4
0
        /// <summary>
        /// Tries to create an XPath Function expression if the function Uri correseponds to a supported XPath Function.
        /// </summary>
        /// <param name="u">Function Uri.</param>
        /// <param name="args">Function Arguments.</param>
        /// <param name="scalarArgs">Scalar Arguments.</param>
        /// <param name="expr">Generated Expression.</param>
        /// <returns>Whether an expression was successfully generated.</returns>
        public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <String, ISparqlExpression> scalarArgs, out ISparqlExpression expr)
        {
            // If any Scalar Arguments are present then can't possibly be an XPath Function
            if (scalarArgs.Count > 0)
            {
                expr = null;
                return(false);
            }

            String func = u.AbsoluteUri;

            if (func.StartsWith(XPathFunctionsNamespace))
            {
                func = func.Substring(XPathFunctionsNamespace.Length);
                ISparqlExpression xpathFunc = null;

                switch (func)
                {
                case Absolute:
                    if (args.Count == 1)
                    {
                        xpathFunc = new AbsFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath abs() function");
                    }
                    break;

                case AdjustDateTimeToTimezone:
                    throw new NotSupportedException("XPath adjust-dateTime-to-timezone() function is not supported");

                case Boolean:
                    if (args.Count == 1)
                    {
                        xpathFunc = new BooleanFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath boolean() function");
                    }
                    throw new NotSupportedException("XPath boolean() function is not supported");

                case Ceiling:
                    if (args.Count == 1)
                    {
                        xpathFunc = new CeilingFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath ceiling() function");
                    }
                    break;

                case Compare:
                    if (args.Count == 2)
                    {
                        xpathFunc = new CompareFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath compare() function");
                    }
                    break;

                case Concat:
                    if (args.Count == 2)
                    {
                        xpathFunc = new ConcatFunction(args.First(), args.Last());
                    }
                    else if (args.Count > 2)
                    {
                        xpathFunc = new ConcatFunction(args);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath concat() function");
                    }
                    break;

                case Contains:
                    if (args.Count == 2)
                    {
                        xpathFunc = new ContainsFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath contains() function");
                    }
                    break;

                case DayFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new DayFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath day-from-dateTime() function");
                    }
                    break;

                case EncodeForURI:
                    if (args.Count == 1)
                    {
                        xpathFunc = new EncodeForUriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath encode-for-uri() function");
                    }
                    break;

                case EndsWith:
                    if (args.Count == 2)
                    {
                        xpathFunc = new EndsWithFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath ends-with() function");
                    }
                    break;

                case EscapeHtmlURI:
                    if (args.Count == 1)
                    {
                        xpathFunc = new EscapeHtmlUriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath escape-html-uri() function");
                    }
                    break;

                case False:
                    if (args.Count == 0)
                    {
                        xpathFunc = new ConstantTerm(new BooleanNode(null, false));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath false() function");
                    }
                    break;

                case Floor:
                    if (args.Count == 1)
                    {
                        xpathFunc = new FloorFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath floor() function");
                    }
                    break;

                case HoursFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new HoursFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath hours-from-dateTime() function");
                    }
                    break;

                case LowerCase:
                    if (args.Count == 1)
                    {
                        xpathFunc = new LowerCaseFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath lower-case() function");
                    }
                    break;

                case Matches:
                    if (args.Count == 2)
                    {
                        xpathFunc = new Functions.Sparql.Boolean.RegexFunction(args.First(), args.Last());
                    }
                    else if (args.Count == 3)
                    {
                        xpathFunc = new Functions.Sparql.Boolean.RegexFunction(args.First(), args[1], args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath matches() function");
                    }
                    break;

                case MinutesFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new MinutesFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath minutes-from-dateTime() function");
                    }
                    break;

                case MonthFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new MonthFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath month-from-dateTime() function");
                    }
                    break;

                case NormalizeSpace:
                    if (args.Count == 1)
                    {
                        xpathFunc = new NormalizeSpaceFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                    }
                    break;

                case NormalizeUnicode:
                    if (args.Count == 1)
                    {
                        xpathFunc = new NormalizeUnicodeFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        xpathFunc = new NormalizeUnicodeFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                    }
                    break;

                case Not:
                    if (args.Count == 1)
                    {
                        xpathFunc = new NotExpression(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath not() function");
                    }
                    break;

                case Replace:
                    if (args.Count == 3)
                    {
                        xpathFunc = new ReplaceFunction(args.First(), args[1], args.Last());
                    }
                    else if (args.Count == 4)
                    {
                        xpathFunc = new ReplaceFunction(args.First(), args[1], args[2], args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath replace() function");
                    }
                    break;

                case Round:
                    if (args.Count == 1)
                    {
                        xpathFunc = new RoundFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath round() function");
                    }
                    break;

                case RoundHalfToEven:
                    if (args.Count == 1)
                    {
                        xpathFunc = new RoundHalfToEvenFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        xpathFunc = new RoundHalfToEvenFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath round-half-to-even() function");
                    }
                    break;

                case SecondsFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new SecondsFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath seconds-from-dateTime() function");
                    }
                    break;

                case StartsWith:
                    if (args.Count == 2)
                    {
                        xpathFunc = new StartsWithFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath starts-with() function");
                    }
                    break;

                case StringJoin:
                    if (args.Count == 1)
                    {
                        xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First()));
                    }
                    else if (args.Count == 2)
                    {
                        xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First(), args.Last()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath string-join() function");
                    }
                    break;

                case StringLength:
                    if (args.Count == 1)
                    {
                        xpathFunc = new StringLengthFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath string-length() function");
                    }
                    break;

                case Substring:
                    if (args.Count == 2)
                    {
                        xpathFunc = new SubstringFunction(args.First(), args.Last());
                    }
                    else if (args.Count == 3)
                    {
                        xpathFunc = new SubstringFunction(args.First(), args[1], args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath substring() function");
                    }
                    break;

                case SubstringAfter:
                    if (args.Count == 2)
                    {
                        xpathFunc = new SubstringAfterFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath substring-after() function");
                    }
                    break;

                case SubstringBefore:
                    if (args.Count == 2)
                    {
                        xpathFunc = new SubstringBeforeFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath substring-before() function");
                    }
                    break;

                case TimezoneFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new TimezoneFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath timezone-from-dateTime() function");
                    }
                    break;

                case Translate:
                    throw new NotSupportedException("XPath translate() function is not supported");

                case True:
                    if (args.Count == 0)
                    {
                        xpathFunc = new ConstantTerm(new BooleanNode(null, true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath true() function");
                    }
                    break;

                case UpperCase:
                    if (args.Count == 1)
                    {
                        xpathFunc = new UpperCaseFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath upper-case() function");
                    }
                    break;

                case YearFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new YearFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath year-from-dateTime() function");
                    }
                    break;
                }

                if (xpathFunc != null)
                {
                    expr = xpathFunc;
                    return(true);
                }
            }
            expr = null;
            return(false);
        }
コード例 #5
0
ファイル: XPathFunctionFactory.cs プロジェクト: jmahmud/RDFer
        /// <summary>
        /// Tries to create an XPath Function expression if the function Uri correseponds to a supported XPath Function
        /// </summary>
        /// <param name="u">Function Uri</param>
        /// <param name="args">Function Arguments</param>
        /// <param name="scalarArgs">Scalar Arguments</param>
        /// <param name="expr">Generated Expression</param>
        /// <returns>Whether an expression was successfully generated</returns>
        public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<String,ISparqlExpression> scalarArgs, out ISparqlExpression expr)
        {
            //If any Scalar Arguments are present then can't possibly be an XPath Function
            if (scalarArgs.Count > 0)
            {
                expr = null;
                return false;
            }

            String func = u.ToString();
            if (func.StartsWith(XPathFunctionFactory.XPathFunctionsNamespace))
            {
                func = func.Substring(XPathFunctionFactory.XPathFunctionsNamespace.Length);
                ISparqlExpression xpathFunc = null;

                switch (func)
                {
                    case XPathFunctionFactory.Absolute:
                        if (args.Count == 1)
                        {
                            xpathFunc = new AbsFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath abs() function");
                        }
                        break;
                    case XPathFunctionFactory.AdjustDateTimeToTimezone:
                        throw new NotSupportedException("XPath adjust-dateTime-to-timezone() function is not supported");
                    case XPathFunctionFactory.Boolean:
                        if (args.Count == 1)
                        {
                            xpathFunc = new BooleanFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath boolean() function");
                        }
                        throw new NotSupportedException("XPath boolean() function is not supported");
                    case XPathFunctionFactory.Ceiling:
                        if (args.Count == 1)
                        {
                            xpathFunc = new CeilingFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath ceiling() function");
                        }
                        break;
                    case XPathFunctionFactory.Compare:
                        if (args.Count == 2)
                        {
                            xpathFunc = new CompareFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath compare() function");
                        }
                        break;
                    case XPathFunctionFactory.Concat:
                        if (args.Count == 2)
                        {
                            xpathFunc = new ConcatFunction(args.First(), args.Last());
                        }
                        else if (args.Count > 2)
                        {
                            xpathFunc = new ConcatFunction(args);
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath concat() function");
                        }
                        break;
                    case XPathFunctionFactory.Contains:
                        if (args.Count == 2)
                        {
                            xpathFunc = new ContainsFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath contains() function");
                        }
                        break;
                    case XPathFunctionFactory.DayFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new DayFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath day-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.EncodeForURI:
                        if (args.Count == 1)
                        {
                            xpathFunc = new EncodeForUriFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath encode-for-uri() function");
                        }
                        break;
                    case XPathFunctionFactory.EndsWith:
                        if (args.Count == 2)
                        {
                            xpathFunc = new EndsWithFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath ends-with() function");
                        }
                        break;
            #if !NO_WEB
                    case XPathFunctionFactory.EscapeHtmlURI:
                        if (args.Count == 1)
                        {
                            xpathFunc = new EscapeHtmlUriFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath escape-html-uri() function");
                        }
                        break;
            #endif
                    case XPathFunctionFactory.False:
                        if (args.Count == 0)
                        {
                            xpathFunc = new ConstantTerm(new BooleanNode(null, false));
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath false() function");
                        }
                        break;
                    case XPathFunctionFactory.Floor:
                        if (args.Count == 1)
                        {
                            xpathFunc = new FloorFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath floor() function");
                        }
                        break;
                    case XPathFunctionFactory.HoursFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new HoursFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath hours-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.LowerCase:
                        if (args.Count == 1)
                        {
                            xpathFunc = new LowerCaseFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath lower-case() function");
                        }
                        break;
                    case XPathFunctionFactory.Matches:
                        if (args.Count == 2)
                        {
                            xpathFunc = new VDS.RDF.Query.Expressions.Functions.Sparql.Boolean.RegexFunction(args.First(), args.Last());
                        }
                        else if (args.Count == 3)
                        {
                            xpathFunc = new VDS.RDF.Query.Expressions.Functions.Sparql.Boolean.RegexFunction(args.First(), args[1], args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath matches() function");
                        }
                        break;
                    case XPathFunctionFactory.MinutesFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new MinutesFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath minutes-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.MonthFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new MonthFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath month-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.NormalizeSpace:
                        if (args.Count == 1)
                        {
                            xpathFunc = new NormalizeSpaceFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                        }
                        break;
            #if !NO_NORM
                    case XPathFunctionFactory.NormalizeUnicode:
                        if (args.Count == 1)
                        {
                            xpathFunc = new NormalizeUnicodeFunction(args.First());
                        }
                        else if (args.Count == 2)
                        {
                            xpathFunc = new NormalizeUnicodeFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                        }
                        break;
            #endif
                    case XPathFunctionFactory.Not:
                        if (args.Count == 1)
                        {
                            xpathFunc = new NotExpression(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath not() function");
                        }
                        break;
                    case XPathFunctionFactory.Replace:
                        if (args.Count == 3)
                        {
                            xpathFunc = new ReplaceFunction(args.First(), args[1], args.Last());
                        }
                        else if (args.Count == 4)
                        {
                            xpathFunc = new ReplaceFunction(args.First(), args[1], args[2], args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath replace() function");
                        }
                        break;
                    case XPathFunctionFactory.Round:
                        if (args.Count == 1)
                        {
                            xpathFunc = new RoundFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath round() function");
                        }
                        break;
            #if !SILVERLIGHT
                    case XPathFunctionFactory.RoundHalfToEven:
                        if (args.Count == 1)
                        {
                            xpathFunc = new RoundHalfToEvenFunction(args.First());
                        }
                        else if (args.Count == 2)
                        {
                            xpathFunc = new RoundHalfToEvenFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath round-half-to-even() function");
                        }
                        break;
            #endif
                    case XPathFunctionFactory.SecondsFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new SecondsFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath seconds-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.StartsWith:
                        if (args.Count == 2)
                        {
                            xpathFunc = new StartsWithFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath starts-with() function");
                        }
                        break;
                    case XPathFunctionFactory.StringJoin:
                        if (args.Count == 1)
                        {
                            xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First()));
                        }
                        else if (args.Count == 2)
                        {
                            xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First(), args.Last()));
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath string-join() function");
                        }
                        break;
                    case XPathFunctionFactory.StringLength:
                        if (args.Count == 1)
                        {
                            xpathFunc = new StringLengthFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath string-length() function");
                        }
                        break;
                    case XPathFunctionFactory.Substring:
                        if (args.Count == 2)
                        {
                            xpathFunc = new SubstringFunction(args.First(), args.Last());
                        }
                        else if (args.Count == 3)
                        {
                            xpathFunc = new SubstringFunction(args.First(), args[1], args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath substring() function");
                        }
                        break;
                    case XPathFunctionFactory.SubstringAfter:
                        if (args.Count == 2)
                        {
                            xpathFunc = new SubstringAfterFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath substring-after() function");
                        }
                        break;
                    case XPathFunctionFactory.SubstringBefore:
                        if (args.Count == 2)
                        {
                            xpathFunc = new SubstringBeforeFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath substring-before() function");
                        }
                        break;
                    case XPathFunctionFactory.TimezoneFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new TimezoneFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath timezone-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.Translate:
                        throw new NotSupportedException("XPath translate() function is not supported");
                    case XPathFunctionFactory.True:
                        if (args.Count == 0)
                        {
                            xpathFunc = new ConstantTerm(new BooleanNode(null, true));
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath true() function");
                        }
                        break;
                    case XPathFunctionFactory.UpperCase:
                        if (args.Count == 1)
                        {
                            xpathFunc = new UpperCaseFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath upper-case() function");
                        }
                        break;
                    case XPathFunctionFactory.YearFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new YearFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath year-from-dateTime() function");
                        }
                        break;
                }

                if (xpathFunc != null)
                {
                    expr = xpathFunc;
                    return true;
                }
            }
            expr = null;
            return false;
        }
コード例 #6
0
        public void TestNullSource()
        {
            var function = new ReplaceFunction();

            Assert.That(function.Evaluate(null, "a", "b"), Is.EqualTo(""));
        }
コード例 #7
0
        public void TestNullEmptyAfter()
        {
            var function = new ReplaceFunction();

            Assert.That(function.Evaluate("a-b-c-d-e-f", "-", null), Is.EqualTo("abcdef"));
        }
コード例 #8
0
        public void TestAllFilled()
        {
            var function = new ReplaceFunction();

            Assert.That(function.Evaluate("a-b-c-d-e-f", "-", "+"), Is.EqualTo("a+b+c+d+e+f"));
        }