Exemplo n.º 1
0
        private void ParseLine()
        {
            string regex = @"\((?<value>[\[\]\+\!]+)\)";

            List <string> internalLines = RegexScraper.ScrapeFromString <string>(Line, regex);

            foreach (string iLine in internalLines)
            {
                CFLine challenge = new CFLine(iLine);

                InternalLines.Add(challenge);
            }

            //Patch to fix lines without ( or ).
            if (internalLines.Count == 0)
            {
                string[] parts = Line.Split(':');

                if (parts.Length == 2)
                {
                    InternalLines.Add(new CFLine(parts[1]));
                }
                else
                {
                    parts = Line.Split('=');

                    if (parts.Length == 2)
                    {
                        InternalLines.Add(new CFLine(parts[1]));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CalculateValue()
        {
            if (InternalLines.Count > 0)
            {
                CFLine previousChallenge = null;

                foreach (CFLine challenge in InternalLines)
                {
                    if (challenge.Type == CFDateType.String || (previousChallenge != null && previousChallenge.Type == CFDateType.String))
                    {
                        string val = Value.ToString() + challenge.Value.ToString();

                        Value = Int32.Parse(val);
                    }
                    else if (challenge.Type == CFDateType.Int)
                    {
                        Value += challenge.Value;
                    }

                    previousChallenge = challenge;
                }
            }

            StringBuilder sBuilder = new StringBuilder();

            foreach (char c in Line)
            {
                sBuilder.Append(c);

                Methods method;

                if (Keys.TryGetValue(sBuilder.ToString(), out method))
                {
                    switch (method)
                    {
                    case Methods.One:
                        Value = 1;
                        break;

                    case Methods.PlusOne:
                        Value++;
                        break;

                    case Methods.ToString:
                        Type = CFDateType.String;
                        break;
                    }

                    sBuilder.Clear();
                }
            }
        }