mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
Interpret numeric values as being hexadecimal values if they contain hex digits a-f
svn path=/trunk/; revision=13612
This commit is contained in:
parent
8bab7189cb
commit
a1c0271111
1 changed files with 31 additions and 1 deletions
|
@ -7,13 +7,43 @@ namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public bool Error = false;
|
public bool Error = false;
|
||||||
|
|
||||||
|
private const string SpecialHexCharacters = "ABCDEF";
|
||||||
|
|
||||||
|
private bool IsSpecialHexCharacter(char ch)
|
||||||
|
{
|
||||||
|
foreach (char specialChar in SpecialHexCharacters)
|
||||||
|
{
|
||||||
|
if (ch.ToString().ToUpper() == specialChar.ToString())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HasSpecialHexCharacters(string s)
|
||||||
|
{
|
||||||
|
foreach (char ch in s)
|
||||||
|
{
|
||||||
|
if (IsSpecialHexCharacter(ch))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public long Parse(string s)
|
public long Parse(string s)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Error = false;
|
Error = false;
|
||||||
|
bool useHex = false;
|
||||||
if (s.StartsWith("0x"))
|
if (s.StartsWith("0x"))
|
||||||
return Int64.Parse(s.Substring(2),
|
{
|
||||||
|
s = s.Substring(2);
|
||||||
|
useHex = true;
|
||||||
|
}
|
||||||
|
if (HasSpecialHexCharacters(s))
|
||||||
|
useHex = true;
|
||||||
|
if (useHex)
|
||||||
|
return Int64.Parse(s,
|
||||||
NumberStyles.HexNumber);
|
NumberStyles.HexNumber);
|
||||||
else
|
else
|
||||||
return Int64.Parse(s);
|
return Int64.Parse(s);
|
||||||
|
|
Loading…
Reference in a new issue