summaryrefslogtreecommitdiff
path: root/src/analysis/db/misc/rlestr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/misc/rlestr.c')
-rw-r--r--src/analysis/db/misc/rlestr.c107
1 files changed, 100 insertions, 7 deletions
diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c
index 39e2d99..c1d2d95 100644
--- a/src/analysis/db/misc/rlestr.c
+++ b/src/analysis/db/misc/rlestr.c
@@ -43,12 +43,73 @@
* *
******************************************************************************/
-void init_rle_string(rle_string *str, const char *data)
+void init_dynamic_rle_string(rle_string *str, char *data)
+{
+ if (data != NULL)
+ {
+ str->data = data;
+ str->length = strlen(data);
+ str->dynamic = true;
+ }
+ else
+ {
+ str->data = NULL;
+ str->length = 0;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = représentation de chaîne à traiter. *
+* data = données à conserver en mémoire. *
+* *
+* Description : Définit une représentation de chaîne de caractères constante.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void init_static_rle_string(rle_string *str, const char *data)
+{
+ if (data != NULL)
+ {
+ str->cst_data = data;
+ str->length = strlen(data);
+ str->dynamic = false;
+ }
+ else
+ {
+ str->data = NULL;
+ str->length = 0;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = représentation de chaîne à traiter. *
+* data = données à conserver en mémoire. *
+* *
+* Description : Copie une chaîne de caractères existante. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void dup_into_rle_string(rle_string *str, const char *data)
{
if (data != NULL)
{
str->data = strdup(data);
str->length = strlen(data);
+ str->dynamic = true;
}
else
{
@@ -72,15 +133,44 @@ void init_rle_string(rle_string *str, const char *data)
* *
******************************************************************************/
-void set_rle_string(rle_string *str, const char *data)
+void set_dynamic_rle_string(rle_string *str, char *data)
{
if (str->data != NULL)
unset_rle_string(str);
if (data != NULL)
{
- str->data = strdup(data);
+ str->data = data;
+ str->length = strlen(data);
+ str->dynamic = true;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = représentation de chaîne à traiter. *
+* data = données à conserver en mémoire. *
+* *
+* Description : Constitue une représentation de chaîne de caractères stable. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void set_static_rle_string(rle_string *str, const char *data)
+{
+ if (str->data != NULL)
+ unset_rle_string(str);
+
+ if (data != NULL)
+ {
+ str->cst_data = data;
str->length = strlen(data);
+ str->dynamic = false;
}
}
@@ -102,9 +192,10 @@ void unset_rle_string(rle_string *str)
{
if (str->data != NULL)
{
- free(str->data);
- str->data = NULL;
+ if (str->dynamic)
+ free(str->data);
+ str->data = NULL;
str->length = 0;
}
@@ -184,6 +275,7 @@ bool unpack_rle_string(rle_string *str, packed_buffer *pbuf)
if (result && str->length > 0)
{
str->data = (char *)malloc(str->length + 1);
+ str->dynamic = true;
result = extract_packed_buffer(pbuf, str->data, str->length + 1, false);
@@ -323,11 +415,12 @@ bool load_rle_string(rle_string *str, const char *name, const bound_value *value
switch (value->type)
{
case SQLITE_TEXT:
- set_rle_string(str, value->cstring);
+ unset_rle_string(str);
+ dup_into_rle_string(str, value->cstring);
break;
case SQLITE_NULL:
- set_rle_string(str, NULL);
+ unset_rle_string(str);
break;
default: