internal static void BooleanLang(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame topSequenceArg = context.TopSequenceArg;
     Value[] sequences = context.Sequences;
     while (topSequenceArg.basePtr <= topSequenceArg.endPtr)
     {
         NodeSequence sequence = sequences[topSequenceArg.basePtr++].Sequence;
         for (int i = 0; i < sequence.Count; i++)
         {
             string strA = context.PeekString(topArg.basePtr).ToUpperInvariant();
             QueryNode node = sequence.Items[i].Node;
             long currentPosition = node.Node.CurrentPosition;
             node.Node.CurrentPosition = node.Position;
             string strB = node.Node.XmlLang.ToUpperInvariant();
             node.Node.CurrentPosition = currentPosition;
             if ((strA.Length == strB.Length) && (string.CompareOrdinal(strA, strB) == 0))
             {
                 context.SetValue(context, topArg.basePtr++, true);
             }
             else if (((strB.Length > 0) && (strA.Length < strB.Length)) && (strB.StartsWith(strA, StringComparison.Ordinal) && (strB[strA.Length] == '-')))
             {
                 context.SetValue(context, topArg.basePtr++, true);
             }
             else
             {
                 context.SetValue(context, topArg.basePtr++, false);
             }
         }
         topSequenceArg.basePtr++;
     }
 }
Exemplo n.º 2
0
        internal static void BooleanLang(ProcessingContext context)
        {
            StackFrame topArg         = context.TopArg;
            StackFrame topSequenceArg = context.TopSequenceArg;

            Value[] sequences = context.Sequences;
            while (topSequenceArg.basePtr <= topSequenceArg.endPtr)
            {
                NodeSequence sequence = sequences[topSequenceArg.basePtr++].Sequence;
                for (int i = 0; i < sequence.Count; i++)
                {
                    string    strA            = context.PeekString(topArg.basePtr).ToUpperInvariant();
                    QueryNode node            = sequence.Items[i].Node;
                    long      currentPosition = node.Node.CurrentPosition;
                    node.Node.CurrentPosition = node.Position;
                    string strB = node.Node.XmlLang.ToUpperInvariant();
                    node.Node.CurrentPosition = currentPosition;
                    if ((strA.Length == strB.Length) && (string.CompareOrdinal(strA, strB) == 0))
                    {
                        context.SetValue(context, topArg.basePtr++, true);
                    }
                    else if (((strB.Length > 0) && (strA.Length < strB.Length)) && (strB.StartsWith(strA, StringComparison.Ordinal) && (strB[strA.Length] == '-')))
                    {
                        context.SetValue(context, topArg.basePtr++, true);
                    }
                    else
                    {
                        context.SetValue(context, topArg.basePtr++, false);
                    }
                }
                topSequenceArg.basePtr++;
            }
        }
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     StackFrame topArg = context.TopArg;
     SeekableXPathNavigator contextNode = context.Processor.ContextNode;
     long currentPosition = contextNode.CurrentPosition;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string str = context.PeekString(topArg.basePtr);
         NodeSequence val = context.CreateSequence();
         if (XPathMessageFunction.MoveToHeader(contextNode) && contextNode.MoveToFirstChild())
         {
             do
             {
                 long num2 = contextNode.CurrentPosition;
                 string str2 = XPathMessageFunctionActor.ExtractFromNavigator(contextNode);
                 contextNode.CurrentPosition = num2;
                 if (str2 == str)
                 {
                     val.Add(contextNode);
                 }
             }
             while (contextNode.MoveToNext());
         }
         context.SetValue(context, topArg.basePtr, val);
         topArg.basePtr++;
     }
     contextNode.CurrentPosition = currentPosition;
 }
        internal override void Eval(ProcessingContext context)
        {
            StackFrame[] frameArray = new StackFrame[this.argCount];
            for (int i = 0; i < this.argCount; i++)
            {
                frameArray[i] = context[i];
            }
            StringBuilder builder = new StringBuilder();

            while (frameArray[0].basePtr <= frameArray[0].endPtr)
            {
                builder.Length = 0;
                for (int k = 0; k < this.argCount; k++)
                {
                    builder.Append(context.PeekString(frameArray[k].basePtr));
                }
                context.SetValue(context, frameArray[this.argCount - 1].basePtr, builder.ToString());
                for (int m = 0; m < this.argCount; m++)
                {
                    frameArray[m].basePtr++;
                }
            }
            for (int j = 0; j < (this.argCount - 1); j++)
            {
                context.PopFrame();
            }
        }
