Beispiel #1
0
        public static void MyClassInitialize(TestContext testContext)
        {
            List <string> regexValues = new List <string>()
            {
                @"\bCR *-*#* *\d{3,10}", @"\bCR *-*#* *\d{3,10}"
            };

            standardRegexValues = regexValues;

            ApplyToGroup[] applyToGroup = new ApplyToGroup[] {
                new ApplyToGroup()
                {
                    GroupName = "MyGroup1"
                },
                new ApplyToGroup()
                {
                    GroupName = "MyGroup2"
                }
            };
            TagRegex[] tagRegex = new TagRegex[] {
                new TagRegex()
                {
                    RegexValue = regexValues[0]
                },
                new TagRegex()
                {
                    RegexValue = regexValues[1]
                }
            };
            inferenceList = new List <ScriptTagInference>();
            inferenceList.Add(new ScriptTagInference()
            {
                TagRegex = tagRegex, ApplyToGroup = applyToGroup
            });
        }
Beispiel #2
0
        private async Task <IDictionary <string, IList <string> > > ExtractTagsAsync(string html)
        {
            var tags = new Dictionary <string, IList <string> >();

            foreach (Match match in TagRowRegex.Matches(html))
            {
                var name = match.Groups["name"].Value;
                var tag  = (await Task.WhenAll(TagRegex.Matches(match.Groups["content"].Value)
                                               .Select(async t => await _tagTranslationInfo.GetTranslationAsync(name, t.Groups["tag"].Value))))
                           .Select(t => t.Item2).ToList();
                tags.Add((await _tagTranslationInfo.GetTranslationAsync(name)).Item2, tag);
            }

            return(tags);
        }
