Skip to content

Commit 4c231c5

Browse files
[import-parse.cpp] convert to cpp
1 parent 96707e5 commit 4c231c5

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

gnucash/import-export/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set (generic_import_SOURCES
1919
import-backend.cpp
2020
import-format-dialog.cpp
2121
import-match-picker.cpp
22-
import-parse.c
22+
import-parse.cpp
2323
import-utilities.cpp
2424
import-settings.cpp
2525
import-main-matcher.cpp

gnucash/import-export/import-parse.c renamed to gnucash/import-export/import-parse.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static regex_t date_ymd_regex;
5353

5454
static gboolean regex_compiled = FALSE;
5555

56+
/* Set and clear flags in bit-flags */
57+
#define import_set_flag(i,f) (i = static_cast<GncImportFormat>(static_cast<int>(i) | static_cast<int>(f)))
58+
#define import_clear_flag(i,f) (i = static_cast<GncImportFormat>(static_cast<int>(i) & static_cast<int>(~f)))
59+
5660
static void
5761
compile_regex(void)
5862
{
@@ -104,7 +108,7 @@ my_strntol(const char *str, int len)
104108
static GncImportFormat
105109
check_date_format(const char * str, regmatch_t *match, GncImportFormat fmts)
106110
{
107-
GncImportFormat res = 0;
111+
GncImportFormat res = GNCIF_NONE;
108112
int len0 = 0, len1 = 0, len2 = 0;
109113
int val0 = 0, val1 = 0, val2 = 0;
110114

@@ -179,18 +183,18 @@ check_date_format(const char * str, regmatch_t *match, GncImportFormat fmts)
179183
GncImportFormat
180184
gnc_import_test_numeric(const char* str, GncImportFormat fmts)
181185
{
182-
GncImportFormat res = 0;
186+
GncImportFormat res = GNCIF_NONE;
183187

184188
g_return_val_if_fail(str, fmts);
185189

186190
if (!regex_compiled)
187191
compile_regex();
188192

189193
if ((fmts & GNCIF_NUM_PERIOD) && !regexec(&decimal_radix_regex, str, 0, NULL, 0))
190-
res |= GNCIF_NUM_PERIOD;
194+
import_set_flag (res, GNCIF_NUM_PERIOD);
191195

192196
if ((fmts & GNCIF_NUM_COMMA) && !regexec(&comma_radix_regex, str, 0, NULL, 0))
193-
res |= GNCIF_NUM_COMMA;
197+
import_set_flag (res, GNCIF_NUM_COMMA);
194198

195199
return res;
196200
}
@@ -200,7 +204,7 @@ GncImportFormat
200204
gnc_import_test_date(const char* str, GncImportFormat fmts)
201205
{
202206
regmatch_t match[5];
203-
GncImportFormat res = 0;
207+
GncImportFormat res = GNCIF_NONE;
204208

205209
g_return_val_if_fail(str, fmts);
206210
g_return_val_if_fail(strlen(str) > 1, fmts);
@@ -218,23 +222,24 @@ gnc_import_test_date(const char* str, GncImportFormat fmts)
218222
* let's try both ways and let the parser check that YYYY is
219223
* valid.
220224
*/
221-
char temp[9];
225+
#define DATE_LEN 8
226+
char temp[DATE_LEN + 1];
222227

223228
g_return_val_if_fail(match[4].rm_so != -1, fmts);
224-
g_return_val_if_fail(match[4].rm_eo - match[4].rm_so == 8, fmts);
229+
g_return_val_if_fail(match[4].rm_eo - match[4].rm_so == DATE_LEN, fmts);
225230

226231
/* make a temp copy of the XXXXXXXX string */
227-
strncpy(temp, str + match[4].rm_so, 8);
228-
temp[8] = '\0';
232+
strncpy(temp, str + match[4].rm_so, DATE_LEN);
233+
temp[DATE_LEN] = '\0';
229234

230235
/* then check it against the ymd or mdy formats, as necessary */
231236
if (((fmts & GNCIF_DATE_YDM) || (fmts & GNCIF_DATE_YMD)) &&
232237
!regexec(&date_ymd_regex, temp, 4, match, 0))
233-
res |= check_date_format(temp, match, fmts);
238+
import_set_flag (res, check_date_format (temp, match, fmts));
234239

235240
if (((fmts & GNCIF_DATE_DMY) || (fmts & GNCIF_DATE_MDY)) &&
236241
!regexec(&date_mdy_regex, temp, 4, match, 0))
237-
res |= check_date_format(temp, match, fmts);
242+
import_set_flag (res, check_date_format (temp, match, fmts));
238243
}
239244
}
240245

gnucash/import-export/import-parse.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#ifndef IMPORT_PARSE_H
2828
#define IMPORT_PARSE_H
2929

30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
3034
#include "qof.h"
3135

3236
typedef enum
@@ -57,9 +61,9 @@ gboolean gnc_import_parse_numeric(const char* str, GncImportFormat fmt,
5761
gboolean gnc_import_parse_date(const char *date, GncImportFormat fmt,
5862
time64 *val);
5963

60-
/* Set and clear flags in bit-flags */
61-
#define import_set_flag(i,f) (i |= f)
62-
#define import_clear_flag(i,f) (i &= ~f)
6364

65+
#ifdef __cplusplus
66+
}
67+
#endif
6468

6569
#endif /* IMPORT_PARSE_H */

po/POTFILES.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ gnucash/import-export/import-commodity-matcher.cpp
352352
gnucash/import-export/import-format-dialog.cpp
353353
gnucash/import-export/import-main-matcher.cpp
354354
gnucash/import-export/import-match-picker.cpp
355-
gnucash/import-export/import-parse.c
355+
gnucash/import-export/import-parse.cpp
356356
gnucash/import-export/import-pending-matches.cpp
357357
gnucash/import-export/import-settings.cpp
358358
gnucash/import-export/import-utilities.cpp

0 commit comments

Comments
 (0)