[import-parse.cpp] convert to cpp

This commit is contained in:
Christopher Lam 2023-07-14 15:52:13 +08:00
parent 96707e5eee
commit 4c231c5c35
4 changed files with 25 additions and 16 deletions

View File

@ -19,7 +19,7 @@ set (generic_import_SOURCES
import-backend.cpp
import-format-dialog.cpp
import-match-picker.cpp
import-parse.c
import-parse.cpp
import-utilities.cpp
import-settings.cpp
import-main-matcher.cpp

View File

@ -53,6 +53,10 @@ static regex_t date_ymd_regex;
static gboolean regex_compiled = FALSE;
/* Set and clear flags in bit-flags */
#define import_set_flag(i,f) (i = static_cast<GncImportFormat>(static_cast<int>(i) | static_cast<int>(f)))
#define import_clear_flag(i,f) (i = static_cast<GncImportFormat>(static_cast<int>(i) & static_cast<int>(~f)))
static void
compile_regex(void)
{
@ -104,7 +108,7 @@ my_strntol(const char *str, int len)
static GncImportFormat
check_date_format(const char * str, regmatch_t *match, GncImportFormat fmts)
{
GncImportFormat res = 0;
GncImportFormat res = GNCIF_NONE;
int len0 = 0, len1 = 0, len2 = 0;
int val0 = 0, val1 = 0, val2 = 0;
@ -179,7 +183,7 @@ check_date_format(const char * str, regmatch_t *match, GncImportFormat fmts)
GncImportFormat
gnc_import_test_numeric(const char* str, GncImportFormat fmts)
{
GncImportFormat res = 0;
GncImportFormat res = GNCIF_NONE;
g_return_val_if_fail(str, fmts);
@ -187,10 +191,10 @@ gnc_import_test_numeric(const char* str, GncImportFormat fmts)
compile_regex();
if ((fmts & GNCIF_NUM_PERIOD) && !regexec(&decimal_radix_regex, str, 0, NULL, 0))
res |= GNCIF_NUM_PERIOD;
import_set_flag (res, GNCIF_NUM_PERIOD);
if ((fmts & GNCIF_NUM_COMMA) && !regexec(&comma_radix_regex, str, 0, NULL, 0))
res |= GNCIF_NUM_COMMA;
import_set_flag (res, GNCIF_NUM_COMMA);
return res;
}
@ -200,7 +204,7 @@ GncImportFormat
gnc_import_test_date(const char* str, GncImportFormat fmts)
{
regmatch_t match[5];
GncImportFormat res = 0;
GncImportFormat res = GNCIF_NONE;
g_return_val_if_fail(str, fmts);
g_return_val_if_fail(strlen(str) > 1, fmts);
@ -218,23 +222,24 @@ gnc_import_test_date(const char* str, GncImportFormat fmts)
* let's try both ways and let the parser check that YYYY is
* valid.
*/
char temp[9];
#define DATE_LEN 8
char temp[DATE_LEN + 1];
g_return_val_if_fail(match[4].rm_so != -1, fmts);
g_return_val_if_fail(match[4].rm_eo - match[4].rm_so == 8, fmts);
g_return_val_if_fail(match[4].rm_eo - match[4].rm_so == DATE_LEN, fmts);
/* make a temp copy of the XXXXXXXX string */
strncpy(temp, str + match[4].rm_so, 8);
temp[8] = '\0';
strncpy(temp, str + match[4].rm_so, DATE_LEN);
temp[DATE_LEN] = '\0';
/* then check it against the ymd or mdy formats, as necessary */
if (((fmts & GNCIF_DATE_YDM) || (fmts & GNCIF_DATE_YMD)) &&
!regexec(&date_ymd_regex, temp, 4, match, 0))
res |= check_date_format(temp, match, fmts);
import_set_flag (res, check_date_format (temp, match, fmts));
if (((fmts & GNCIF_DATE_DMY) || (fmts & GNCIF_DATE_MDY)) &&
!regexec(&date_mdy_regex, temp, 4, match, 0))
res |= check_date_format(temp, match, fmts);
import_set_flag (res, check_date_format (temp, match, fmts));
}
}

View File

@ -27,6 +27,10 @@
#ifndef IMPORT_PARSE_H
#define IMPORT_PARSE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "qof.h"
typedef enum
@ -57,9 +61,9 @@ gboolean gnc_import_parse_numeric(const char* str, GncImportFormat fmt,
gboolean gnc_import_parse_date(const char *date, GncImportFormat fmt,
time64 *val);
/* Set and clear flags in bit-flags */
#define import_set_flag(i,f) (i |= f)
#define import_clear_flag(i,f) (i &= ~f)
#ifdef __cplusplus
}
#endif
#endif /* IMPORT_PARSE_H */

View File

@ -352,7 +352,7 @@ gnucash/import-export/import-commodity-matcher.cpp
gnucash/import-export/import-format-dialog.cpp
gnucash/import-export/import-main-matcher.cpp
gnucash/import-export/import-match-picker.cpp
gnucash/import-export/import-parse.c
gnucash/import-export/import-parse.cpp
gnucash/import-export/import-pending-matches.cpp
gnucash/import-export/import-settings.cpp
gnucash/import-export/import-utilities.cpp