From d1c86c84cfe21260cf622cdb3c1ef3cf6673ca78 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 11 Jan 2023 23:06:27 +0100 Subject: [PATCH] fix: allow to use a minus sign in strings with FT::numeric flag --- src/baseexpression.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/baseexpression.h b/src/baseexpression.h index 3952dce..b8043da 100644 --- a/src/baseexpression.h +++ b/src/baseexpression.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2022, Tomasz Sowa + * Copyright (c) 2018-2023, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -795,6 +795,7 @@ protected: { bool was_comma = false; bool was_something_printed = false; + bool was_digit_printed = false; for(size_t i = 0 ; has_known_length ? (i < len) : val[i] != 0 ; ++i) { @@ -803,17 +804,30 @@ protected: if( c == ',' ) c = '.'; - if( (c=='.' && !was_comma) || (c>='0' && c<='9') ) + if( (c=='.' && !was_comma) || (c>='0' && c<='9') || (c=='-' && !was_something_printed) ) { + if( c=='.' ) + { + if( !was_digit_printed ) + { + esc(static_cast('0'), stream, field_type, model_env); + was_digit_printed = true; + } + + was_comma = true; + } + esc(c, stream, field_type, model_env); was_something_printed = true; - if( c == '.' ) - was_comma = true; + if( c>='0' && c<='9' ) + { + was_digit_printed = true; + } } } - if( !was_something_printed ) + if( !was_digit_printed ) { esc(static_cast('0'), stream, field_type, model_env); }