Exemplo n.º 5
0
        internal static void NormalizeSpace(ProcessingContext context)
        {
            StackFrame argStr = context.TopArg;

            StringBuilder builder = new StringBuilder();

            while (argStr.basePtr <= argStr.endPtr)
            {
                char[] whitespace = new char[] { ' ', '\t', '\r', '\n' };
                string str        = context.PeekString(argStr.basePtr).Trim(whitespace);

                bool eatingWhitespace = false;
                builder.Length = 0;
                for (int i = 0; i < str.Length; ++i)
                {
                    char c = str[i];
                    if (XPathCharTypes.IsWhitespace(c))
                    {
                        if (!eatingWhitespace)
                        {
                            builder.Append(' ');
                            eatingWhitespace = true;
                        }
                    }
                    else
                    {
                        builder.Append(c);
                        eatingWhitespace = false;
                    }
                }

                context.SetValue(context, argStr.basePtr, builder.ToString());
                argStr.basePtr++;
            }
        }
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            StackFrame             topArg      = context.TopArg;
            SeekableXPathNavigator contextNode = context.Processor.ContextNode;
            long currentPosition = contextNode.CurrentPosition;

            while (topArg.basePtr <= topArg.endPtr)
            {
                string       str = context.PeekString(topArg.basePtr);
                NodeSequence val = context.CreateSequence();
                if (XPathMessageFunction.MoveToHeader(contextNode) && contextNode.MoveToFirstChild())
                {
                    do
                    {
                        long   num2 = contextNode.CurrentPosition;
                        string str2 = XPathMessageFunctionActor.ExtractFromNavigator(contextNode);
                        contextNode.CurrentPosition = num2;
                        if (str2 == str)
                        {
                            val.Add(contextNode);
                        }
                    }while (contextNode.MoveToNext());
                }
                context.SetValue(context, topArg.basePtr, val);
                topArg.basePtr++;
            }
            contextNode.CurrentPosition = currentPosition;
        }
Exemplo n.º 7
0
        internal override void Eval(ProcessingContext context)
        {
            Fx.Assert(context != null, "");

            StackFrame[] args = new StackFrame[argCount];
            for (int i = 0; i < this.argCount; ++i)
            {
                args[i] = context[i];
            }

            StringBuilder builder = new StringBuilder();

            while (args[0].basePtr <= args[0].endPtr)
            {
                builder.Length = 0;

                for (int i = 0; i < this.argCount; ++i)
                {
                    builder.Append(context.PeekString(args[i].basePtr));
                }

                context.SetValue(context, args[this.argCount - 1].basePtr, builder.ToString());
                for (int i = 0; i < this.argCount; ++i)
                {
                    args[i].basePtr++;
                }
            }

            for (int i = 0; i < this.argCount - 1; ++i)
            {
                context.PopFrame();
            }
        }
Exemplo n.º 8
0
        internal static void SubstringLimit(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;
            StackFrame frame3    = context[2];

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str2;
                string str        = context.PeekString(topArg.basePtr);
                int    startIndex = ((int)Math.Round(context.PeekDouble(secondArg.basePtr))) - 1;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
                int length = (int)Math.Round(context.PeekDouble(frame3.basePtr));
                if ((length < 1) || ((startIndex + length) >= str.Length))
                {
                    str2 = string.Empty;
                }
                else
                {
                    str2 = str.Substring(startIndex, length);
                }
                context.SetValue(context, frame3.basePtr, str2);
                secondArg.basePtr++;
                topArg.basePtr++;
                frame3.basePtr++;
            }
            context.PopFrame();
            context.PopFrame();
        }
 internal override void Eval(ProcessingContext context)
 {
     StackFrame[] frameArray = new StackFrame[this.argCount];
     for (int i = 0; i < this.argCount; i++)
     {
         frameArray[i] = context[i];
     }
     StringBuilder builder = new StringBuilder();
     while (frameArray[0].basePtr <= frameArray[0].endPtr)
     {
         builder.Length = 0;
         for (int k = 0; k < this.argCount; k++)
         {
             builder.Append(context.PeekString(frameArray[k].basePtr));
         }
         context.SetValue(context, frameArray[this.argCount - 1].basePtr, builder.ToString());
         for (int m = 0; m < this.argCount; m++)
         {
             frameArray[m].basePtr++;
         }
     }
     for (int j = 0; j < (this.argCount - 1); j++)
     {
         context.PopFrame();
     }
 }
Exemplo n.º 10
0
        internal static void Translate(ProcessingContext context)
        {
            StackFrame    topArg    = context.TopArg;
            StackFrame    secondArg = context.SecondArg;
            StackFrame    frame3    = context[2];
            StringBuilder builder   = new StringBuilder();

            while (topArg.basePtr <= topArg.endPtr)
            {
                builder.Length = 0;
                string str  = context.PeekString(topArg.basePtr);
                string str2 = context.PeekString(secondArg.basePtr);
                string str3 = context.PeekString(frame3.basePtr);
                for (int i = 0; i < str.Length; i++)
                {
                    char ch    = str[i];
                    int  index = str2.IndexOf(ch);
                    if (index < 0)
                    {
                        builder.Append(ch);
                    }
                    else if (index < str3.Length)
                    {
                        builder.Append(str3[index]);
                    }
                }
                context.SetValue(context, frame3.basePtr, builder.ToString());
                topArg.basePtr++;
                secondArg.basePtr++;
                frame3.basePtr++;
            }
            context.PopFrame();
            context.PopFrame();
        }
Exemplo n.º 11
0
        internal static void NormalizeSpace(ProcessingContext context)
        {
            StackFrame    topArg  = context.TopArg;
            StringBuilder builder = new StringBuilder();

            while (topArg.basePtr <= topArg.endPtr)
            {
                char[] trimChars = new char[] { ' ', '\t', '\r', '\n' };
                string str       = context.PeekString(topArg.basePtr).Trim(trimChars);
                bool   flag      = false;
                builder.Length = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (XPathCharTypes.IsWhitespace(c))
                    {
                        if (!flag)
                        {
                            builder.Append(' ');
                            flag = true;
                        }
                    }
                    else
                    {
                        builder.Append(c);
                        flag = false;
                    }
                }
                context.SetValue(context, topArg.basePtr, builder.ToString());
                topArg.basePtr++;
            }
        }
Exemplo n.º 12
0
        internal static void NodesetCount(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                context.SetValue(context, arg.basePtr, context.PeekSequence(arg.basePtr).Count);
                arg.basePtr++;
            }
        }
Exemplo n.º 13
0
        internal static void NumberFloor(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                context.SetValue(context, topArg.basePtr, Math.Floor(context.PeekDouble(topArg.basePtr)));
                topArg.basePtr++;
            }
        }
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     StackFrame topArg = context.TopArg;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string dateStr = context.PeekString(topArg.basePtr);
         context.SetValue(context, topArg.basePtr, Convert(dateStr));
         topArg.basePtr++;
     }
 }
Exemplo n.º 15
0
        internal static void NodesetCount(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                context.SetValue(context, topArg.basePtr, (double)context.PeekSequence(topArg.basePtr).Count);
                topArg.basePtr++;
            }
        }
Exemplo n.º 16
0
        internal static void StringLength(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                context.SetValue(context, arg.basePtr, context.PeekString(arg.basePtr).Length);
                arg.basePtr++;
            }
        }
Exemplo n.º 17
0
        internal static void StringLength(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                context.SetValue(context, topArg.basePtr, (double)context.PeekString(topArg.basePtr).Length);
                topArg.basePtr++;
            }
        }
Exemplo n.º 18
0
        internal static void NumberCeiling(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                context.SetValue(context, arg.basePtr, Math.Ceiling(context.PeekDouble(arg.basePtr)));
                arg.basePtr++;
            }
        }
Exemplo n.º 19
0
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     StackFrame topArg = context.TopArg;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string spanStr = context.PeekString(topArg.basePtr);
         context.SetValue(context, topArg.basePtr, Convert(spanStr));
         topArg.basePtr++;
     }
 }
Exemplo n.º 20
0
        internal static void NodesetName(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(arg.basePtr);
                context.SetValue(context, arg.basePtr, sequence.Name);
                arg.basePtr++;
            }
        }
Exemplo n.º 21
0
        internal static void NodesetNamespaceUri(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(topArg.basePtr);
                context.SetValue(context, topArg.basePtr, sequence.Namespace);
                topArg.basePtr++;
            }
        }
Exemplo n.º 22
0
        internal static void NumberRound(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                context.PeekDouble(topArg.basePtr);
                context.SetValue(context, topArg.basePtr, QueryValueModel.Round(context.PeekDouble(topArg.basePtr)));
                topArg.basePtr++;
            }
        }
