Gameloop.Vdf
Gameloop.Vdf copied to clipboard
Case insensitive option for ContainsKey and getter?
Hello, i would like to ask if i can retrieve a value by a key name ignoring the case?
In source engine KeyValues class, this code:
KeyValues *pKV = new KeyValues("Test");
pKV->SetInt("Apple", 5);
Msg("%d %d", pKV->GetInt("apple"), pKV->GetInt("APPLE"));
it prints "5 5", which means the cases are ignored
Json.NET appears to have a GetValue
method that this library doesn't yet support. I'll tag this issue as a feature request.
In the meantime, you should be able to filter children manually
// returns 5
pKV.Children<VProperty>().First(x => x.Key.Equals("apple", StringComparison.InvariantCultureIgnoreCase)).Value
You could also write an extension method that does this:
public static class VdfExtensions
{
public static VToken GetValueIgnoreCase(this VObject obj, string key)
{
return obj.Children<VProperty>().First(x => x.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)).Value;
}
}
// returns 5
pKV.GetValueIgnoreCase("apple")