ITextSnapshot Text and LineTerminator

SyntaxEditor Brainstorming Forum

Posted 15 years ago by Mike Strobel - Software Engineer, CDC Software
Avatar
A week or so ago I was working on a DLR language parser/highlighter for the SyntaxEditor alpha. I would create classification ranges based on the ranges of the tokens that I received from the DLR's tokenizer service, but my classification ranges were always several characters off, and I was getting argument out-of-range exceptions. I eventually figured out that the text ranges expected from the classifier were based on the document text using \n line terminators, while the ITextSnapshot's Text property returned the text using \r\n line terminators. This seems a bit odd to me. I was able to get it working by passing the result of GetText(LineTerminator.Newline) to the DLR's tokenizer, but the current design seems a bit counterintuitive. I would think that the Text property would expose the text with the same formatting as is expected by the parser/classifier. Has anyone else run into this issue?

Perhaps Text should return the document text with \n line terminators, and a RawText or OriginalText property should return the text with the document's original line terminators?

[Modified at 02/23/2009 08:43 AM]

Comments (3)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We actually used to return \n-only text via Text properties in SyntaxEditor 3.1 or so. However we ran into tons of people who complained the opposite way because they expected \r\n. The other bad thing about that way was that often enough people would grab Text and save it to files or bind it to other data etc. So they'd end up with saved files or data that only had \n line terminators, instead of \r\n as they were expecting.

So these days we have the Text property return \r\n (which is what mot people expect for external usage) but for parsing or other reasons, the GetText method can be used to get any format you need. Hope that helps explain the reasoning behind it.


Actipro Software Support

Posted 15 years ago by Mike Strobel - Software Engineer, CDC Software
Avatar
I know all too well how user (developer) habits help to shape APIs. I can see why you made the change. How about adding some tips to the API docs, like this:

ITextSnapshot.Text
==================

<remarks>
This value should not be used as input for language parsers or classifiers.  Instead, call <see cref="GetText(LineTerminator)"/> with the <see cref="LineTerminator.Newline"/> parameter.
</remarks>
ITextSnapshot.GetText(LineTerminator)
==================

<remarks>
To retrieve the document text in the format expected by a language parser or classifier, pass <see cref="LineTerminator.Newline"/> as the <paramref name="lineTerminator" /> parameter.
</remarks>
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Good points, will do.


Actipro Software Support