call(back)
Algorithms & Data StructureseasySign in to star problems

Docstring Naming Conversion

A line of documentation refers to code inside backticks. A pair of backticks encloses one or more identifiers separated by spaces. Function and variable names are written in snake_case (lowercase words joined by underscores); constants are written in UPPER_CASE.

Convert every snake_case identifier inside backticks to camelCase: keep the first word as it is, capitalise the first letter of each later word, and drop the underscores. Leave constants unchanged, and leave everything outside backticks exactly as it is, including the backticks and the spaces between identifiers.

Input:  Function `some_function` has two arguments `short_arg very_long_argument`.
        The `very_long_argument` has a default value of `CONSTANT_VALUE`.
Output: Function `someFunction` has two arguments `shortArg veryLongArgument`.
        The `veryLongArgument` has a default value of `CONSTANT_VALUE`.

The line is 1 to 2,000 characters long and its backticks are always paired. Words inside an identifier may contain digits.

Hints

Hint 1

Track one bit of state while scanning: whether you are inside a backtick span. Text outside is copied; text inside is processed identifier by identifier.

Hint 2

An identifier is a constant when it contains no lowercase letter. Otherwise split it on underscores and capitalise every word after the first.

Hint 3

Do not split the span on whitespace and re-join with single spaces: several spaces in a row have to survive.

Topics

Asked at

Similar Problems6