mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
Optimization on search for control characters in strings.
Optimization on search for control characters in strings in worksheet_write_string(). Issue #298
This commit is contained in:
parent
a8d7138cfb
commit
9e8bc95b45
@ -46,7 +46,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "shared_strings.h"
|
||||
#include "chart.h"
|
||||
|
@ -167,6 +167,7 @@ void lxw_xml_data_element(FILE * xmlfile,
|
||||
|
||||
void lxw_xml_rich_si_element(FILE * xmlfile, const char *string);
|
||||
|
||||
uint8_t lxw_has_control_characters(const char *string);
|
||||
char *lxw_escape_control_characters(const char *string);
|
||||
char *lxw_escape_url_characters(const char *string, uint8_t escape_hash);
|
||||
|
||||
|
@ -145,9 +145,7 @@ _write_si(lxw_sst *self, char *string)
|
||||
lxw_xml_start_tag(self->file, "si", NULL);
|
||||
|
||||
/* Look for and escape control chars in the string. */
|
||||
if (strpbrk(string, "\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C"
|
||||
"\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16"
|
||||
"\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F")) {
|
||||
if (lxw_has_control_characters(string)) {
|
||||
string = lxw_escape_control_characters(string);
|
||||
escaped_string = LXW_TRUE;
|
||||
}
|
||||
|
@ -6669,9 +6669,7 @@ worksheet_write_string(lxw_worksheet *self,
|
||||
}
|
||||
else {
|
||||
/* Look for and escape control chars in the string. */
|
||||
if (strpbrk(string, "\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C"
|
||||
"\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16"
|
||||
"\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F")) {
|
||||
if (lxw_has_control_characters(string)) {
|
||||
string_copy = lxw_escape_control_characters(string);
|
||||
}
|
||||
else {
|
||||
@ -7277,9 +7275,7 @@ worksheet_write_rich_string(lxw_worksheet *self,
|
||||
}
|
||||
else {
|
||||
/* Look for and escape control chars in the string. */
|
||||
if (strpbrk(rich_string, "\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C"
|
||||
"\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16"
|
||||
"\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F")) {
|
||||
if (lxw_has_control_characters(rich_string)) {
|
||||
string_copy = lxw_escape_control_characters(rich_string);
|
||||
free(rich_string);
|
||||
}
|
||||
|
@ -227,6 +227,22 @@ lxw_escape_data(const char *data)
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for control characters in strings.
|
||||
*/
|
||||
uint8_t
|
||||
lxw_has_control_characters(const char *string)
|
||||
{
|
||||
while (string) {
|
||||
if (*string < 0x20 && *string != 0x0A && *string != 0x09)
|
||||
return LXW_TRUE;
|
||||
|
||||
string++;
|
||||
}
|
||||
|
||||
return LXW_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Escape control characters in strings with _xHHHH_.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user