I work with massive strings which need a lot of manipulation.For example, I might generate a string like this:Part 1 BoatSection A  ProgrammingPart 2 Partitioning boats for programming.Section AA Section SQL Entries.The string would be too large to manually check every part of it. Now I need to split this string into a stringlist by sections and parts. I can think of two options:A Regular Expression:QStringList sl = s.split(QRegularExpression(\n(?=Part [0-9]+|Section [A-Z]+)));That looks like it should work, but sometimes exceptions slip through (IE: Section SQL Entries would erroneously get split)Otherwise what I could do is place a marker when I generate the initial string:Part 1 BoatSection A  ProgrammingPart 2 Partitioning boats for programming.Section AA Section SQL Entries.Which means that splitting the string would become easy:QStringList sl = s.split());Something tells me though that neither of these are good style or programming practice, but I have up until this point not discussed it nor found an alternative.If you were my project manager, would you accept either of these methods? If not, what would you suggest I do as a best practice?
Is placing text markers inside of strings bad style? Is there an alternative?
programming practices;coding style;coding standards;strings;regular expressions
It's not bad practice to have document encoding embedded as text in a string. Think of markdown, HTML, XML, JSON, YAML, LaTeX, etc.What is bad practice is reinventing the wheel. Rather than writing your own text processor, think about using an existing standard. There's plenty of free software that do much of the parsing for you, and many have a non-restrictive license that let you use said software in your own proprietary software.