I've just started getting into the Open API, so I apologize in advance if
this is a stupid question... (coding at 2 AM probably doesn't help either ![]()
What's the best way to tokenize a Document into individual lines? I've
found the getLineCount() method to get the number of lines, but i'd like to
know the best way to iterate over each line.
Should I just wrap the char array returned by doc.getChars() with a
CharArrayReader and BufferedReader like this:
CharArrayReader stringReader = new CharArrayReader(doc.getChars());
BufferedReader in = new BufferedReader(stringReader);
So that I could later call in.readLine() in a loop?
Or is there a better way?
thanks!
chris
As a followup, how can I get the user's line separator preference? I don't
see a relevant method in EditorSettings.
thanks,
chris
You actually do not need this in editor/document. Document always has single
'\n' line separator in it. User preference is taken into an account while
loading/saving a file.
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
"Develop with pleasure!"
"Chris Bartley" <spam@feynman.org> wrote in message
news:aleshp$5a2$1@is.intellij.net...
As a followup, how can I get the user's line separator preference? I
don't
see a relevant method in EditorSettings.
>
thanks,
>
chris
>
>
Ah, so easy!
Wow, you JetBrains folks are the best! Thanks for
creating such a wonderful IDE, and for making it so amazingly easy to use
and extend.
in total awe,
many thanks,
chris
"Maxim Shafirov" <max@intellij.net> wrote in message
news:alf7td$b88$1@is.intellij.net...
You actually do not need this in editor/document. Document always has
single
'\n' line separator in it. User preference is taken into an account while
loading/saving a file.
Getting slightly red ![]()
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
"Develop with pleasure!"
"Chris Bartley" <spam@feynman.org> wrote in message
news:alfm4g$l83$1@is.intellij.net...
Ah, so easy!
Wow, you JetBrains folks are the best! Thanks for
creating such a wonderful IDE, and for making it so amazingly easy to use
and extend.
>
in total awe,
many thanks,
>
chris
>
"Maxim Shafirov" <max@intellij.net> wrote in message
news:alf7td$b88$1@is.intellij.net...
You actually do not need this in editor/document. Document always has
single
'\n' line separator in it. User preference is taken into an account
while
loading/saving a file.
>
>
>
Would this be satisfactory?
Document doc = ...;
char[] docText = doc.getChars();
int lineCount = doc.getLineCount();
for (int i = 0; i < lineCount; i++) {
int lineStart = doc.getLineStartOffset(i);
int lineEnd = doc.getLineEndOffset(i);
String lineText = new String(docText, lineStart, lineEnd - lineStart);
// Do something with lineText...
}
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
"Develop with pleasure!"
Oooo, yes, that's absolutely perfect. Thanks so much! ![]()
"Maxim Shafirov" <max@intellij.net> wrote in message
news:alf7pi$b73$1@is.intellij.net...
Would this be satisfactory?
>
Document doc = ...;
char[] docText = doc.getChars();
int lineCount = doc.getLineCount();
for (int i = 0; i < lineCount; i++) {
int lineStart = doc.getLineStartOffset(i);
int lineEnd = doc.getLineEndOffset(i);
String lineText = new String(docText, lineStart, lineEnd -
lineStart);
>
// Do something with lineText...
}