Exemplo n.º 23
0
        internal static void StringConcatTwo(ProcessingContext context)
        {
            StackFrame frame  = context[0];
            StackFrame frame2 = context[1];

            while (frame.basePtr <= frame.endPtr)
            {
                context.SetValue(context, frame2.basePtr, context.PeekString(frame.basePtr) + context.PeekString(frame2.basePtr));
                frame.basePtr++;
                frame2.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 24
0
        internal static void BooleanLang(ProcessingContext context)
        {
            StackFrame langArg   = context.TopArg;
            StackFrame sequences = context.TopSequenceArg;

            Value[] sequenceBuffer = context.Sequences;

            while (sequences.basePtr <= sequences.endPtr)
            {
                NodeSequence sourceSeq = sequenceBuffer[sequences.basePtr++].Sequence;

                for (int item = 0; item < sourceSeq.Count; ++item)
                {
                    string lang = context.PeekString(langArg.basePtr).ToUpperInvariant();

                    QueryNode node = sourceSeq.Items[item].Node;
                    long      pos  = node.Node.CurrentPosition;
                    node.Node.CurrentPosition = node.Position;
                    string docLang = node.Node.XmlLang.ToUpperInvariant();
                    node.Node.CurrentPosition = pos;

                    if (lang.Length == docLang.Length && string.CompareOrdinal(lang, docLang) == 0)
                    {
                        context.SetValue(context, langArg.basePtr++, true);
                    }
                    else if (docLang.Length > 0 && lang.Length < docLang.Length && docLang.StartsWith(lang, StringComparison.Ordinal) && docLang[lang.Length] == '-')
                    {
                        context.SetValue(context, langArg.basePtr++, true);
                    }
                    else
                    {
                        context.SetValue(context, langArg.basePtr++, false);
                    }
                }

                sequences.basePtr++;
            }
        }
Exemplo n.º 25
0
        internal static void StringConcatTwo(ProcessingContext context)
        {
            StackFrame arg1 = context[0];
            StackFrame arg2 = context[1];

            while (arg1.basePtr <= arg1.endPtr)
            {
                string str1 = context.PeekString(arg1.basePtr);
                string str2 = context.PeekString(arg2.basePtr);
                context.SetValue(context, arg2.basePtr, str1 + str2);
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 26
0
        internal static void StringStartsWith(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str  = context.PeekString(topArg.basePtr);
                string str2 = context.PeekString(secondArg.basePtr);
                context.SetValue(context, secondArg.basePtr, str.StartsWith(str2, StringComparison.Ordinal));
                topArg.basePtr++;
                secondArg.basePtr++;
            }
            context.PopFrame();
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     int basePtr = topArg.basePtr;
     for (int i = secondArg.basePtr; basePtr <= topArg.endPtr; i++)
     {
         NodeSequence otherSeq = context.Values[basePtr].Sequence;
         NodeSequence sequence = context.Values[i].Sequence;
         context.SetValue(context, i, sequence.Union(context, otherSeq));
         basePtr++;
     }
     context.PopFrame();
     return base.next;
 }
Exemplo n.º 28
0
        internal static void SubstringBefore(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str   = context.PeekString(topArg.basePtr);
                string str2  = context.PeekString(secondArg.basePtr);
                int    index = str.IndexOf(str2, StringComparison.Ordinal);
                context.SetValue(context, secondArg.basePtr, (index == -1) ? string.Empty : str.Substring(0, index));
                topArg.basePtr++;
                secondArg.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 29
0
        internal static void StringStartsWith(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string leftString  = context.PeekString(arg1.basePtr);
                string rightString = context.PeekString(arg2.basePtr);
                context.SetValue(context, arg2.basePtr, leftString.StartsWith(rightString, StringComparison.Ordinal));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 30
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;
            int        basePtr   = topArg.basePtr;

            for (int i = secondArg.basePtr; basePtr <= topArg.endPtr; i++)
            {
                NodeSequence otherSeq = context.Values[basePtr].Sequence;
                NodeSequence sequence = context.Values[i].Sequence;
                context.SetValue(context, i, sequence.Union(context, otherSeq));
                basePtr++;
            }
            context.PopFrame();
            return(base.next);
        }
Exemplo n.º 31
0
        internal static void SubstringAfter(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str1 = context.PeekString(arg1.basePtr);
                string str2 = context.PeekString(arg2.basePtr);
                int    idx  = str1.IndexOf(str2, StringComparison.Ordinal);
                context.SetValue(context, arg2.basePtr, idx == -1 ? string.Empty : str1.Substring(idx + str2.Length));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 32
0
        internal static void NumberSum(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(arg.basePtr);
                double       sum      = 0.0;
                for (int item = 0; item < sequence.Count; ++item)
                {
                    sum += QueryValueModel.Double(sequence[item].StringValue());
                }

                context.SetValue(context, arg.basePtr, sum);
                arg.basePtr++;
            }
        }
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     StackFrame topArg = context.TopArg;
     Message contextMessage = context.Processor.ContextMessage;
     CorrelationDataMessageProperty property = null;
     CorrelationDataMessageProperty.TryGet(contextMessage, out property);
     while (topArg.basePtr <= topArg.endPtr)
     {
         string str;
         if ((property == null) || !property.TryGetValue(context.PeekString(topArg.basePtr), out str))
         {
             str = string.Empty;
         }
         context.SetValue(context, topArg.basePtr, str);
         topArg.basePtr++;
     }
 }
Exemplo n.º 34
0
        internal static void NumberSum(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(topArg.basePtr);
                double       val      = 0.0;
                for (int i = 0; i < sequence.Count; i++)
                {
                    NodeSequenceItem item = sequence[i];
                    val += QueryValueModel.Double(item.StringValue());
                }
                context.SetValue(context, topArg.basePtr, val);
                topArg.basePtr++;
            }
        }
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            StackFrame topArg         = context.TopArg;
            Message    contextMessage = context.Processor.ContextMessage;
            CorrelationDataMessageProperty property = null;

            CorrelationDataMessageProperty.TryGet(contextMessage, out property);
            while (topArg.basePtr <= topArg.endPtr)
            {
                string str;
                if ((property == null) || !property.TryGetValue(context.PeekString(topArg.basePtr), out str))
                {
                    str = string.Empty;
                }
                context.SetValue(context, topArg.basePtr, str);
                topArg.basePtr++;
            }
        }
Exemplo n.º 36
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            Fx.Assert(topArg.Count == secondArg.Count, "");
            for (int x = topArg.basePtr, y = secondArg.basePtr; x <= topArg.endPtr; ++x, ++y)
            {
                NodeSequence seqX = context.Values[x].Sequence;
                NodeSequence seqY = context.Values[y].Sequence;

                // Replace with a new sequence that is the union of the two
                context.SetValue(context, y, seqY.Union(context, seqX));
            }

            context.PopFrame();
            return(this.next);
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     Value[] values = context.Values;
     StackFrame topArg = context.TopArg;
     for (int i = topArg.basePtr; i <= topArg.endPtr; i++)
     {
         NodeSequence sequence = values[i].Sequence;
         NodeSequence val = context.CreateSequence();
         for (int j = 0; j < sequence.Count; j++)
         {
             NodeSequenceItem item = sequence[j];
             val.AddCopy(ref item);
         }
         val.Merge();
         context.SetValue(context, i, val);
     }
     return base.next;
 }
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     StackFrame topArg = context.TopArg;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string val = string.Empty;
         NodeSequence sequence = context.PeekSequence(topArg.basePtr);
         if (sequence.Count > 0)
         {
             NodeSequenceItem item = sequence[0];
             SeekableXPathNavigator node = item.Node.Node;
             long currentPosition = node.CurrentPosition;
             NodeSequenceItem item2 = sequence[0];
             node.CurrentPosition = item2.Node.Position;
             val = ExtractFromNavigator(node);
             node.CurrentPosition = currentPosition;
         }
         context.SetValue(context, topArg.basePtr, val);
         topArg.basePtr++;
     }
 }
