Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2015-02-09 14:08:40 -0500
committerPatrick Tasse2015-02-16 11:04:31 -0500
commit5a86cf1d82b3139070ea874d606d7015218b990b (patch)
tree3f17733506c4f0bae5652e072760bb16a47ca1a0
parent6d03bf29322f1ceed7ccba7529d1aab60d6bd0c4 (diff)
downloadorg.eclipse.linuxtools-5a86cf1d82b3139070ea874d606d7015218b990b.tar.gz
org.eclipse.linuxtools-5a86cf1d82b3139070ea874d606d7015218b990b.tar.xz
org.eclipse.linuxtools-5a86cf1d82b3139070ea874d606d7015218b990b.zip
tmf: Bug 459493: TmfTimestampFormat doesn't parse extra spaces correctlyv3.2.0
Change-Id: I83db317b35e126c306e2fb60be9e0de17dccfc6d Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/41460 Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Tested-by: Hudson CI (cherry picked from commit 60d43eda697c100eab9444f137ae90093cabe889) Reviewed-on: https://git.eclipse.org/r/41859
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java26
2 files changed, 30 insertions, 8 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java
index 925b7c5105..94b08c6561 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
@@ -206,7 +206,6 @@ public class TmfTimestampFormatTest {
*/
@Test
public void testParseDateTime() throws ParseException {
-// long ref = tsf.parseValue("2014-11-22 12:34:56.123456789"); // Saturday
long time;
time = new TmfTimestampFormat("yyyy", GMT, CA).parseValue("2014");
@@ -316,6 +315,15 @@ public class TmfTimestampFormatTest {
time = new TmfTimestampFormat("yyyy\"MM\"dd\"HH\"mm\"ss\"SSS\"SSS\"SSS", GMT, CA).parseValue("2014\"11\"22\"12\"34\"56\"123\"456\"789");
assertEquals("2014-11-22 12:34:56.123456789", tsf.format(time));
+
+ time = new TmfTimestampFormat("yyyy MM dd HH mm ss SSS SSS SSS", GMT, CA).parseValue("2014 11 22 12 34 56 123 456 789");
+ assertEquals("2014-11-22 12:34:56.123456789", tsf.format(time));
+
+ time = new TmfTimestampFormat("yyyy MM dd HH mm ss SSS SSS SSS", GMT, CA).parseValue("2014 1 2 3 4 5 123 456 789");
+ assertEquals("2014-01-02 03:04:05.123456789", tsf.format(time));
+
+ time = new TmfTimestampFormat("yyyy MM dd HH mm ss SSS SSS SSS", GMT, CA).parseValue("2014 \t 1 \t 2 \t 3 \t 4 \t 5 \t 123 456 789");
+ assertEquals("2014-01-02 03:04:05.123456789", tsf.format(time));
}
/**
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java
index e682409a26..970ce9dbf7 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
+ * Copyright (c) 2012, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
@@ -614,13 +614,27 @@ public class TmfTimestampFormat extends SimpleDateFormat {
* Returns the source string length if decimal separator is not found.
*/
private int indexOfSourceDecimalSeparator(String source) {
- String pattern = fPattern.substring(0, fPatternDecimalSeparatorIndex);
String separator = fDecimalSeparator == '\'' ? "''" : String.valueOf(fDecimalSeparator); //$NON-NLS-1$
- int sourcePos = source.indexOf(fDecimalSeparator);
- int patternPos = pattern.indexOf(separator);
- while (patternPos != -1 && sourcePos != -1) {
+ int patternPos = fPattern.indexOf(separator);
+ int sourcePos = -1;
+ while (patternPos != -1 && patternPos <= fPatternDecimalSeparatorIndex) {
sourcePos = source.indexOf(fDecimalSeparator, sourcePos + 1);
- patternPos = pattern.indexOf(separator, patternPos + separator.length());
+ if (sourcePos == -1) {
+ break;
+ }
+ // skip optional spaces and tabs before a pattern letter
+ char p = patternPos < fPattern.length() - 1 ? fPattern.charAt(patternPos + 1) : '\0';
+ if ((p >= 'a' && p <= 'z') || (p >= 'A' && p <= 'Z')) {
+ while (sourcePos < source.length() - 1) {
+ char s = source.charAt(sourcePos + 1);
+ if (s == ' ' || s == '\t') {
+ sourcePos++;
+ } else {
+ break;
+ }
+ }
+ }
+ patternPos = fPattern.indexOf(separator, patternPos + separator.length());
}
if (sourcePos == -1) {
sourcePos = source.length();

Back to the top