Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java22
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/OutputStreamMonitor.java28
2 files changed, 45 insertions, 5 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java
index 21e5c20fa..33e06f21e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java
@@ -333,7 +333,27 @@ public class InputStreamMonitor extends OutputStream implements IDisposable {
text = text.replace('\r', '\n');
}
else if (replacement == INSERT_LF_AFTER_CR) {
- text = text.replaceAll(ILineSeparatorConstants.LINE_SEPARATOR_CR, "\r\n"); //$NON-NLS-1$
+ String separator = ILineSeparatorConstants.LINE_SEPARATOR_CR;
+ String separator2 = ILineSeparatorConstants.LINE_SEPARATOR_LF;
+
+ if (text.indexOf(separator) != -1) {
+ String[] fragments = text.split(separator);
+ StringBuilder b = new StringBuilder();
+ for (int i = 0; i < fragments.length; i++) {
+ String fragment = fragments[i];
+ String nextFragment = i + 1 < fragments.length ? fragments[i + 1] : null;
+ b.append(fragment);
+ if (fragment.endsWith(separator2) || (nextFragment != null && nextFragment.startsWith(separator2))) {
+ // Both separators are found, just add the original separator
+ b.append(separator);
+ } else {
+ b.append("\n\r"); //$NON-NLS-1$
+ }
+ }
+ if (!text.equals(b.toString())) {
+ text = b.toString();
+ }
+ }
}
else if (replacement == REMOVE_CR) {
text = text.replaceAll(ILineSeparatorConstants.LINE_SEPARATOR_CR, ""); //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/OutputStreamMonitor.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/OutputStreamMonitor.java
index 9a17a9e5e..5e2f7c3b1 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/OutputStreamMonitor.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/OutputStreamMonitor.java
@@ -277,14 +277,34 @@ public class OutputStreamMonitor implements IDisposable {
if (lineSeparator != null
&& !ILineSeparatorConstants.LINE_SEPARATOR_CRLF.equals(lineSeparator)) {
String separator = ILineSeparatorConstants.LINE_SEPARATOR_LF.equals(lineSeparator) ? "\n" : "\r"; //$NON-NLS-1$ //$NON-NLS-2$
- if (text.contains(separator)) {
- text = text.replaceAll(separator, "\r\n"); //$NON-NLS-1$
- changed = true;
+ String separator2 = ILineSeparatorConstants.LINE_SEPARATOR_LF.equals(lineSeparator) ? "\r" : "\n"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (text.indexOf(separator) != -1) {
+ String[] fragments = text.split(separator);
+ StringBuilder b = new StringBuilder();
+ for (int i = 0; i < fragments.length; i++) {
+ String fragment = fragments[i];
+ String nextFragment = i + 1 < fragments.length ? fragments[i + 1] : null;
+ b.append(fragment);
+ if (fragment.endsWith(separator2) || (nextFragment != null && nextFragment.startsWith(separator2))) {
+ // Both separators are found, just add the original separator
+ b.append(separator);
+ } else {
+ b.append("\n\r"); //$NON-NLS-1$
+ }
+ }
+ if (!text.equals(b.toString())) {
+ text = b.toString();
+ changed = true;
+ }
}
}
// If changed, get the new bytes array
- if (changed) byteBuffer = text.getBytes();
+ if (changed) {
+ byteBuffer = text.getBytes();
+ bytesRead = byteBuffer.length;
+ }
// If listeners are registered, invoke the listeners now.
if (listeners.size() > 0) {

Back to the top