libxlsxwriter/src/shared_strings.c in fast_excel-0.2.6 vs libxlsxwriter/src/shared_strings.c in fast_excel-0.3.0
- old
+ new
@@ -1,11 +1,11 @@
/*****************************************************************************
* shared_strings - A library for creating Excel XLSX sst files.
*
* Used in conjunction with the libxlsxwriter library.
*
- * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
+ * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
*
*/
#include "xlsxwriter/xmlwriter.h"
#include "xlsxwriter/shared_strings.h"
@@ -32,11 +32,11 @@
/*
* Create a new SST SharedString object.
*/
lxw_sst *
-lxw_sst_new()
+lxw_sst_new(void)
{
/* Create the new shared string table. */
lxw_sst *sst = calloc(1, sizeof(lxw_sst));
RETURN_ON_MEM_ERROR(sst, NULL);
@@ -160,10 +160,19 @@
if (escaped_string)
free(string);
}
/*
+ * Write the <si> element for rich strings.
+ */
+STATIC void
+_write_rich_si(lxw_sst *self, char *string)
+{
+ lxw_xml_rich_si_element(self->file, string);
+}
+
+/*
* Write the <sst> element.
*/
STATIC void
_write_sst(lxw_sst *self)
{
@@ -196,11 +205,15 @@
{
struct sst_element *sst_element;
STAILQ_FOREACH(sst_element, self->order_list, sst_order_pointers) {
/* Write the si element. */
- _write_si(self, sst_element->string);
+ if (sst_element->is_rich_string)
+ _write_rich_si(self, sst_element->string);
+ else
+ _write_si(self, sst_element->string);
+
}
}
/*
* Assemble and write the XML file.
@@ -228,11 +241,11 @@
****************************************************************************/
/*
* Add to or find a string in the SST SharedString table and return it's index.
*/
struct sst_element *
-lxw_get_sst_index(lxw_sst *sst, const char *string)
+lxw_get_sst_index(lxw_sst *sst, const char *string, uint8_t is_rich_string)
{
struct sst_element *element;
struct sst_element *existing_element;
/* Create an sst element to potentially add to the table. */
@@ -241,9 +254,10 @@
return NULL;
/* Create potential new element with the string and its index. */
element->index = sst->unique_count;
element->string = lxw_strdup(string);
+ element->is_rich_string = is_rich_string;
/* Try to insert it and see whether we already have that string. */
existing_element = RB_INSERT(sst_rb_tree, sst->rb_tree, element);
/* If existing_element is not NULL, then it already existed. */