Simplified the parsing code; all code paths of the configuration file store are now covered by tests
git-svn-id: file:///srv/devel/repo-conversion/nusu@307 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
55b3ffd923
commit
03ada146e5
|
@ -239,18 +239,15 @@ namespace Nuclex.Support.Settings {
|
||||||
if(value.Count >= 2) {
|
if(value.Count >= 2) {
|
||||||
int index = value.Offset;
|
int index = value.Offset;
|
||||||
if(ParserHelper.SkipInteger(value.Text, ref index)) {
|
if(ParserHelper.SkipInteger(value.Text, ref index)) {
|
||||||
if(index < value.Offset + value.Count) {
|
if(index >= value.Offset + value.Count) {
|
||||||
if(value.Text[index] == '.') {
|
return typeof(int);
|
||||||
return typeof(float);
|
}
|
||||||
}
|
if(value.Text[index] == '.') {
|
||||||
|
return typeof(float);
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeof(int);
|
|
||||||
}
|
}
|
||||||
} else if(value.Count >= 1) { // If it's at least one character, it may be a number
|
} else { // If it's just a single character, it may be a number
|
||||||
int index = value.Offset;
|
if(char.IsNumber(value.Text, value.Offset)) {
|
||||||
ParserHelper.SkipNumericals(value.Text, ref index);
|
|
||||||
if(index > value.Offset) {
|
|
||||||
return typeof(int);
|
return typeof(int);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,10 +356,13 @@ namespace Nuclex.Support.Settings {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[
|
[
|
||||||
Test,
|
Test,
|
||||||
|
TestCase("nothing=", typeof(string)),
|
||||||
TestCase("text = world", typeof(string)),
|
TestCase("text = world", typeof(string)),
|
||||||
TestCase("short=9", typeof(int)),
|
TestCase("short=9", typeof(int)),
|
||||||
TestCase("integer = 123", typeof(int)),
|
TestCase("integer = 123", typeof(int)),
|
||||||
TestCase("integer = 123 ", typeof(int)),
|
TestCase("integer = 123 ", typeof(int)),
|
||||||
|
TestCase("string=x", typeof(string)),
|
||||||
|
TestCase("string = 123s", typeof(string)),
|
||||||
TestCase("float = 123.45", typeof(float)),
|
TestCase("float = 123.45", typeof(float)),
|
||||||
TestCase("float = 123.45 ", typeof(float)),
|
TestCase("float = 123.45 ", typeof(float)),
|
||||||
TestCase("boolean = true", typeof(bool)),
|
TestCase("boolean = true", typeof(bool)),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user