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 356085 | Differences between
and this patch

Collapse All | Expand All

(-)MIParser.java (-28 / +38 lines)
Lines 105-143 Link Here
105
		MIOutput mi = new MIOutput();
105
		MIOutput mi = new MIOutput();
106
		MIResultRecord rr = null;
106
		MIResultRecord rr = null;
107
		List oobs = new ArrayList(1);
107
		List oobs = new ArrayList(1);
108
		int id = -1;
109
108
110
		StringTokenizer st = new StringTokenizer(buffer, "\n"); //$NON-NLS-1$
109
		StringTokenizer st = new StringTokenizer(buffer, "\n"); //$NON-NLS-1$
111
		while (st.hasMoreTokens()) {
110
		while (st.hasMoreTokens()) {
112
			StringBuffer token = new StringBuffer(st.nextToken());
111
			StringBuffer token = new StringBuffer(st.nextToken());
112
			int i = 0;
113
113
114
			// Fetch the Token/Id
114
			// Fetch the Token/Id
115
			if (token.length() > 0 && Character.isDigit(token.charAt(0))) {
115
			if (token.length() > 0 && Character.isDigit(token.charAt(0))) {
116
				int i = 1;
116
				i = 1;
117
				while (i < token.length() && Character.isDigit(token.charAt(i))) {
117
				while (i < token.length() && Character.isDigit(token.charAt(i))) {
118
					i++;
118
					i++;
119
				}
119
				}
120
				String numbers = token.substring(0, i);
121
				try {
122
					id = Integer.parseInt(numbers);
123
				} catch (NumberFormatException e) {
124
				}
125
				// Consume the token.
126
				token.delete(0, i);
127
			}
120
			}
128
121
129
			// ResultRecord ||| Out-Of-Band Records
122
			// ResultRecord ||| Out-Of-Band Records
130
			if (token.length() > 0) {
123
			if (i < token.length() && token.charAt(i) == '^') {
131
				if (token.charAt(0) == '^') {
124
				rr = processMIResultRecord(token);
132
					token.deleteCharAt(0);
125
			} else if (!token.toString().startsWith(primaryPrompt, i)) {
133
					rr = processMIResultRecord(token, id);
126
				MIOOBRecord band = processMIOOBRecord(token);
134
				} else if (startsWith(token, primaryPrompt)) {
127
				if (band != null) {
135
					//break; // Do nothing.
128
					oobs.add(band);
136
				} else {
137
					MIOOBRecord band = processMIOOBRecord(token, id);
138
					if (band != null) {
139
						oobs.add(band);
140
					}
141
				}
129
				}
142
			}
130
			}
143
		}
131
		}
Lines 147-156 Link Here
147
		return mi;
135
		return mi;
148
	}
136
	}
149
137
150
	/**
138
	private int parseToken(StringBuffer buffer) {
151
	 * Assuming '^' was deleted from the Result Record.
139
		int id = -1;
152
	 */
140
		// Fetch the Token/Id
153
	private MIResultRecord processMIResultRecord(StringBuffer buffer, int id) {
141
		if (Character.isDigit(buffer.charAt(0))) {
142
			int i = 1;
143
			while (i < buffer.length() && Character.isDigit(buffer.charAt(i))) {
144
				i++;
145
			}
146
			String numbers = buffer.substring(0, i);
147
			try {
148
				id = Integer.parseInt(numbers);
149
			} catch (NumberFormatException e) {
150
			}
151
			// Consume the token.
152
			buffer.delete(0, i);
153
		}
154
		return id;
155
	}
156
157
	private MIResultRecord processMIResultRecord(StringBuffer buffer) {
158
		// Fetch the Token/Id
159
		int id = parseToken(buffer);
160
		// Consume the '^'
161
		buffer.deleteCharAt(0);
162
154
		MIResultRecord rr = new MIResultRecord();
163
		MIResultRecord rr = new MIResultRecord();
155
		rr.setToken(id);
164
		rr.setToken(id);
156
		if (buffer.toString().startsWith(MIResultRecord.DONE)) {
165
		if (buffer.toString().startsWith(MIResultRecord.DONE)) {
Lines 185-193 Link Here
185
	/**
194
	/**
186
	 * Find OutOfBand Records depending on the starting token.
195
	 * Find OutOfBand Records depending on the starting token.
187
	 */
196
	 */
188
	private MIOOBRecord processMIOOBRecord(StringBuffer buffer, int id) {
197
	private MIOOBRecord processMIOOBRecord(StringBuffer buffer) {
198
		String line = buffer.toString();
199
		int id = parseToken(buffer);
189
		MIOOBRecord oob = null;
200
		MIOOBRecord oob = null;
190
		char c = buffer.charAt(0);
201
		char c = buffer.length() != 0 ? buffer.charAt(0) : 0;
191
		if (c == '*' || c == '+' || c == '=') {
202
		if (c == '*' || c == '+' || c == '=') {
192
			// Consume the first char
203
			// Consume the first char
193
			buffer.deleteCharAt(0);
204
			buffer.deleteCharAt(0);
Lines 242-251 Link Here
242
		} else {
253
		} else {
243
			// Badly format MI line, just pass it to the user as target stream
254
			// Badly format MI line, just pass it to the user as target stream
244
			MIStreamRecord stream = new MITargetStreamOutput();
255
			MIStreamRecord stream = new MITargetStreamOutput();
245
			String res = buffer.toString();
246
			// this awfull expression just mean to replace \ with \\. This is needed because otherwise escaping is lost.
256
			// this awfull expression just mean to replace \ with \\. This is needed because otherwise escaping is lost.
247
			// this is to fix bug 255946 without breaking other stuff 286785
257
			// this is to fix bug 255946 without breaking other stuff 286785
248
			res = res.replaceAll("\\Q\\", "\\\\\\\\");  //$NON-NLS-1$//$NON-NLS-2$
258
			String res = line.replaceAll("\\Q\\", "\\\\\\\\");  //$NON-NLS-1$//$NON-NLS-2$
249
			stream.setCString(res + "\n"); //$NON-NLS-1$
259
			stream.setCString(res + "\n"); //$NON-NLS-1$
250
			oob = stream;
260
			oob = stream;
251
		}
261
		}

Return to bug 356085