Made some progress on my configuration file parser / writer; ParserHelper can now skip over floating point values
git-svn-id: file:///srv/devel/repo-conversion/nusu@298 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
0bb50d9254
commit
ddc76cf09f
11 changed files with 513 additions and 79 deletions
|
@ -93,7 +93,7 @@ namespace Nuclex.Support.Parsing {
|
|||
public void CanSkipNumbersInNullString() {
|
||||
int index = 0;
|
||||
Assert.DoesNotThrow(
|
||||
delegate() { ParserHelper.SkipNumbers((string)null, ref index); }
|
||||
delegate() { ParserHelper.SkipNumericals((string)null, ref index); }
|
||||
);
|
||||
Assert.AreEqual(0, index);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ namespace Nuclex.Support.Parsing {
|
|||
public void CanSkipNumbersInEmptyString() {
|
||||
int index = 0;
|
||||
Assert.DoesNotThrow(
|
||||
delegate() { ParserHelper.SkipNumbers(string.Empty, ref index); }
|
||||
delegate() { ParserHelper.SkipNumericals(string.Empty, ref index); }
|
||||
);
|
||||
Assert.AreEqual(0, index);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace Nuclex.Support.Parsing {
|
|||
[Test]
|
||||
public void NumbersCanBeSkipped() {
|
||||
int index = 6;
|
||||
ParserHelper.SkipNumbers("123abc456def789", ref index);
|
||||
ParserHelper.SkipNumericals("123abc456def789", ref index);
|
||||
Assert.AreEqual(9, index);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace Nuclex.Support.Parsing {
|
|||
/// This skips only numeric characters, but not complete numbers -- if the number
|
||||
/// begins with a minus or plus sign, for example, this function will not skip it.
|
||||
/// </remarks>
|
||||
public static void SkipNumbers(string text, ref int index) {
|
||||
public static void SkipNumericals(string text, ref int index) {
|
||||
if(text == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -102,14 +102,14 @@ namespace Nuclex.Support.Parsing {
|
|||
if((text[index] == '-') || (text[index] == '+')) {
|
||||
nextIndex = index + 1;
|
||||
|
||||
SkipNumbers(text, ref nextIndex);
|
||||
SkipNumericals(text, ref nextIndex);
|
||||
if(nextIndex == (index + 1)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
nextIndex = index;
|
||||
|
||||
SkipNumbers(text, ref nextIndex);
|
||||
SkipNumericals(text, ref nextIndex);
|
||||
if(nextIndex == index) {
|
||||
return false;
|
||||
}
|
||||
|
@ -154,6 +154,28 @@ namespace Nuclex.Support.Parsing {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Skips a floating point value appearing in the input text</summary>
|
||||
/// <param name="text">Text in which a floating point value will be skipped</param>
|
||||
/// <param name="index">Index at which the floating point value begins</param>
|
||||
/// <returns>True if the floating point value was skipped, otherwise false</returns>
|
||||
public static bool SkipFloat(string text, ref int index) {
|
||||
if(SkipInteger(text, ref index)) {
|
||||
if(index < text.Length) {
|
||||
if(text[index] == '.') {
|
||||
++index;
|
||||
SkipNumericals(text, ref index);
|
||||
}
|
||||
if((text[index] == 'e') || (text[index] == 'E')) {
|
||||
throw new NotImplementedException("Exponential format not supported yet");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Support.Parsing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue