changeset 12363:30062c102c94 octave-forge

ignore column delimiters after row delimiters - this avoids generating an empty column when the row starts with a column delimiter (e.g. space or <TAB>)
author schloegl
date Tue, 11 Feb 2014 08:19:32 +0000
parents 61b5829ba23e
children b504f9b83371
files extra/NaN/src/str2array.cpp
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/src/str2array.cpp	Mon Feb 10 18:59:41 2014 +0000
+++ b/extra/NaN/src/str2array.cpp	Tue Feb 11 08:19:32 2014 +0000
@@ -34,7 +34,7 @@
 //
 // Output:
 //    $Id: STR2ARRAY.cpp 7142 2010-03-30 18:48:06Z schloegl $
-//    Copyright (C) 2010,2011 Alois Schloegl <alois.schloegl@gmail.com>
+//    Copyright (C) 2010,2011,2014 Alois Schloegl <alois.schloegl@gmail.com>
 //    This function is part of the NaN-toolbox
 //    http://pub.ist.ac.at/~schloegl/matlab/NaN/
 //
@@ -249,15 +249,27 @@
 
 	/* identify separators */
 	u = (uint8_t*) mxCalloc(1,slen+1);
+	int flag_newline;
 	for (k = 0; k < slen; ) {
 		if (strchr(cdelim,s[k]) != NULL) {
-			u[k] = 1;      // column delimiter
-			while (s[++k]==' ');    // ignore extra space characters
+			if (flag_newline) {
+				// ignore field delimiters after newline
+				s[k]==' ';
+				k++;
+			}
+			else {
+				u[k] = 1;      // column delimiter
+				while (s[++k]==' ');    // ignore extra space characters
+			}
 		}	
-		else if (strchr(rdelim,s[k]) != NULL)
+		else if (strchr(rdelim,s[k]) != NULL) {
 			u[k++] = 2;    // row delimiter
-		else 
+			flag_newline = 1; 
+		}
+		else {
 			k++; 	       // ordinary character 
+			flag_newline = 0; 
+		}
 	}
 
 	/* count dimensions and set delimiter elements to 0 */