use of org.eclipse.jface.text.DefaultLineTracker in project flux by eclipse.
the class Strings method convertIntoLines.
/**
* Converts the given string into an array of lines. The lines
* don't contain any line delimiter characters.
*
* @param input the string
* @return the string converted into an array of strings. Returns <code>
* null</code> if the input string can't be converted in an array of lines.
*/
public static String[] convertIntoLines(String input) {
try {
ILineTracker tracker = new DefaultLineTracker();
tracker.set(input);
int size = tracker.getNumberOfLines();
String[] result = new String[size];
for (int i = 0; i < size; i++) {
IRegion region = tracker.getLineInformation(i);
int offset = region.getOffset();
result[i] = input.substring(offset, offset + region.getLength());
}
return result;
} catch (BadLocationException e) {
return null;
}
}
use of org.eclipse.jface.text.DefaultLineTracker in project flux by eclipse.
the class CodeTemplateContext method changeLineDelimiter.
private static String changeLineDelimiter(String code, String lineDelim) {
try {
ILineTracker tracker = new DefaultLineTracker();
tracker.set(code);
int nLines = tracker.getNumberOfLines();
if (nLines == 1) {
return code;
}
StringBuffer buf = new StringBuffer();
for (int i = 0; i < nLines; i++) {
if (i != 0) {
buf.append(lineDelim);
}
IRegion region = tracker.getLineInformation(i);
String line = code.substring(region.getOffset(), region.getOffset() + region.getLength());
buf.append(line);
}
return buf.toString();
} catch (BadLocationException e) {
// can not happen
return code;
}
}
Aggregations