csv: strip outer whitespace when interpolating CSV values (#1051)
This removes a potential snag in amount field assignments, and hopefully is harmless and acceptable otherwise.
This commit is contained in:
		
							parent
							
								
									d2b3185062
								
							
						
					
					
						commit
						0a3af8d9ee
					
				| @ -850,10 +850,12 @@ getEffectiveAssignment rules record f = lastMay $ assignmentsFor f | |||||||
|                       where |                       where | ||||||
|                         csvline = intercalate "," record |                         csvline = intercalate "," record | ||||||
| 
 | 
 | ||||||
|  | -- | Render a field assigment's template, possibly interpolating referenced | ||||||
|  | -- CSV field values. Outer whitespace is removed from interpolated values. | ||||||
| renderTemplate ::  CsvRules -> CsvRecord -> FieldTemplate -> String | renderTemplate ::  CsvRules -> CsvRecord -> FieldTemplate -> String | ||||||
| renderTemplate rules record t = regexReplaceBy "%[A-z0-9]+" replace t | renderTemplate rules record t = regexReplaceBy "%[A-z0-9]+" replace t | ||||||
|   where |   where | ||||||
|     replace ('%':pat) = maybe pat (\i -> atDef "" record (i-1)) mindex |     replace ('%':pat) = maybe pat (\i -> strip $ atDef "" record (i-1)) mindex | ||||||
|       where |       where | ||||||
|         mindex | all isDigit pat = readMay pat |         mindex | all isDigit pat = readMay pat | ||||||
|                | otherwise       = lookup (map toLower pat) $ rcsvfieldindexes rules |                | otherwise       = lookup (map toLower pat) $ rcsvfieldindexes rules | ||||||
|  | |||||||
| @ -161,8 +161,12 @@ amount USD %4 | |||||||
| # combine three fields to make a comment (containing two tags) | # combine three fields to make a comment (containing two tags) | ||||||
| comment note: %somefield - %anotherfield, date: %1 | comment note: %somefield - %anotherfield, date: %1 | ||||||
| ``` | ``` | ||||||
|  | 
 | ||||||
| Field assignments can be used instead of or in addition to a field list. | Field assignments can be used instead of or in addition to a field list. | ||||||
| 
 | 
 | ||||||
|  | Note, interpolation strips any outer whitespace, so a CSV value like | ||||||
|  | `" 1 "` becomes `1` when interpolated. | ||||||
|  | 
 | ||||||
| ## conditional block | ## conditional block | ||||||
| 
 | 
 | ||||||
| `if` *`PATTERN`*\ | `if` *`PATTERN`*\ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user