That was easier than I thought – yeah, right

In my last post I announced that the GExperts code formatter now supported multiline string literals and boasted that this “was easier than I thought”.

Turns out that it was actually more complicated. I should have known immediately because two of the existing unit testes failed, but somehow I didn’t notice that.

Consider the following code:

  bla := '''^';

That’s obviously not the start of a multiline string literal, it’s a regular string literal containing "’^", where the single quote had been escaped. Unfortunately my detection code thought it was, so it treated the rest of the file as multiline string literal, that is, it didn’t touch it.

So I added a unit test and fixed that by making sure, that there was a space character or a new line after the third single quote. All unit tests worked fine and I thought I had nailed it.

Until I yet a another possibility occurred to me (while I was supposed to be sleeping 🙁 ):

  bla := ''' ';

That again is a regular string literal containing "’ ".

Some more testing showed that the IDE and the compiler do not allow for any other charactor between the triple quote and the new line (I guess that’s all in the published formal description of the Object Pascal language, right?).

So I created another unit test and fixed the code again. I hope I am correct this time, when I say that the GExperts Code Formatter supports multiline string literals.