当前位置: 首页>>代码示例>>C#>>正文


C# StringParser类代码示例

本文整理汇总了C#中StringParser的典型用法代码示例。如果您正苦于以下问题:C# StringParser类的具体用法?C# StringParser怎么用?C# StringParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringParser类属于命名空间,在下文中一共展示了StringParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HelloStringParsing

        public HelloStringParsing()
        {
            var sp = new StringParser();

            _parser = from x in sp.String("Hello")
                      select x;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:7,代码来源:HelloStringParsing.cs

示例2: CommandLineParser

            public CommandLineParser()
            {
                var p = new StringParser();

                Id = from ws in p.SkipWhitespace()
                     from c in p.Char(char.IsLetter)
                     from cs in p.Char(char.IsLetterOrDigit).ZeroOrMore()
                     select new string(c, 1) + new string(cs);

                Key = from ws in p.SkipWhitespace()
                     from c in p.Char(char.IsLetter)
                     from cs in (p.Char(char.IsLetterOrDigit).Or(p.Char('.'))).ZeroOrMore()
                     select new string(c, 1) + new string(cs);

                //                Value = from v in (p.Char(x => !char.IsWhiteSpace(x))).ZeroOrMore()
                //                        select new string(v);
                Value = from v in (p.Char().Except(p.Whitespace())).ZeroOrMore()
                        select new string(v);

                Definition = (from ws in p.SkipWhitespace()
                              from c in p.Char('-', '/')
                              from id in Id
                              from eq in p.Char(':', '=')
                              from v in Value
                              select new Definition(id, v));
            }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:26,代码来源:CommandLine_Spcs.cs

示例3: Should_choose_the_greediest_one

        public void Should_choose_the_greediest_one()
        {
            string subject = "Hello, World";

            var p = new StringParser();

            Parser<string, string> first = from x in p.String("Hello")
                                           select x;

            Assert.IsTrue(first.ParseString(subject).HasValue, "First did not match");

            Parser<string, string> second = from x in p.String("Hello")
                                            from y in p.Char(',')
                                            from ws in p.Whitespace()
                                            from z in p.String("World")
                                            select x + z;

            Assert.IsTrue(second.ParseString(subject).HasValue, "Second did not match");

            Parser<string, string> parser = p.Longest(first, second);

            Result<string, string> result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue, "Neither matched");

            Assert.AreEqual("HelloWorld", result.Value, "Longest parser should have matched");
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:27,代码来源:Greedy_Specs.cs

示例4: CreateUdpIPv4Statistics

        public static UdpStatistics CreateUdpIPv4Statistics()
        {
            LinuxUdpStatistics stats = new LinuxUdpStatistics();
            string fileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
            int firstUdpHeader = fileContents.IndexOf("Udp:");
            int secondUdpHeader = fileContents.IndexOf("Udp:", firstUdpHeader + 1);
            int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondUdpHeader);
            string tcpData = fileContents.Substring(secondUdpHeader, endOfSecondLine - secondUdpHeader);
            StringParser parser = new StringParser(tcpData, ' ');

            // NOTE: Need to verify that this order is consistent. Otherwise, we need to parse the first-line header
            // to determine the order of information contained in the file.

            parser.MoveNextOrFail(); // Skip Udp:

            stats._inDatagrams = parser.ParseNextInt32();
            stats._noPorts = parser.ParseNextInt32();
            stats._inErrors = parser.ParseNextInt32();
            stats._outDatagrams = parser.ParseNextInt32();
            stats._rcvbufErrors = parser.ParseNextInt32();
            stats._sndbufErrors = parser.ParseNextInt32();
            stats._inCsumErrors = parser.ParseNextInt32();

            // Parse the number of active connections out of /proc/net/sockstat
            string sockstatFile = File.ReadAllText(NetworkFiles.SockstatFile);
            int indexOfUdp = sockstatFile.IndexOf("UDP:");
            int endOfUdpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfUdp + 1);
            string udpLineData = sockstatFile.Substring(indexOfUdp, endOfUdpLine - indexOfUdp);
            StringParser sockstatParser = new StringParser(udpLineData, ' ');
            sockstatParser.MoveNextOrFail(); // Skip "UDP:"
            sockstatParser.MoveNextOrFail(); // Skip: "inuse"
            stats._udpListeners = sockstatParser.ParseNextInt32();

            return stats;
        }
开发者ID:JonHanna,项目名称:corefx,代码行数:35,代码来源:LinuxUdpStatistics.cs

示例5: CreateUdpIPv6Statistics

        public static UdpStatistics CreateUdpIPv6Statistics()
        {
            LinuxUdpStatistics stats = new LinuxUdpStatistics();

            string fileContents = File.ReadAllText(NetworkFiles.SnmpV6StatsFile);

            RowConfigReader reader = new RowConfigReader(fileContents);

            stats._inDatagrams = reader.GetNextValueAsInt32("Udp6InDatagrams");
            stats._noPorts = reader.GetNextValueAsInt32("Udp6NoPorts");
            stats._inErrors = reader.GetNextValueAsInt32("Udp6InErrors");
            stats._outDatagrams = reader.GetNextValueAsInt32("Udp6OutDatagrams");
            stats._rcvbufErrors = reader.GetNextValueAsInt32("Udp6RcvbufErrors");
            stats._sndbufErrors = reader.GetNextValueAsInt32("Udp6SndbufErrors");
            stats._inCsumErrors = reader.GetNextValueAsInt32("Udp6InCsumErrors");

            // Parse the number of active connections out of /proc/net/sockstat6
            string sockstatFile = File.ReadAllText(NetworkFiles.Sockstat6File);
            int indexOfUdp = sockstatFile.IndexOf("UDP6:");
            int endOfUdpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfUdp + 1);
            string udpLineData = sockstatFile.Substring(indexOfUdp, endOfUdpLine - indexOfUdp);
            StringParser sockstatParser = new StringParser(udpLineData, ' ');
            sockstatParser.MoveNextOrFail(); // Skip "UDP6:"
            sockstatParser.MoveNextOrFail(); // Skip: "inuse"
            stats._udpListeners = sockstatParser.ParseNextInt32();

            return stats;
        }
开发者ID:JonHanna,项目名称:corefx,代码行数:28,代码来源:LinuxUdpStatistics.cs

示例6: Read

 internal static StringLiteralToken Read(ILexerStream stream)
 {
     var extent = new SourceExtent(stream);
     var sourceChars = new List<char>();
     // read the first character
     sourceChars.Add(stream.ReadChar('"'));
     // read the remaining characters
     var parser = new StringParser();
     while (!stream.Eof)
     {
         var peek = stream.Peek();
         sourceChars.Add(peek);
         if ((peek == '"') && !parser.IsEscaped)
         {
             parser.ConsumeEof();
             break;
         }
         else
         {
             parser.ConsumeChar(stream.Read());
         }
     }
     // read the last character
     sourceChars.Add(stream.ReadChar('"'));
     // process any escape sequences in the string
     var unescaped = parser.OutputString.ToString();
     // return the result
     extent = extent.WithText(sourceChars);
     return new StringLiteralToken(extent, unescaped);
 }
开发者ID:sergey-raevskiy,项目名称:MofParser,代码行数:30,代码来源:StringLiteralToken.cs

示例7: ParseGatewayAddressesFromRouteFile

        // /proc/net/route contains some information about gateway addresses,
        // and separates the information about by each interface.
        internal static List<GatewayIPAddressInformation> ParseGatewayAddressesFromRouteFile(string filePath, string interfaceName)
        {
            if (!File.Exists(filePath))
            {
                throw ExceptionHelper.CreateForInformationUnavailable();
            }

            List<GatewayIPAddressInformation> collection = new List<GatewayIPAddressInformation>();
            // Columns are as follows (first-line header):
            // Iface  Destination  Gateway  Flags  RefCnt  Use  Metric  Mask  MTU  Window  IRTT
            string[] fileLines = File.ReadAllLines(filePath);
            foreach (string line in fileLines)
            {
                if (line.StartsWith(interfaceName))
                {
                    StringParser parser = new StringParser(line, '\t', skipEmpty: true);
                    parser.MoveNext();
                    parser.MoveNextOrFail();
                    string gatewayIPHex = parser.MoveAndExtractNext();
                    long addressValue = Convert.ToInt64(gatewayIPHex, 16);
                    IPAddress address = new IPAddress(addressValue);
                    collection.Add(new SimpleGatewayIPAddressInformation(address));
                }
            }

            return collection;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:29,代码来源:StringParsingHelpers.Addresses.cs

示例8: TestStringOne

        public void TestStringOne()
        {
            var matcher = new StringParser();

            var match = matcher.GetMatch(StrList1, matcher.One);
            Assert.IsTrue(match.Success);
            Assert.AreEqual(1, match.Result);
        }
开发者ID:darrenstarr,项目名称:ironmeta,代码行数:8,代码来源:StringParserTests.cs

示例9: Hello_StringParsing

        public Hello_StringParsing()
        {
            var sp = new StringParser();

            _parser = from x in sp.String("Hello")
                      from y in sp.Char(',')
                      select x;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:8,代码来源:Hello_StringParsing.cs

示例10: TestStringPi

        public void TestStringPi()
        {
            var matcher = new StringParser();

            var match = matcher.GetMatch(StrListPi, matcher.Pi);
            Assert.IsTrue(match.Success);
            Assert.AreEqual(314, match.Result);
        }
开发者ID:darrenstarr,项目名称:ironmeta,代码行数:8,代码来源:StringParserTests.cs

示例11: HelloOrHello_StringParsing

        public HelloOrHello_StringParsing()
        {
            var sp = new StringParser();

            _parser = (from hello in sp.String("Hello") select hello)
                .Longest(from hello in sp.String("Hello")
                         from comma in sp.Char(',')
                         select hello);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:9,代码来源:HelloOrHello_StringParsing.cs

示例12: Count_Returns_Number_Of_Tokens

        public void Count_Returns_Number_Of_Tokens()
        {
            Int32 EXPECTED = 2;
            StringParser target = new StringParser("unit test", ' ', StringSplitOptions.RemoveEmptyEntries);
            Assert.AreEqual(EXPECTED, target.Count);

            target = new StringParser(" unit  test ", " ", StringSplitOptions.RemoveEmptyEntries);
            Assert.AreEqual(EXPECTED, target.Count);
        }
开发者ID:rahilkidwai,项目名称:Net.Utility,代码行数:9,代码来源:StringParserTests.cs

示例13: Hello__StringParsing

        public Hello__StringParsing()
        {
            var sp = new StringParser();

            _parser = from x in sp.String("Hello")
                      from y in sp.Char(',')
                      from z in sp.Whitespace()
                      select x;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:9,代码来源:Hello__StringParsing.cs

示例14: TestParserWithNoEndingSeparatorWithSkipEmpty

        public void TestParserWithNoEndingSeparatorWithSkipEmpty()
        {
            string buffer = ",,,Str|ing,,123";
            char separator = ',';

            StringParser sp = new StringParser(buffer, separator, true);
            Assert.Equal("Str|ing", sp.MoveAndExtractNext());
            Assert.Equal(123, sp.ParseNextInt32());
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:9,代码来源:StringParserTests.cs

示例15: Hello__WorldStringParsing

        public Hello__WorldStringParsing()
        {
            var sp = new StringParser();

            _parser = from hello in sp.String("Hello")
                      from comma in sp.Char(',')
                      from ws in sp.Whitespace()
                      from world in sp.String("World")
                      select hello;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:10,代码来源:Hello__WorldStringParsing.cs


注:本文中的StringParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。