Beispiel #3
0
        /// <summary>
        /// Handles ui messages from the client. For things such as button presses
        /// which interact with the world and require server action.
        /// </summary>
        /// <param name="obj">A user interface message from the client.</param>
        private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
        {
            var msg = (UiActionMessage)obj.Message;

            if (!Anchored)
            {
                return;
            }

            //Check for correct message and ignore maleformed strings
            if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tag))
            {
                _tag = msg.Tag;
                ClickSound();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Constructor for making an HtmlTag chunk with strings
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="fullTagName"></param>
        /// <param name="isSelfClosing"></param>
        public HtmlTag(string tag)
            : base(tag, HtmlChunkType.Tag)
        {
            TagRegex tagReg = new TagRegex();
            Match    m      = tagReg.Match(tag);

            if (m.Success)
            {
                _attributes    = HtmlParserHelper.GetAttributesFromTag(m);
                _isSelfClosing = HtmlParserHelper.IsSelfClosingTag(m);
                setTagInfoInternal(HtmlParserHelper.GetTagName(m));
                _id = _attributes.ContainsKey("id") ? _attributes["id"] : "";
            }
            else
            {
                throw new ArgumentException("A valid tag is required", "tag");
            }
        }
Beispiel #5
0
        /* Function: GetAllTagProperties
         * If <Type> is <XMLElementType.Tag>, this generates a dictionary of all the properties in the tag, if any.
         */
        public Dictionary <string, string> GetAllTagProperties()
        {
            if (type != XMLElementType.Tag)
            {
                throw new InvalidOperationException();
            }

            Dictionary <string, string> properties = new Dictionary <string, string>();

            Match             match    = TagRegex.Match(RawText, RawTextIndex, length);
            CaptureCollection captures = match.Groups[2].Captures;

            foreach (Capture capture in captures)
            {
                Match propertyMatch = TagPropertyRegex.Match(RawText, capture.Index, capture.Length);
                properties.Add(propertyMatch.Groups[1].ToString(),
                               DecodePropertyValue(propertyMatch.Groups[2].Index, propertyMatch.Groups[2].Length));
            }

            return(properties);
        }
Beispiel #6
0
        /* Function: TagProperty
         * If <Type> is <XMLElementType.Tag>, return the value of the passed property, or null if it doesn't exist.  The property
         * name is case-insensitive.
         */
        public string TagProperty(string name)
        {
            if (type != XMLElementType.Tag)
            {
                throw new InvalidOperationException();
            }

            Match             match    = TagRegex.Match(RawText, RawTextIndex, length);
            CaptureCollection captures = match.Groups[2].Captures;

            foreach (Capture capture in captures)
            {
                Match propertyMatch = TagPropertyRegex.Match(RawText, capture.Index, capture.Length);

                if (name.Length == propertyMatch.Groups[1].Length &&
                    string.Compare(name, 0, RawText, propertyMatch.Groups[1].Index, name.Length, true) == 0)
                {
                    return(DecodePropertyValue(propertyMatch.Groups[2].Index, propertyMatch.Groups[2].Length));
                }
            }

            return(null);
        }
        public DisposalRouterWindow()
        {
            RobustXamlLoader.Load(this);

            TagInput.IsValid = tags => TagRegex.IsMatch(tags);
        }
Beispiel #8
0
        // Group: Private Functions
        // __________________________________________________________________________


        /* Function: DetermineElement
         * Determines which <XMLElementType> the iterator is currently on, setting <type> and <length>.
         */
        private void DetermineElement()
        {
            bool found = false;

            if (tokenIterator == null || !IsInBounds)
            {
                type   = XMLElementType.OutOfBounds;
                length = 0;
                found  = true;
            }
            // If we're on a new line and either whitespace or a comment token...
            else if ((RawTextIndex == 0 ||
                      Tokenizer.FundamentalTypeOf(RawText[RawTextIndex - 1]) == FundamentalType.LineBreak)
                     &&
                     (tokenIterator.FundamentalType == FundamentalType.Whitespace ||
                      tokenIterator.CommentParsingType == CommentParsingType.CommentSymbol ||
                      tokenIterator.CommentParsingType == CommentParsingType.CommentDecoration))
            {
                type   = XMLElementType.Indent;
                length = 0;

                TokenIterator lookahead = tokenIterator;

                do
                {
                    length += lookahead.RawTextLength;
                    lookahead.Next();
                }while (lookahead.RawTextIndex < endingRawTextIndex &&
                        (lookahead.FundamentalType == FundamentalType.Whitespace ||
                         lookahead.CommentParsingType == CommentParsingType.CommentSymbol ||
                         lookahead.CommentParsingType == CommentParsingType.CommentDecoration));

                found = true;
            }
            else if (tokenIterator.FundamentalType == FundamentalType.LineBreak)
            {
                type   = XMLElementType.LineBreak;
                length = tokenIterator.RawTextLength;
                found  = true;
            }
            else if (tokenIterator.Character == '<')
            {
                int nextBracketIndex = RawText.IndexOfAny(AngleBrackets, RawTextIndex + 1);

                if (nextBracketIndex != -1 && nextBracketIndex < endingRawTextIndex && RawText[nextBracketIndex] == '>')
                {
                    type   = XMLElementType.Tag;
                    length = nextBracketIndex + 1 - RawTextIndex;

                    Match tagMatch = TagRegex.Match(RawText, RawTextIndex, length);

                    if (tagMatch.Success)
                    {
                        found   = true;
                        tagType = tagMatch.Groups[1].ToString().ToLower();
                    }
                }
            }
            else if (tokenIterator.Character == '&')
            {
                int semicolonIndex = RawText.IndexOf(';', RawTextIndex + 1);

                if (semicolonIndex != -1 && semicolonIndex < endingRawTextIndex &&
                    HTMLEntityChars.IsEntityChar(RawText, RawTextIndex, semicolonIndex + 1 - RawTextIndex))
                {
                    type   = XMLElementType.EntityChar;
                    length = semicolonIndex + 1 - RawTextIndex;
                    found  = true;
                }
            }

            if (!found)
            {
                type = XMLElementType.Text;

                int nextElementIndex = RawText.IndexOfAny(StartOfElement, RawTextIndex + 1);

                if (nextElementIndex == -1)
                {
                    length = endingRawTextIndex - RawTextIndex;
                }
                else
                {
                    length = nextElementIndex - RawTextIndex;
                }
            }
        }
        private List <HtmlChunk> ParseBml(string bml)
        {
            //loop thru bml

            ////find tag
            /////if reg'd tag save position found. Take all above bml and move to a string. Find end tag

            int currentIndex = 0;
            //int lastChunkStartIndex = 0;
            int lastChunkEndIndex = 0;

            List <HtmlChunk> _chunks   = new List <HtmlChunk>();
            Match            lastmatch = null;

            while (currentIndex < bml.Length)
            {
                Match m = null;

                // Find next opening tags
                TagRegex bmlTag = new TagRegex();
                m = bmlTag.Match(bml, currentIndex);

                //Check to see if we have a match
                if (m.Success)
                {
                    string tagName = HtmlParserHelper.GetTagName(m);
                    if (HtmlParserHelper.IsRegisteredPrefix(tagName))
                    {
                        lastmatch = m;
                        if (HtmlParserHelper.IsSelfClosingTag(m))
                        {
                            //Self closing
                            //Add the in between bml as a chunk
                            //Add chunks to list
                            _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, m.Index - lastChunkEndIndex)));
                            //Check to see if its a Region
                            if (HtmlParserHelper.GetTagName(m) == "base:Region")
                            {
                                _chunks.Add(new BmlRegion(m));
                            }
                            else
                            {
                                _chunks.Add(new HtmlTag(m));
                            }

                            //SET last chunk index

                            //increment the index by the length of the tag
                            currentIndex      = m.Index + m.Length;
                            lastChunkEndIndex = currentIndex;
                            continue;
                        }
                        else
                        {
                            //Not self closing, find end tag
                            string outter = HtmlParserHelper.GetOutterText(bml, m);

                            //add the chunks to the list
                            _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, m.Index - lastChunkEndIndex)));
                            //Check to see if its a Region
                            if (HtmlParserHelper.GetTagName(m) == "base:Region")
                            {
                                _chunks.Add(new BmlRegion(m, outter));
                            }
                            else
                            {
                                _chunks.Add(new HtmlTag(m, outter));
                            }

                            //SET last chunk index
                            //increment index the amount of outtertext.
                            currentIndex      = m.Index + outter.Length;
                            lastChunkEndIndex = currentIndex;
                            continue;
                        }
                    }
                }
                currentIndex++;
            }

            //add final chunk
            _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, bml.Length - lastChunkEndIndex)));

            return(_chunks);
        }