Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 225047 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/nls/StringHelper.java (-5 / +27 lines)
Lines 11-34 Link Here
11
package org.eclipse.pde.internal.ui.nls;
11
package org.eclipse.pde.internal.ui.nls;
12
12
13
public class StringHelper {
13
public class StringHelper {
14
	private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
14
15
15
	protected static String preparePropertiesString(String s, char[] newLine) {
16
	public static String preparePropertiesString(String s, char[] newLine) {
16
		if (s == null)
17
		if (s == null)
17
			return null;
18
			return null;
18
		int length = s.length();
19
		int length = s.length();
19
		int nlLength = newLine.length;
20
		int nlLength = newLine.length;
20
		StringBuffer sb = new StringBuffer(length + nlLength);
21
		StringBuffer sb = new StringBuffer(length + nlLength);
21
		for (int i = 0; i < length; i++) {
22
		int i = 0;
23
		while (i < length) {
22
			char c = s.charAt(i);
24
			char c = s.charAt(i);
23
			if (i + nlLength < length) {
25
			if (i + nlLength < length) {
24
				boolean notNewLine = false;
26
				boolean notNewLine = false;
25
				for (int j = 0; j < nlLength; j++)
27
				for (int j = 0; j < nlLength; j++)
26
					if (s.charAt(i + j) != newLine[j])
28
					if (s.charAt(i + j) != newLine[j])
27
						notNewLine = true;
29
						notNewLine = true;
28
				if (!notNewLine)
30
				if (!notNewLine) {
29
					sb.append("\\"); //$NON-NLS-1$
31
					sb.append(unwindEscapeChars(new String(newLine)));
32
					// skip the nl chars
33
					i += nlLength;
34
					while (i < length && s.charAt(i) == ' ') {
35
						sb.append(' ');
36
						i++;
37
					}
38
					if (i < length) {
39
						sb.append("\\"); //$NON-NLS-1$
40
						sb.append(newLine);
41
					}
42
					continue;
43
				}
30
			}
44
			}
31
			sb.append(c);
45
			sb.append(unwindEscapeChars(Character.toString(c)));
46
			i++;
32
		}
47
		}
33
		return sb.toString();
48
		return sb.toString();
34
	}
49
	}
Lines 60-69 Link Here
60
				return "\\r";//$NON-NLS-1$
75
				return "\\r";//$NON-NLS-1$
61
			case '\\' :
76
			case '\\' :
62
				return "\\\\";//$NON-NLS-1$
77
				return "\\\\";//$NON-NLS-1$
78
			default :
79
				if (((c < 0x0020) || (c > 0x007e)))
80
					return new StringBuffer().append('\\').append('u').append(toHex((c >> 12) & 0xF)).append(toHex((c >> 8) & 0xF)).append(toHex((c >> 4) & 0xF)).append(toHex(c & 0xF)).toString();
63
		}
81
		}
64
		return String.valueOf(c);
82
		return String.valueOf(c);
65
	}
83
	}
66
84
85
	private static char toHex(int halfByte) {
86
		return HEX_DIGITS[(halfByte & 0xF)];
87
	}
88
67
	protected static String windEscapeChars(String s) {
89
	protected static String windEscapeChars(String s) {
68
		if (s == null)
90
		if (s == null)
69
			return null;
91
			return null;

Return to bug 225047