Exemplo n.º 39
0
        internal static void NumberRound(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                double val = context.PeekDouble(arg.basePtr);
                context.SetValue(context, arg.basePtr, QueryValueModel.Round(context.PeekDouble(arg.basePtr)));
                arg.basePtr++;
            }
        }
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            StackFrame seqArg = context.TopArg;

            while (seqArg.basePtr <= seqArg.endPtr)
            {
                string actor = string.Empty;
                NodeSequence seq = context.PeekSequence(seqArg.basePtr);

                if (seq.Count > 0)
                {
                    SeekableXPathNavigator nav = seq[0].Node.Node;
                    long p = nav.CurrentPosition;
                    nav.CurrentPosition = seq[0].Node.Position;
                    actor = ExtractFromNavigator(nav);
                    nav.CurrentPosition = p;
                }

                context.SetValue(context, seqArg.basePtr, actor);

                seqArg.basePtr++;
            }
        }
Exemplo n.º 41
0
 internal static void StringConcatFour(ProcessingContext context)
 {
     StackFrame arg1 = context[0];
     StackFrame arg2 = context[1];
     StackFrame arg3 = context[2];
     StackFrame arg4 = context[3];
     while (arg1.basePtr <= arg1.endPtr)
     {
         string str1 = context.PeekString(arg1.basePtr);
         string str2 = context.PeekString(arg2.basePtr);
         string str3 = context.PeekString(arg3.basePtr);
         string str4 = context.PeekString(arg4.basePtr);
         context.SetValue(context, arg4.basePtr, str1 + str2 + str3 + str4);
         arg1.basePtr++;
         arg2.basePtr++;
         arg3.basePtr++;
         arg4.basePtr++;
     }
     context.PopFrame();
     context.PopFrame();
     context.PopFrame();
 }
Exemplo n.º 42
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            Fx.Assert(topArg.Count == secondArg.Count, "");
            for (int x = topArg.basePtr, y = secondArg.basePtr; x <= topArg.endPtr; ++x, ++y)
            {
                NodeSequence seqX = context.Values[x].Sequence;
                NodeSequence seqY = context.Values[y].Sequence;

                // Replace with a new sequence that is the union of the two
                context.SetValue(context, y, seqY.Union(context, seqX));
            }

            context.PopFrame();
            return this.next;
        }
