mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: turn extra_data key/value pair in parser to std::string
Less troublesome memory management. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
92a1a08b21
commit
e6321a1305
3 changed files with 7 additions and 11 deletions
|
@ -278,17 +278,15 @@ static void depth(const char *buffer, depth_t *depth, struct parser_state *state
|
||||||
|
|
||||||
static void extra_data_start(struct parser_state *state)
|
static void extra_data_start(struct parser_state *state)
|
||||||
{
|
{
|
||||||
memset(&state->cur_extra_data, 0, sizeof(struct extra_data));
|
state->cur_extra_data.key.clear();
|
||||||
|
state->cur_extra_data.value.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extra_data_end(struct parser_state *state)
|
static void extra_data_end(struct parser_state *state)
|
||||||
{
|
{
|
||||||
// don't save partial structures - we must have both key and value
|
// don't save partial structures - we must have both key and value
|
||||||
if (state->cur_extra_data.key && state->cur_extra_data.value)
|
if (!state->cur_extra_data.key.empty() && !state->cur_extra_data.value.empty())
|
||||||
add_extra_data(get_dc(state), state->cur_extra_data.key, state->cur_extra_data.value);
|
add_extra_data(get_dc(state), state->cur_extra_data.key.c_str(), state->cur_extra_data.value.c_str());
|
||||||
free((void *)state->cur_extra_data.key);
|
|
||||||
free((void *)state->cur_extra_data.value);
|
|
||||||
state->cur_extra_data.key = state->cur_extra_data.value = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void weight(const char *buffer, weight_t *weight, struct parser_state *state)
|
static void weight(const char *buffer, weight_t *weight, struct parser_state *state)
|
||||||
|
@ -829,9 +827,9 @@ static int match_dc_data_fields(struct divecomputer *dc, const char *name, char
|
||||||
return 1;
|
return 1;
|
||||||
if (MATCH("salinity.water", salinity, &dc->salinity))
|
if (MATCH("salinity.water", salinity, &dc->salinity))
|
||||||
return 1;
|
return 1;
|
||||||
if (MATCH("key.extradata", utf8_string, (char **)&state->cur_extra_data.key))
|
if (MATCH("key.extradata", utf8_string_std, &state->cur_extra_data.key))
|
||||||
return 1;
|
return 1;
|
||||||
if (MATCH("value.extradata", utf8_string, (char **)&state->cur_extra_data.value))
|
if (MATCH("value.extradata", utf8_string_std, &state->cur_extra_data.value))
|
||||||
return 1;
|
return 1;
|
||||||
if (MATCH("divemode", get_dc_type, &dc->divemode))
|
if (MATCH("divemode", get_dc_type, &dc->divemode))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -24,8 +24,6 @@ parser_state::~parser_state()
|
||||||
free_dive(cur_dive);
|
free_dive(cur_dive);
|
||||||
free_trip(cur_trip);
|
free_trip(cur_trip);
|
||||||
free_dive_site(cur_dive_site);
|
free_dive_site(cur_dive_site);
|
||||||
free((void *)cur_extra_data.key);
|
|
||||||
free((void *)cur_extra_data.value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -88,7 +88,7 @@ struct parser_state {
|
||||||
int lastcylinderindex = 0, next_o2_sensor = 0;
|
int lastcylinderindex = 0, next_o2_sensor = 0;
|
||||||
int o2pressure_sensor = 0;
|
int o2pressure_sensor = 0;
|
||||||
int sample_rate = 0;
|
int sample_rate = 0;
|
||||||
struct extra_data cur_extra_data{ 0 };
|
struct { std::string key; std::string value; } cur_extra_data;
|
||||||
struct units xml_parsing_units;
|
struct units xml_parsing_units;
|
||||||
struct divelog *log = nullptr; /* non-owning */
|
struct divelog *log = nullptr; /* non-owning */
|
||||||
struct fingerprint_table *fingerprints = nullptr; /* non-owning */
|
struct fingerprint_table *fingerprints = nullptr; /* non-owning */
|
||||||
|
|
Loading…
Add table
Reference in a new issue