Offsets counting CR/LF as 1 char?

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by shark92651
Avatar
I have some new bugs since upgrading to version 4.0. I have an external parser that is counting the new CR/LF line terminators as two characters but the editor considers this only one character - this seems wrong. Of course, now all my indicators are off by 1 character per line. Is there a way to tell it to count the line terminators as 2 chars long?

Comments (4)

Posted 13 years ago by shark92651
Avatar
Ok, I found the GetText mehtod - I think this may solve it for me.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes what happened was that we felt the way it is in v4.0 is how it should have been all along. In v3.1, properties like Document.Text would only return the LF-only line ends. But typically when you grab the Text property you are expecting it to be the code that has both CR and LF so we changed Text to default to CRLF in v4.0. As you noticed, there is a GetText method that lets you specify the format you want. Also GetSubstring has a similar overload.


Actipro Software Support

Posted 13 years ago by shark92651
Avatar
Well at least I can work around the issue now but it still seems to not be quite right by default. I agree that if it is saving/loading the file with CR/LF pairs that it should also internally return those line terminator characters in the string, however I think it should by default also count that as 2 chars when dealing with offsets. The fact that I have to use GetText(LineTerminator.NewLine) just to get the offsets to align properly seems strange since I am indeed using LineTerminator.CarraigeReturnNewLine as my line terminator. I would suggest you make the offsets count the actual number of characters in the string but add a property such as OldStyleLineOffsets to allow people to keep the old behavior without having to change all their code.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Unfortunately it isn't practical for parsing reasons to keep two offsets in a string. If we did that, some files have CR only, some have LF only, others have CR LF. So there is no consistent pattern to check for when looking for line ends. Now obviously we have to do that somewhere, so we take the parsing hit the first time the text is typed, pasted, or loaded into the control. But then from that point on, we know that there will always only be a LF at the end of each line internally. So the fact that we know exactly what character delimits a line terminator and that there is only one character eliminates all kinds of if...then...else statements and such that would need to be scattered through our code, thereby slowing down run-time parsing significantly. Hope that explains the reasoning.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.