From 80595fe5fa14844e3c37d0fe665c33e5949a8699 Mon Sep 17 00:00:00 2001 From: gambas Date: Tue, 7 Aug 2018 13:39:18 +0200 Subject: [PATCH] Finish fixing thousand separator bug. [INTERPRETER] * BUG: Finish fixing thousand separator bug. --- main/gbx/gbx_number.c | 17 ++++++++++++----- main/share/gb_common_buffer.h | 3 ++- main/share/gb_common_buffer_temp.h | 14 +++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/main/gbx/gbx_number.c b/main/gbx/gbx_number.c index 3c22ae554..7bf04edbf 100644 --- a/main/gbx/gbx_number.c +++ b/main/gbx/gbx_number.c @@ -47,6 +47,7 @@ #define get_current COMMON_get_current #define buffer_pos COMMON_pos #define get_size_left COMMON_get_size_left +#define has_string COMMON_has_string #define IS_PURE_INTEGER(_int64_val) ((_int64_val) == ((int)(_int64_val))) @@ -54,11 +55,13 @@ static bool read_integer(int base, bool minus, int64_t *result, bool local) { uint64_t nbr2, nbr; int d, n, c, nmax; - char thsep; + const char *thsep; + int lthsep; int ndigit_thsep; bool first_thsep; thsep = LOCAL_get(local)->thousand_sep; + lthsep = LOCAL_get(local)->len_thousand_sep; ndigit_thsep = 0; first_thsep = FALSE; @@ -81,8 +84,9 @@ static bool read_integer(int base, bool minus, int64_t *result, bool local) { if (local) { - if (c == thsep && (ndigit_thsep == 3 || (!first_thsep && ndigit_thsep >= 1 && ndigit_thsep <= 3))) + if (has_string(thsep, lthsep) && (ndigit_thsep == 3 || (!first_thsep && ndigit_thsep >= 1 && ndigit_thsep <= 3))) { + COMMON_pos += lthsep; c = get_char(); first_thsep = TRUE; ndigit_thsep = 0; @@ -184,7 +188,8 @@ static bool read_float(double *result, bool local) { LOCAL_INFO *local_info; char point; - char thsep; + const char *thsep; + int lthsep; int ndigit_thsep; bool first_thsep; int c, n; @@ -201,6 +206,7 @@ static bool read_float(double *result, bool local) local_info = LOCAL_get(local); point = local_info->decimal_point; thsep = local_info->thousand_sep; + lthsep = local_info->len_thousand_sep; ndigit_thsep = 0; first_thsep = FALSE; @@ -231,11 +237,12 @@ static bool read_float(double *result, bool local) if (local && !frac) { - if (c == thsep && (ndigit_thsep == 3 || (!first_thsep && ndigit_thsep >= 1 && ndigit_thsep <= 3))) + if (has_string(thsep, lthsep) && (ndigit_thsep == 3 || (!first_thsep && ndigit_thsep >= 1 && ndigit_thsep <= 3))) { - c = get_char(); + COMMON_pos += lthsep; first_thsep = TRUE; ndigit_thsep = 0; + c = get_char(); } } diff --git a/main/share/gb_common_buffer.h b/main/share/gb_common_buffer.h index af26d8dc2..6d6fc6e93 100644 --- a/main/share/gb_common_buffer.h +++ b/main/share/gb_common_buffer.h @@ -24,7 +24,7 @@ #ifndef __GB_COMMON_BUFFER_H #define __GB_COMMON_BUFFER_H -#define COMMON_BUF_MAX 256 +#define COMMON_BUF_MAX 512 #ifndef __COMMON_BUFFER_C EXTERN int COMMON_pos; @@ -42,4 +42,5 @@ int COMMON_put_char(char c); void COMMON_jump_space(void); char *COMMON_get_current(void); int COMMON_get_size_left(void); +bool COMMON_has_string(const char *str, int len); #endif diff --git a/main/share/gb_common_buffer_temp.h b/main/share/gb_common_buffer_temp.h index d617abf2a..aa4a7bbeb 100644 --- a/main/share/gb_common_buffer_temp.h +++ b/main/share/gb_common_buffer_temp.h @@ -24,17 +24,18 @@ #define __COMMON_BUFFER_C #include "gb_common.h" +#include "gb_common_buffer.h" -char COMMON_buffer[256]; +char COMMON_buffer[COMMON_BUF_MAX]; int COMMON_pos; int COMMON_len; static char *common_buffer; static int common_last; -void COMMON_buffer_init(char *str, int len) +void COMMON_buffer_init(const char *str, int len) { - common_buffer = str; + common_buffer = (char *)str; COMMON_len = len; COMMON_pos = 0; common_last = (-1); @@ -103,3 +104,10 @@ int COMMON_get_size_left(void) } +bool COMMON_has_string(const char *str, int len) +{ + if (COMMON_get_size_left() > len) + return FALSE; + + return memcmp(&common_buffer[COMMON_pos], str, len) == 0; +}