Exemplo n.º 43
0
        internal static void Translate(ProcessingContext context)
        {
            StackFrame argSource = context.TopArg;
            StackFrame argKeys = context.SecondArg;
            StackFrame argValues = context[2];

            // PERF, [....], this is really slow.
            StringBuilder builder = new StringBuilder();
            while (argSource.basePtr <= argSource.endPtr)
            {
                builder.Length = 0;

                string source = context.PeekString(argSource.basePtr);
                string keys = context.PeekString(argKeys.basePtr);
                string values = context.PeekString(argValues.basePtr);
                for (int i = 0; i < source.Length; ++i)
                {
                    char c = source[i];
                    int idx = keys.IndexOf(c);
                    if (idx < 0)
                    {
                        builder.Append(c);
                    }
                    else if (idx < values.Length)
                    {
                        builder.Append(values[idx]);
                    }
                }
                context.SetValue(context, argValues.basePtr, builder.ToString());
                argSource.basePtr++;
                argKeys.basePtr++;
                argValues.basePtr++;
            }

            context.PopFrame();
            context.PopFrame();
        }
Exemplo n.º 44
0
        internal static void NormalizeSpace(ProcessingContext context)
        {
            StackFrame argStr = context.TopArg;

            StringBuilder builder = new StringBuilder();
            while (argStr.basePtr <= argStr.endPtr)
            {
                char[] whitespace = new char[] { ' ', '\t', '\r', '\n' };
                string str = context.PeekString(argStr.basePtr).Trim(whitespace);

                bool eatingWhitespace = false;
                builder.Length = 0;
                for (int i = 0; i < str.Length; ++i)
                {
                    char c = str[i];
                    if (XPathCharTypes.IsWhitespace(c))
                    {
                        if (!eatingWhitespace)
                        {
                            builder.Append(' ');
                            eatingWhitespace = true;
                        }
                    }
                    else
                    {
                        builder.Append(c);
                        eatingWhitespace = false;
                    }
                }

                context.SetValue(context, argStr.basePtr, builder.ToString());
                argStr.basePtr++;
            }
        }
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            StackFrame nameArg = context.TopArg;
            Message message = context.Processor.ContextMessage;
            CorrelationDataMessageProperty data = null;

            CorrelationDataMessageProperty.TryGet(message, out data);

            while (nameArg.basePtr <= nameArg.endPtr)
            {
                string value;

                if (data == null || !data.TryGetValue(context.PeekString(nameArg.basePtr), out value))
                {
                    value = string.Empty;
                }

                context.SetValue(context, nameArg.basePtr, value);
                nameArg.basePtr++;
            }
        }
Exemplo n.º 46
0
        internal static void NumberFloor(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                context.SetValue(context, arg.basePtr, Math.Floor(context.PeekDouble(arg.basePtr)));
                arg.basePtr++;
            }
        }
Exemplo n.º 47
0
        internal static void NodesetNamespaceUri(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(arg.basePtr);
                context.SetValue(context, arg.basePtr, sequence.Namespace);
                arg.basePtr++;
            }
        }
Exemplo n.º 48
0
 internal static void NodesetCount(ProcessingContext context)
 {
     StackFrame arg = context.TopArg;
     while (arg.basePtr <= arg.endPtr)
     {
         context.SetValue(context, arg.basePtr, context.PeekSequence(arg.basePtr).Count);
         arg.basePtr++;
     }
 }
Exemplo n.º 49
0
        internal static void BooleanLang(ProcessingContext context)
        {
            StackFrame langArg = context.TopArg;
            StackFrame sequences = context.TopSequenceArg;
            Value[] sequenceBuffer = context.Sequences;

            while (sequences.basePtr <= sequences.endPtr)
            {
                NodeSequence sourceSeq = sequenceBuffer[sequences.basePtr++].Sequence;

                for (int item = 0; item < sourceSeq.Count; ++item)
                {
                    string lang = context.PeekString(langArg.basePtr).ToUpperInvariant();

                    QueryNode node = sourceSeq.Items[item].Node;
                    long pos = node.Node.CurrentPosition;
                    node.Node.CurrentPosition = node.Position;
                    string docLang = node.Node.XmlLang.ToUpperInvariant();
                    node.Node.CurrentPosition = pos;

                    if (lang.Length == docLang.Length && string.CompareOrdinal(lang, docLang) == 0)
                    {
                        context.SetValue(context, langArg.basePtr++, true);
                    }
                    else if (docLang.Length > 0 && lang.Length < docLang.Length && docLang.StartsWith(lang, StringComparison.Ordinal) && docLang[lang.Length] == '-')
                    {
                        context.SetValue(context, langArg.basePtr++, true);
                    }
                    else
                    {
                        context.SetValue(context, langArg.basePtr++, false);
                    }
                }

                sequences.basePtr++;
            }
        }
