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

Option to ignore case for string atom #1

Open
tadfisher opened this issue May 8, 2023 · 0 comments
Open

Option to ignore case for string atom #1

tadfisher opened this issue May 8, 2023 · 0 comments

Comments

@tadfisher
Copy link

tadfisher commented May 8, 2023

I have to say that this is the best parser library for Kotlin right now. One thing that's less-than-trivial to implement is a case-insensitive variant of string(), which kind of requires a copy-paste of the string() implementation:

fun ParserState.stringIgnoreCase(expected: String): String {
    if (position + expected.length > input.length) {
        fail("Expected '$expected', but got EOF.")
    }

    if (!input.regionMatches(position, expected, 0, expected.length, ignoreCase = true)) {
        fail(
            "Expected '$expected' (ignoring case), but got " +
                "'${input.substring(position, position + expected.length)}'."
        )
    }
    position += expected.length
    return expected
}

fun stringIgnoreCase(expected: String): Parser<String> = parser { stringIgnoreCase(expected) }

As you can see, the only way this differs from string() is the addition of the ignoreCase argument to regionMatches. Would it make sense to add a parameter like ignoreCase = false to the existing string atom?

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

No branches or pull requests

1 participant