blob: 7eabad5f41a261204aeb8ca135c327b41b35c927 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.mi.core.output;
/**
* GDB/MI const value represents a ios-c string.
*/
public class MIConst extends MIValue {
String cstring = ""; //$NON-NLS-1$
public String getCString() {
return cstring;
}
public void setCString(String str) {
cstring = str;
}
/**
* Translate gdb c-string.
*/
public String getString() {
return getString(cstring);
}
public static String getString(String str) {
StringBuffer buffer = new StringBuffer();
boolean escape = false;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '\\') {
if (escape) {
buffer.append(c);
escape = false;
} else {
escape = true;
}
} else {
if (escape) {
buffer.append(isoC(c));
} else {
buffer.append(c);
}
escape = false;
}
}
// If escape is still true it means that the
// last char was an '\'.
if (escape) {
buffer.append('\\');
}
return buffer.toString();
}
public String toString() {
return getCString();
}
/**
* Assuming that the precedent character was the
* escape sequence '\'
*/
private static String isoC(char c) {
String s = new Character(c).toString();
if (c == '"') {
s = "\""; //$NON-NLS-1$
} else if (c == '\'') {
s = "\'"; //$NON-NLS-1$
} else if (c == '?') {
s = "?"; //$NON-NLS-1$
} else if (c == 'a') {
s = "\007"; //$NON-NLS-1$
} else if (c == 'b') {
s = "\b"; //$NON-NLS-1$
} else if (c == 'f') {
s = "\f"; //$NON-NLS-1$
} else if (c == 'n') {
s = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ $NON-NLS-2$
} else if (c == 'r') {
s = "\r"; //$NON-NLS-1$
} else if (c == 't') {
s = "\t"; //$NON-NLS-1$
} else if (c == 'v') {
s = "\013"; //$NON-NLS-1$
}
return s;
}
}
|