Exemplo n.º 50
0
        internal override void Eval(ProcessingContext context)
        {
            Fx.Assert(context != null, "");

            StackFrame[] args = new StackFrame[argCount];
            for (int i = 0; i < this.argCount; ++i)
            {
                args[i] = context[i];
            }

            StringBuilder builder = new StringBuilder();
            while (args[0].basePtr <= args[0].endPtr)
            {
                builder.Length = 0;

                for (int i = 0; i < this.argCount; ++i)
                {
                    builder.Append(context.PeekString(args[i].basePtr));
                }

                context.SetValue(context, args[this.argCount - 1].basePtr, builder.ToString());
                for (int i = 0; i < this.argCount; ++i)
                {
                    args[i].basePtr++;
                }
            }

            for (int i = 0; i < this.argCount - 1; ++i)
            {
                context.PopFrame();
            }
        }
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     StackFrame spanArg = context.TopArg;
     while (spanArg.basePtr <= spanArg.endPtr)
     {
         string spanStr = context.PeekString(spanArg.basePtr);
         context.SetValue(context, spanArg.basePtr, Convert(spanStr));
         spanArg.basePtr++;
     }
 }
Exemplo n.º 52
0
        internal override Opcode Eval(ProcessingContext context)
        {
            XPathNavigator nav = context.Processor.ContextNode;
            if (nav != null && context.Processor.ContextMessage != null)
            {
                ((SeekableMessageNavigator)nav).Atomize();
            }

            if (this.argCount == 0)
            {
                context.PushFrame();
                int count = context.IterationCount;
                if (count > 0)
                {
                    object ret = this.function.Invoke(this.xsltContext, NullArgs, nav);
                    switch (this.function.ReturnType)
                    {
                        case XPathResultType.String:
                            context.Push((string)ret, count);
                            break;

                        case XPathResultType.Number:
                            context.Push((double)ret, count);
                            break;

                        case XPathResultType.Boolean:
                            context.Push((bool)ret, count);
                            break;

                        case XPathResultType.NodeSet:
                            NodeSequence seq = context.CreateSequence();
                            XPathNodeIterator iter = (XPathNodeIterator)ret;
                            seq.Add(iter);
                            context.Push(seq, count);
                            break;

                        default:
                            // This should never be reached
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
                    }
                }
            }
            else
            {
                // PERF, [....], see if we can cache these arrays to avoid allocations
                object[] xsltArgs = new object[this.argCount];
                int iterationCount = context.TopArg.Count;
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    for (int i = 0; i < this.argCount; ++i)
                    {
                        StackFrame arg = context[i];
                        Fx.Assert(iteration < arg.Count, "");

                        switch (this.function.ArgTypes[i])
                        {
                            case XPathResultType.String:
                                xsltArgs[i] = context.PeekString(arg[iteration]);
                                break;

                            case XPathResultType.Number:
                                xsltArgs[i] = context.PeekDouble(arg[iteration]);
                                break;

                            case XPathResultType.Boolean:
                                xsltArgs[i] = context.PeekBoolean(arg[iteration]);
                                break;

                            case XPathResultType.NodeSet:
                                NodeSequenceIterator iter = new NodeSequenceIterator(context.PeekSequence(arg[iteration]));
                                xsltArgs[i] = iter;
                                this.iterList.Add(iter);
                                break;

                            default:
                                // This should never be reached
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ArgTypes[i].ToString())));
                        }
                    }

                    object ret = this.function.Invoke(this.xsltContext, xsltArgs, nav);

                    if (this.iterList != null)
                    {
                        for (int i = 0; i < this.iterList.Count; ++i)
                        {
                            this.iterList[i].Clear();
                        }
                        this.iterList.Clear();
                    }

                    switch (this.function.ReturnType)
                    {
                        case XPathResultType.String:
                            context.SetValue(context, context[this.argCount - 1][iteration], (string)ret);
                            break;

                        case XPathResultType.Number:
                            context.SetValue(context, context[this.argCount - 1][iteration], (double)ret);
                            break;

                        case XPathResultType.Boolean:
                            context.SetValue(context, context[this.argCount - 1][iteration], (bool)ret);
                            break;

                        case XPathResultType.NodeSet:
                            NodeSequence seq = context.CreateSequence();
                            XPathNodeIterator iter = (XPathNodeIterator)ret;
                            seq.Add(iter);
                            context.SetValue(context, context[this.argCount - 1][iteration], seq);
                            break;

                        default:
                            // This should never be reached
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
                    }
                }

                for (int i = 0; i < this.argCount - 1; ++i)
                {
                    context.PopFrame();
                }
            }
            return this.next;
        }
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            StackFrame actorArg = context.TopArg;

            SeekableXPathNavigator nav = context.Processor.ContextNode;
            long p = nav.CurrentPosition;
            while (actorArg.basePtr <= actorArg.endPtr)
            {
                string actor = context.PeekString(actorArg.basePtr);
                NodeSequence seq = context.CreateSequence();

                if (MoveToHeader(nav) && nav.MoveToFirstChild())
                {
                    do
                    {
                        // PERF, [....], this will be faster if I cache the envelope namespace to do the
                        //               actor lookup by hand
                        long pos = nav.CurrentPosition;
                        string navActor = XPathMessageFunctionActor.ExtractFromNavigator(nav);
                        nav.CurrentPosition = pos;

                        if (navActor == actor)
                        {
                            seq.Add(nav);
                        }
                    } while (nav.MoveToNext());
                }

                context.SetValue(context, actorArg.basePtr, seq);

                actorArg.basePtr++;
            }
            nav.CurrentPosition = p;
        }
