Problem Statement
You are given a String[] text. Each element of text represents a single line. A character is called escaped if it is immediately preceded by an unescaped slash character. Otherwise, it is called unescaped. For example, in the string "hello/nworld" the character 'n' is escaped, but in the string "hello//nworld", it is not. In the second example the second slash character is escaped by the first one. If an unescaped slash ends a line, it does not escape any character.
Replace all escaped 'n' characters in text with line breaks. Then, remove all remaining slashes that currently escape a character, and return the resulting text as a String[]. Each element of this String[] should correspond to a line of the text. text may contain empty strings, which must be preserved in the return value (see examples for clarification).
Definition
- Class:
- TextUnescaper
- Method:
- processLines
- Parameters:
- String[]
- Returns:
- String[]
- Method signature:
- String[] processLines(String[] text)
- (be sure your method is public)
Notes
- Do not process "/N" as a line break. It is case sensitive.
Constraints
- text will contain between 1 and 50 elements, inclusive.
- Each element of text will contain between 0 and 50 characters, inclusive.
- Each element of text will contain letters ('a'..'z', 'A'..'Z'), digits ('0'..'9'), spaces (' ') and slashes ('/') only.
Examples
{"First line/nSecond line", "Third /line/", "/And //fourth"}Returns: {"First line", "Second line", "Third line/", "And /fourth" }The first line is divided into two lines because of the escaped 'n'. In the second line of the original text, only the first slash escapes a character. In the third line of the original text, the first two slashes each escape a character. However, the third slash doesn't escape a character because it is escaped by the second slash.{"/n", "", "/n/n/n"}Returns: {"", "", "", "", "", "", "" }There are three lines and four escaped 'n's. So the result contains seven empty lines.{"Just plain", "text", "nothing special"}Returns: {"Just plain", "text", "nothing special" }{"Beware of this//n"}Returns: {"Beware of this/n" }{"///n", "/N"}Returns: {"/", "", "N" }Do not process "/N" as a line break.