Implement a function that converts simplified link syntax text into an HTML anchor tag <a href="url">text</a> across an entire input string. Constraints: do not use regular expressions; rely only on basic string operations (e.g., indexOf, split, substring). Requirements:
-
Support multiple links per line and across lines.
-
Preserve all non-link text and punctuation.
-
Leave malformed patterns (e.g., missing brackets or quotes) unchanged.
-
If brackets appear inside the label, treat the innermost valid [ ... ] preceding a (" ... ") as the link label.
-
Treat escaped brackets or quotes (preceded by a backslash ) as literals.
-
Analyze the time and space complexity of your approach.
-
Provide unit tests for typical, edge, and large inputs.
Examples:
Input: "Click
Go to Link
now."
Output: "Click <a href="whateverlink.com">Go to Link
</a>
now."
Input: "
A
and
B
"
Output: "<a href="u1">A
</a>
and <a href="u2">B
</a>
"
Input: "Broken
label
stays"
Output: "Broken
label
stays"