コード例 #1
0
        public static ParameterCollection Parse(ITextParser reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            var parameters = new ParameterCollection();
            while (!reader.EndOfFile)
            {
                string name = Uri.UnescapeDataString(reader.ReadToEnd("&="));
                char current = reader.Current;
                reader.Consume();
                switch (current)
                {
                    case '&':
                        parameters.Add(name, string.Empty);
                        break;
                    case '=':
                        {
                            string value = reader.ReadToEnd("&");
                            reader.Consume();
                            parameters.Add(name, Uri.UnescapeDataString(value));
                        }
                        break;
                    default:
                        parameters.Add(name, string.Empty);
                        break;
                }
            }

            return parameters;
        }
コード例 #2
0
ファイル: CookieParser.cs プロジェクト: jmptrader/griffin
        /// <summary>
        /// Parse a header
        /// </summary>
        /// <param name="name">Name of header.</param>
        /// <param name="reader">Reader containing value.</param>
        /// <returns>HTTP Header</returns>
        /// <exception cref="FormatException">Header value is not of the expected format.</exception>
        public IHeader Parse(string name, ITextParser reader)
        {
            //key: "value"; key: "value"

            var cookies = new HttpCookieCollection();
            while (!reader.EndOfFile)
            {
                // read name
                string cookieName = reader.ReadToEnd("=;");

                // cookie with value?
                if (reader.Current == '=')
                {
                    reader.Consume();
                    reader.ConsumeWhiteSpaces();

                    // is value quoted or not?
                    string value = reader.Current == '"' ? reader.ReadQuotedString() : reader.ReadToEnd(";");
                    cookies.Add(new HttpCookie(cookieName, value));
                }
                //else
                //    cookies.Add(new RequestCookie(cookieName, string.Empty));

                // consume whitespaces and cookie separator
                reader.ConsumeWhiteSpaces(';');
            }

            return new CookieHeader(cookies);
        }
コード例 #3
0
 public IHeader Parse(string name, ITextParser reader)
 {
     var header = new AuthorizationHeader();
     reader.ConsumeWhiteSpaces();
     header.Scheme = reader.ReadWord();
     reader.ConsumeWhiteSpaces();
     header.Data = reader.ReadToEnd();
     return header;
 }
コード例 #4
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Loads the updated set of biomass parameters from the text file
 /// associated with this update.
 /// </summary>
 /// <param name="parameterParser">
 /// A parser to parse the text file's contents.
 /// </param>
 public void LoadParameters(ITextParser<IParameters> parameterParser)
 {
     try
     {
         parameters = PlugIn.ModelCore.Load<IParameters>(file, parameterParser);
     }
     catch (FileNotFoundException)
     {
         string mesg = string.Format("Error: The file {0} does not exist", file);
         throw new System.ApplicationException(mesg);
     }
 }
コード例 #5
0
ファイル: DateParser.cs プロジェクト: jmptrader/griffin
        /// <summary>
        /// Parse a header
        /// </summary>
        /// <param name="name">Name of header.</param>
        /// <param name="reader">Reader containing value.</param>
        /// <returns>HTTP Header</returns>
        /// <exception cref="FormatException">Header value is not of the expected format.</exception>
        public IHeader Parse(string name, ITextParser reader)
        {
            string value = reader.ReadToEnd();

            try
            {
                return new DateHeader(name,
                                      DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal));
            }
            catch (FormatException err)
            {
                throw new BadRequestException("'" + name + "' do not contain a valid date", err);
            }
        }
コード例 #6
0
ファイル: ConnectionParser.cs プロジェクト: jmptrader/griffin
        /// <summary>
        /// Parse a header
        /// </summary>
        /// <param name="name">Name of header.</param>
        /// <param name="reader">Reader containing value.</param>
        /// <returns>HTTP Header</returns>
        /// <exception cref="FormatException">Header value is not of the expected format.</exception>
        public IHeader Parse(string name, ITextParser reader)
        {
            string typeStr = reader.ReadToEnd(';');
            ConnectionType type;

            try
            {
                type = (ConnectionType) Enum.Parse(typeof (ConnectionType), typeStr.Replace("-", string.Empty), true);
            }
            catch (ArgumentException err)
            {
                throw new FormatException("Unknown connection type '" + typeStr + "'.", err);
            }

            // got parameters
            if (reader.Current == ';')
            {
                HeaderParameterCollection parameters = HeaderParameterCollection.Parse(reader);
                return new ConnectionHeader(type, parameters);
            }

            return new ConnectionHeader(type);
        }
コード例 #7
0
 public WordFrequencyAnalyzer(ITextParser textParser)
 {
     _textParser = textParser;
 }
コード例 #8
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Loads the updated set of biomass parameters from the text file
 ///   associated with this update.
 /// </summary>
 /// <param name="parameterParser">
 /// A parser to parse the text file's contents.
 /// </param>
 public void LoadParameters(ITextParser<IInputParameters> parameterParser)
 {
     parameters = Landis.Data.Load<IInputParameters>(file, parameterParser);
 }
コード例 #9
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Loads the updated set of biomass parameters from the text file
 /// associated with this update.
 /// </summary>
 /// <param name="parameterParser">
 /// A parser to parse the text file's contents.
 /// </param>
 public void LoadParameters(ITextParser<IParameters> parameterParser)
 {
     parameters = PlugIn.ModelCore.Load<IParameters>(file, parameterParser);
 }
コード例 #10
0
ファイル: StringParser.cs プロジェクト: jmptrader/griffin
 /// <summary>
 /// Parse a header
 /// </summary>
 /// <param name="name">Name of header.</param>
 /// <param name="reader">Reader containing value.</param>
 /// <returns>HTTP Header</returns>
 /// <exception cref="FormatException">Header value is not of the expected format.</exception>
 public IHeader Parse(string name, ITextParser reader)
 {
     return null;
 }
コード例 #11
0
 public CharArrayTextParser(ITextParser parser, char[] chars)
 {
     _parser = parser;
     _chars  = chars;
 }
コード例 #12
0
            /// <summary>
            /// Parses attributes from the tag using the given
            /// <see cref="ITextParser"/> <paramref name="tp"/>. The
            /// <see cref="ITextParser"/> position should be set to
            /// the first character of the tag following the element name.
            /// </summary>
            private bool ParseAttributes(ITextParser tp)
            {
                const char   kDoubleQuote       = '"';
                const char   kSingleQuote       = '\'';
                const string kDoubleQuoteEntity = "&#22;";

                if (tp.Peek() == '>')
                {
                    tp.MoveAhead();
                    return(true);
                }

                var sb = new StringBuilder();

                // Copy current input character
                void Copy()
                {
                    sb.Append(tp.Peek());
                    tp.MoveAhead();
                }

                // Copy input characters until fence character or end of tag
                void CopyTo(char fence)
                {
                    while (!tp.EndOfText)
                    {
                        var c = tp.Peek();
                        if (c == fence || c == '>')
                        {
                            break;
                        }
                        if (c != kDoubleQuote)
                        {
                            sb.Append(c);
                        }
                        else
                        {
                            sb.Append(kDoubleQuoteEntity);
                        }
                        tp.MoveAhead();
                    }
                }

                // Copy attributes
                var startPos = tp.Position;

                while (!tp.EndOfText)
                {
                    var c = tp.Peek();
                    if (c == '>' || c == '<')
                    {
                        break;
                    }
                    switch (c)
                    {
                    case '=':
                        Copy();
                        c = tp.Peek();
                        if (c == kDoubleQuote)
                        {
                            // Copy double-quoted value
                            Copy();
                            CopyTo(kDoubleQuote);
                            sb.Append(kDoubleQuote);
                            tp.MoveAhead();
                        }
                        else if (c == kSingleQuote)
                        {
                            // Copy single-quoted value, but with double-quotes
                            sb.Append(kDoubleQuote);
                            tp.MoveAhead();
                            CopyTo(kSingleQuote);
                            sb.Append(kDoubleQuote);
                            tp.MoveAhead();
                        }
                        else
                        {
                            // Copy unqouted value adding double-quotes
                            sb.Append(kDoubleQuote);
                            CopyTo(' ');
                            sb.Append(kDoubleQuote);
                        }
                        break;

                    default:
                        Copy();
                        break;
                    }
                }

                if (tp.Peek() != '>')
                {
                    return(false);
                }

                if (tp.CharAt(tp.Position - 1) == '/')
                {
                    IsSelfClosingTag = true;
                    sb.Length        = sb.Length - 1;
                }

                AttributesPart = sb.ToString();
                if (AttributesPart.IndexOf('&') != -1)
                {
                    AttributesPart = ResolveEntities(AttributesPart);
                }

                tp.MoveAhead();

                return(true);
            }
コード例 #13
0
 public void Init()
 {
     _textParser = new TextParser();
     _frequencyAnalyzer = new WordFrequencyAnalyzer(_textParser);
 }
コード例 #14
0
        public static void Start(ITaskFirst taskFirst, ITextParser textParser)
        {
            do
            {
                Console.Clear();
                Console.WriteLine(menu);
                switch (Console.ReadLine())
                {
                case "1":
                    taskFirst.SentencesInAscendingOrder.ToList().ForEach(sent => Console.Write(sent));
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    break;

                case "2":
                    Console.WriteLine("Input the length of the word");
                    if (int.TryParse(Console.ReadLine(), out int length))
                    {
                        if (length <= 0)
                        {
                            Console.WriteLine("The length must be bigger than 0");
                        }
                        else
                        {
                            Console.WriteLine("Words:");
                            taskFirst.GetWordsFromIssueSentencesByGivenLength(length).ToList().ForEach(word => Console.WriteLine(word));
                        }
                    }
                    else
                    {
                        Console.WriteLine("Incorrect input");
                    }
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    break;

                case "3":
                    Console.WriteLine("Input the length of the word");
                    if (int.TryParse(Console.ReadLine(), out int lengthWord))
                    {
                        if (lengthWord <= 0)
                        {
                            Console.WriteLine("The length must be bigger than 0");
                        }
                        else
                        {
                            taskFirst.SentencesWithoutWordsStartWithConsonant(lengthWord);
                            Console.WriteLine(taskFirst.Text);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Incorrect input");
                    }
                    Console.ReadKey();
                    break;

                case "4":
                    Console.WriteLine("Input the srtrig to insert");
                    string inserting = Console.ReadLine();
                    Console.WriteLine("Input the index of sentence (start with 0)");
                    if (int.TryParse(Console.ReadLine(), out int indexSentence))
                    {
                        if (indexSentence >= 0 && indexSentence < taskFirst.Text.AmountOfSentences)
                        {
                            Console.WriteLine("Input the length of the word");
                            if (int.TryParse(Console.ReadLine(), out int wordLength))
                            {
                                if (wordLength <= 0)
                                {
                                    Console.WriteLine("The length must be bigger than 0");
                                }
                                else
                                {
                                    taskFirst.ReplaceWordOfGivenLengthInSentenceByElements(indexSentence, wordLength, textParser.ParseText(inserting).ToArray());
                                    Console.WriteLine(taskFirst.Text);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Incorrect input");
                            }
                        }
                        else
                        {
                            Console.WriteLine("There is no sentence with this index in text");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Incorrect input");
                    }
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    break;

                case "5":
                    Console.WriteLine(taskFirst.Text);
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    break;

                default:
                    Console.WriteLine("You have finished work");
                    return;
                }
            } while (true);
        }
コード例 #15
0
 public TextController(ILogger <TextController> logger, ITextParser parser)
 {
     _logger = logger;
     _parser = parser;
 }
コード例 #16
0
 public StringTextParser(ITextParser parser, string match, StringComparison comparisonType = StringComparison.Ordinal)
 {
     _parser         = parser;
     _match          = match;
     _comparisonType = comparisonType;
 }