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


C# StringParser.MoveAndExtractNext方法代码示例

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


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

示例1: 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

示例2: 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

示例3: TestParserWithNoEndingSeparatorWithNoSkipEmpty

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

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

示例4: TestParserMoveWithSkipEmpty

        public void TestParserMoveWithSkipEmpty()
        {
            string buffer = "My,, ,Te,,st,Str|ing,,123,,";
            char separator = ',';

            StringParser sp = new StringParser(buffer, separator, true);
            sp.MoveNextOrFail();
            Assert.Equal("My", sp.ExtractCurrent());
            Assert.Equal(' ', sp.ParseNextChar());
            sp.MoveNextOrFail();
            Assert.Equal("Te", sp.ExtractCurrent());
            Assert.Equal("st", sp.MoveAndExtractNext());
            sp.MoveNextOrFail();
            Assert.Equal("Str|ing", sp.ExtractCurrent());
            Assert.Equal(123, sp.ParseNextInt32());
            Assert.Throws<InvalidDataException>(() => sp.MoveNextOrFail());
            sp.MoveNext();
            Assert.Equal("", sp.ExtractCurrent());
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:19,代码来源:StringParserTests.cs

示例5: CreateIPv4Statistics

        /// <summary>
        /// Constructs an IPGlobalStatistics object from the snmp4 stats file.
        /// </summary>
        public static LinuxIPGlobalStatistics CreateIPv4Statistics()
        {
            LinuxIPGlobalStatistics stats = new LinuxIPGlobalStatistics();
            string fileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
            int firstIpHeader = fileContents.IndexOf("Ip:");
            int secondIpHeader = fileContents.IndexOf("Ip:", firstIpHeader + 1);
            int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondIpHeader);
            string ipData = fileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
            StringParser parser = new StringParser(ipData, ' ');

            // 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 Ip:

            // According to RFC 1213, "1" indicates "acting as a gateway". "2" indicates "NOT acting as a gateway".
            stats._forwarding = parser.MoveAndExtractNext() == "1";
            stats._defaultTtl = parser.ParseNextInt32();
            stats._inReceives = parser.ParseNextInt32();
            stats._inHeaderErrors = parser.ParseNextInt32();
            stats._inAddressErrors = parser.ParseNextInt32();
            stats._forwardedDatagrams = parser.ParseNextInt32();
            stats._inUnknownProtocols = parser.ParseNextInt32();
            stats._inDiscards = parser.ParseNextInt32();
            stats._inDelivers = parser.ParseNextInt32();
            stats._outRequests = parser.ParseNextInt32();
            stats._outDiscards = parser.ParseNextInt32();
            stats._outNoRoutes = parser.ParseNextInt32();
            stats._reassemblyTimeout = parser.ParseNextInt32();
            stats._reassemblyRequireds = parser.ParseNextInt32();
            stats._reassemblyOKs = parser.ParseNextInt32();
            stats._reassemblyFails = parser.ParseNextInt32();
            stats._fragmentOKs = parser.ParseNextInt32();
            stats._fragmentFails = parser.ParseNextInt32();
            stats._fragmentCreates = parser.ParseNextInt32();

            string routeFile = ReadProcConfigFile(NetworkFiles.Ipv4RouteFile);
            stats._numRoutes = CountOccurences(Environment.NewLine, routeFile) - 1; // File includes one-line header

            stats._numInterfaces = GetNumInterfaces();
            stats._numIPAddresses = GetNumIPAddresses();
            return stats;
        }
开发者ID:JonHanna,项目名称:corefx,代码行数:46,代码来源:LinuxIPGlobalStatistics.cs

示例6: ParseRemoteConnectionInformation

        // Common parsing logic for the remote connection information
        private static void ParseRemoteConnectionInformation(string line, out IPAddress remoteIPAddress, out int remotePort)
        {
            StringParser parser = new StringParser(line, ' ', true);
            parser.MoveNextOrFail(); // skip Index
            parser.MoveNextOrFail(); // skip local_address

            string remoteAddressAndPort = parser.MoveAndExtractNext();
            int indexOfColon = remoteAddressAndPort.IndexOf(':');
            if (indexOfColon == -1)
            {
                throw new InvalidOperationException("Parsing error. No colon in " + remoteAddressAndPort);
            }

            string remoteAddressString = remoteAddressAndPort.Substring(0, indexOfColon);
            remoteIPAddress = ParseHexIPAddress(remoteAddressString);

            string portString = remoteAddressAndPort.Substring(indexOfColon + 1, remoteAddressAndPort.Length - (indexOfColon + 1));
            if (!int.TryParse(portString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out remotePort))
            {
                throw new InvalidOperationException("Couldn't parse remote port number " + portString);
            }
        }
开发者ID:nadyalo,项目名称:corefx,代码行数:23,代码来源:StringParsingHelpers.Connections.cs

示例7: ParseTcpConnectionInformationFromLine

        // Parsing logic for local and remote addresses and ports, as well as socket state.
        internal static TcpConnectionInformation ParseTcpConnectionInformationFromLine(string line)
        {
            StringParser parser = new StringParser(line, ' ', true);
            parser.MoveNextOrFail(); // skip Index

            string localAddressAndPort = parser.MoveAndExtractNext(); // local_address
            IPAddress localAddress;
            int localPort;
            ParseAddressAndPort(localAddressAndPort, out localAddress, out localPort);

            string remoteAddressAndPort = parser.MoveAndExtractNext(); // rem_address
            IPAddress remoteAddress;
            int remotePort;
            ParseAddressAndPort(remoteAddressAndPort, out remoteAddress, out remotePort);

            string socketStateHex = parser.MoveAndExtractNext();
            int state;
            if (!int.TryParse(socketStateHex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out state))
            {
                throw new InvalidOperationException("Invalid state value: " + socketStateHex);
            }
            TcpState tcpState = MapTcpState((Interop.LinuxTcpState)state);

            IPEndPoint localEndPoint = new IPEndPoint(localAddress, localPort);
            IPEndPoint remoteEndPoint = new IPEndPoint(remoteAddress, remotePort);

            return new SimpleTcpConnectionInformation(localEndPoint, remoteEndPoint, tcpState);
        }
开发者ID:nadyalo,项目名称:corefx,代码行数:29,代码来源:StringParsingHelpers.Connections.cs

示例8: ParseLocalConnectionInformation

        // Common parsing logic for the local connection information.
        private static IPEndPoint ParseLocalConnectionInformation(string line)
        {
            StringParser parser = new StringParser(line, ' ', true);
            parser.MoveNextOrFail(); // skip Index

            string localAddressAndPort = parser.MoveAndExtractNext();
            int indexOfColon = localAddressAndPort.IndexOf(':');
            if (indexOfColon == -1)
            {
                throw ExceptionHelper.CreateForParseFailure();
            }

            string remoteAddressString = localAddressAndPort.Substring(0, indexOfColon);
            IPAddress localIPAddress = ParseHexIPAddress(remoteAddressString);

            string portString = localAddressAndPort.Substring(indexOfColon + 1, localAddressAndPort.Length - (indexOfColon + 1));
            int localPort;
            if (!int.TryParse(portString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out localPort))
            {
                throw ExceptionHelper.CreateForParseFailure();
            }

            return new IPEndPoint(localIPAddress, localPort);
        }
开发者ID:ardacetinkaya,项目名称:corefx,代码行数:25,代码来源:StringParsingHelpers.Connections.cs

示例9: ParseTcpConnectionInformationFromLine

        // Parsing logic for local and remote addresses and ports, as well as socket state.
        internal static TcpConnectionInformation ParseTcpConnectionInformationFromLine(string line)
        {
            StringParser parser = new StringParser(line, ' ', skipEmpty: true);
            parser.MoveNextOrFail(); // skip Index

            string localAddressAndPort = parser.MoveAndExtractNext(); // local_address
            IPEndPoint localEndPoint = ParseAddressAndPort(localAddressAndPort);

            string remoteAddressAndPort = parser.MoveAndExtractNext(); // rem_address
            IPEndPoint remoteEndPoint = ParseAddressAndPort(remoteAddressAndPort);

            string socketStateHex = parser.MoveAndExtractNext();
            int nativeTcpState;
            if (!int.TryParse(socketStateHex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out nativeTcpState))
            {
                throw ExceptionHelper.CreateForParseFailure();
            }

            TcpState tcpState = MapTcpState(nativeTcpState);

            return new SimpleTcpConnectionInformation(localEndPoint, remoteEndPoint, tcpState);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:23,代码来源:StringParsingHelpers.Connections.cs

示例10: ParseIPv4GlobalStatisticsFromSnmpFile

        public static IPGlobalStatisticsTable ParseIPv4GlobalStatisticsFromSnmpFile(string filePath)
        {
            string fileContents = File.ReadAllText(filePath);

            int firstIpHeader = fileContents.IndexOf("Ip:", StringComparison.Ordinal);
            int secondIpHeader = fileContents.IndexOf("Ip:", firstIpHeader + 1, StringComparison.Ordinal);
            int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondIpHeader, StringComparison.Ordinal);
            string ipData = fileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
            StringParser parser = new StringParser(ipData, ' ');

            parser.MoveNextOrFail(); // Skip Ip:

            // According to RFC 1213, "1" indicates "acting as a gateway". "2" indicates "NOT acting as a gateway".
            return new IPGlobalStatisticsTable()
            {
                Forwarding = parser.MoveAndExtractNext() == "1",
                DefaultTtl = parser.ParseNextInt32(),
                InReceives = parser.ParseNextInt32(),
                InHeaderErrors = parser.ParseNextInt32(),
                InAddressErrors = parser.ParseNextInt32(),
                ForwardedDatagrams = parser.ParseNextInt32(),
                InUnknownProtocols = parser.ParseNextInt32(),
                InDiscards = parser.ParseNextInt32(),
                InDelivers = parser.ParseNextInt32(),
                OutRequests = parser.ParseNextInt32(),
                OutDiscards = parser.ParseNextInt32(),
                OutNoRoutes = parser.ParseNextInt32(),
                ReassemblyTimeout = parser.ParseNextInt32(),
                ReassemblyRequireds = parser.ParseNextInt32(),
                ReassemblyOKs = parser.ParseNextInt32(),
                ReassemblyFails = parser.ParseNextInt32(),
                FragmentOKs = parser.ParseNextInt32(),
                FragmentFails = parser.ParseNextInt32(),
                FragmentCreates = parser.ParseNextInt32(),
            };
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:36,代码来源:StringParsingHelpers.Statistics.cs

示例11: TestExtractingStringFromParentheses

        public void TestExtractingStringFromParentheses()
        {
            string buffer = "This(is a unicode \u0020)something,(89),(haha123blah)After brace,";
            char separator = ',';

            StringParser sp = new StringParser(buffer, separator);
            Assert.Throws<InvalidDataException>(() => sp.MoveAndExtractNextInOuterParens());
            Assert.Equal("This(is a unicode \u0020)something", sp.ExtractCurrent());
            Assert.Equal("89),(haha123blah", sp.MoveAndExtractNextInOuterParens());
            Assert.Equal("(89),(haha123blah)", sp.ExtractCurrent());
            Assert.Equal("fter brace", sp.MoveAndExtractNext());
            Assert.Equal("", sp.MoveAndExtractNext());
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:13,代码来源:StringParserTests.cs

示例12: TestUnicodeSeparator

        public void TestUnicodeSeparator()
        {
            string buffer = "\u0020some\u0020123";
            char separator = '\u0020';

            StringParser sp = new StringParser(buffer, separator);
            sp.MoveNextOrFail();
            Assert.Equal("some", sp.MoveAndExtractNext());
            Assert.Equal((uint)123, sp.ParseNextUInt32());
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:10,代码来源:StringParserTests.cs

示例13: GetGatewayAddresses

        // /proc/net/route contains some information about gateway addresses,
        // and seperates the information about by each interface.
        public GatewayIPAddressInformationCollection GetGatewayAddresses()
        {
            GatewayIPAddressInformationCollection collection = new GatewayIPAddressInformationCollection();
            // Columns are as follows (first-line header):
            // Iface  Destination  Gateway  Flags  RefCnt  Use  Metric  Mask  MTU  Window  IRTT
            string[] fileLines = File.ReadAllLines(NetworkFiles.Ipv4RouteFile);
            foreach (string line in fileLines)
            {
                if (line.StartsWith(_linuxNetworkInterface.Name))
                {
                    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.InternalAdd(new SimpleGatewayIPAddressInformation(address));
                }
            }

            return collection;
        }
开发者ID:JonHanna,项目名称:corefx,代码行数:24,代码来源:LinuxIPInterfaceProperties.cs

示例14: TestExtractCurrentToEnd

 public void TestExtractCurrentToEnd()
 {
     string buffer = "This has a /path/to my favorite file/with a space";
     char separator = ' ';
     StringParser sp = new StringParser(buffer, separator);
     Assert.Equal("This", sp.MoveAndExtractNext());
     Assert.Equal("has", sp.MoveAndExtractNext());
     Assert.Equal("a", sp.MoveAndExtractNext());
     Assert.True(sp.MoveNext());
     Assert.Equal("/path/to my favorite file/with a space", sp.ExtractCurrentToEnd());
 }
开发者ID:dotnet,项目名称:corefx,代码行数:11,代码来源:StringParserTests.cs


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