本文整理汇总了C#中StringParser.MoveNext方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.MoveNext方法的具体用法?C# StringParser.MoveNext怎么用?C# StringParser.MoveNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringParser
的用法示例。
在下文中一共展示了StringParser.MoveNext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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());
}
示例3: 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;
}
示例4: ParseMapsModulesCore
private static IEnumerable<ParsedMapsModule> ParseMapsModulesCore(IEnumerable<string> lines)
{
Debug.Assert(lines != null);
// Parse each line from the maps file into a ParsedMapsModule result
foreach (string line in lines)
{
// Use a StringParser to avoid string.Split costs
var parser = new StringParser(line, separator: ' ', skipEmpty: true);
// Parse the address range
KeyValuePair<long, long> addressRange =
parser.ParseRaw(delegate (string s, ref int start, ref int end)
{
long startingAddress = 0, endingAddress = 0;
int pos = s.IndexOf('-', start, end - start);
if (pos > 0)
{
string startingString = s.Substring(start, pos);
if (long.TryParse(startingString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out startingAddress))
{
string endingString = s.Substring(pos + 1, end - (pos + 1));
long.TryParse(endingString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out endingAddress);
}
}
return new KeyValuePair<long, long>(startingAddress, endingAddress);
});
// Parse the permissions (we only care about entries with 'r' and 'x' set)
if (!parser.ParseRaw(delegate (string s, ref int start, ref int end)
{
bool sawRead = false, sawExec = false;
for (int i = start; i < end; i++)
{
if (s[i] == 'r')
sawRead = true;
else if (s[i] == 'x')
sawExec = true;
}
return sawRead & sawExec;
}))
{
continue;
}
// Skip past the offset, dev, and inode fields
parser.MoveNext();
parser.MoveNext();
parser.MoveNext();
// Parse the pathname
if (!parser.MoveNext())
{
continue;
}
string pathname = parser.ExtractCurrent();
// We only get here if a we have a non-empty pathname and
// the permissions included both readability and executability.
// Yield the result.
yield return new ParsedMapsModule { FileName = pathname, AddressRange = addressRange };
}
}
示例5: ResolvePath
/// <summary>Resolves a path to the filename passed to ProcessStartInfo.</summary>
/// <param name="filename">The filename.</param>
/// <returns>The resolved path.</returns>
private static string ResolvePath(string filename)
{
// Follow the same resolution that Windows uses with CreateProcess:
// 1. First try the exact path provided
// 2. Then try the file relative to the executable directory
// 3. Then try the file relative to the current directory
// 4. then try the file in each of the directories specified in PATH
// Windows does additional Windows-specific steps between 3 and 4,
// and we ignore those here.
// If the filename is a complete path, use it, regardless of whether it exists.
if (Path.IsPathRooted(filename))
{
// In this case, it doesn't matter whether the file exists or not;
// it's what the caller asked for, so it's what they'll get
return filename;
}
// Then check the executable's directory
string path = GetExePath();
if (path != null)
{
try
{
path = Path.Combine(Path.GetDirectoryName(path), filename);
if (File.Exists(path))
{
return path;
}
}
catch (ArgumentException) { } // ignore any errors in data that may come from the exe path
}
// Then check the current directory
path = Path.Combine(Directory.GetCurrentDirectory(), filename);
if (File.Exists(path))
{
return path;
}
// Then check each directory listed in the PATH environment variables
string pathEnvVar = Environment.GetEnvironmentVariable("PATH");
if (pathEnvVar != null)
{
var pathParser = new StringParser(pathEnvVar, ':', skipEmpty: true);
while (pathParser.MoveNext())
{
string subPath = pathParser.ExtractCurrent();
path = Path.Combine(subPath, filename);
if (File.Exists(path))
{
return path;
}
}
}
// Could not find the file
throw new Win32Exception(Interop.Errors.ENOENT);
}
示例6: 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());
}