ASM #16923 - Fix METAR decoder extra whitespace problem

Change-Id: I55ca60148f4079237876c74279ef7cb528eb6c12

Former-commit-id: 18e305efea [formerly c4ce7f8bd1bbf8e971b80f8291f67f5f7af09d46]
Former-commit-id: ebfafc7cbd
This commit is contained in:
Melissa Porricel 2015-04-23 09:03:51 -04:00
parent c6ae0a7f27
commit 5ca1058bc3

View file

@ -85,6 +85,7 @@ import com.vividsolutions.jts.geom.impl.CoordinateArraySequence;
* May 14, 2014 2536 bclement moved WMO Header to common, removed TimeTools usage * May 14, 2014 2536 bclement moved WMO Header to common, removed TimeTools usage
* Jul 23, 2014 3410 bclement location changed to floats * Jul 23, 2014 3410 bclement location changed to floats
* Oct 02, 2014 3693 mapeters Added Pattern constants. * Oct 02, 2014 3693 mapeters Added Pattern constants.
* Apr 22, 2015 DR 16923 MPorricelli Modified cleanMessage to eliminate extra spaces
* *
* </pre> * </pre>
* *
@ -988,7 +989,8 @@ public class MetarDecoder extends AbstractDecoder {
} }
/** /**
* Get rid of any control characters prior to parsing data. * Get rid of any control characters and extraneous spaces
* prior to parsing data.
* *
* @param message * @param message
* @return * @return
@ -998,15 +1000,18 @@ public class MetarDecoder extends AbstractDecoder {
char lastChar = 0; char lastChar = 0;
for (int i = 0; i < message.length(); i++) { for (int i = 0; i < message.length(); i++) {
char c = message.charAt(i); char c = message.charAt(i);
if (c < ' ') { // if current char is a control char or space and prev char is
if (lastChar != c) { // not a space, then add a space to string
if (c <= ' ') {
if (lastChar != ' ') {
sb.append(' '); sb.append(' ');
lastChar = ' ';
} }
} else { } else {
sb.append(c); sb.append(c);
}
lastChar = c; lastChar = c;
} }
}
return sb.toString(); return sb.toString();
} }