Exemplo n.º 54
0
        internal static void NumberSum(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;
            while (arg.basePtr <= arg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(arg.basePtr);
                double sum = 0.0;
                for (int item = 0; item < sequence.Count; ++item)
                {
                    sum += QueryValueModel.Double(sequence[item].StringValue());
                }

                context.SetValue(context, arg.basePtr, sum);
                arg.basePtr++;
            }
        }
Exemplo n.º 55
0
        internal static void Substring(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str = context.PeekString(arg1.basePtr);
                int startAt = ((int)Math.Round(context.PeekDouble(arg2.basePtr))) - 1;
                if (startAt < 0)
                {
                    startAt = 0;
                }
                context.SetValue(context, arg2.basePtr, (startAt >= str.Length) ? string.Empty : str.Substring(startAt));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 56
0
        internal static void SubstringLimit(ProcessingContext context)
        {
            StackFrame argString = context.TopArg;
            StackFrame argStartAt = context.SecondArg;
            StackFrame argLimit = context[2];

            Fx.Assert(argString.Count == argStartAt.Count, "");
            Fx.Assert(argString.Count == argLimit.Count, "");

            while (argString.basePtr <= argString.endPtr)
            {
                string str = context.PeekString(argString.basePtr);
                int startAt = ((int)Math.Round(context.PeekDouble(argStartAt.basePtr))) - 1;
                if (startAt < 0)
                {
                    startAt = 0;
                }
                int length = (int)Math.Round(context.PeekDouble(argLimit.basePtr));

                string substr;
                if (length < 1 || ((startAt + length) >= str.Length))
                {
                    substr = string.Empty;
                }
                else
                {
                    substr = str.Substring(startAt, length);
                }
                context.SetValue(context, argLimit.basePtr, substr);
                argStartAt.basePtr++;
                argString.basePtr++;
                argLimit.basePtr++;
            }

            context.PopFrame();
            context.PopFrame();
        }
Exemplo n.º 57
0
 internal static void StringLength(ProcessingContext context)
 {
     StackFrame arg = context.TopArg;
     while (arg.basePtr <= arg.endPtr)
     {
         context.SetValue(context, arg.basePtr, context.PeekString(arg.basePtr).Length);
         arg.basePtr++;
     }
 }
Exemplo n.º 58
0
        internal static void SubstringAfter(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str1 = context.PeekString(arg1.basePtr);
                string str2 = context.PeekString(arg2.basePtr);
                int idx = str1.IndexOf(str2, StringComparison.Ordinal);
                context.SetValue(context, arg2.basePtr, idx == -1 ? string.Empty : str1.Substring(idx + str2.Length));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Exemplo n.º 59
0
        internal override Opcode Eval(ProcessingContext context)
        {
            Value[] values = context.Values;
            StackFrame arg = context.TopArg;

            for (int i = arg.basePtr; i <= arg.endPtr; ++i)
            {
                Fx.Assert(ValueDataType.Sequence == values[i].Type, "");
                NodeSequence seq = values[i].Sequence;

                NodeSequence newSeq = context.CreateSequence();
                for (int j = 0; j < seq.Count; ++j)
                {
                    NodeSequenceItem item = seq[j];
                    newSeq.AddCopy(ref item);
                }
                newSeq.Merge();

                context.SetValue(context, i, newSeq);
            }

            return this.next;
        }
Exemplo n.º 60
0
        internal static void StringStartsWith(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string leftString = context.PeekString(arg1.basePtr);
                string rightString = context.PeekString(arg2.basePtr);
                context.SetValue(context, arg2.basePtr, leftString.StartsWith(rightString, StringComparison.Ordinal));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }