Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive option for ContainsKey and getter? #30

Open
a6874453 opened this issue Jul 8, 2021 · 1 comment
Open

Case insensitive option for ContainsKey and getter? #30

a6874453 opened this issue Jul 8, 2021 · 1 comment

Comments

@a6874453
Copy link

a6874453 commented Jul 8, 2021

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

@shravan2x
Copy link
Owner

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants