libxlsxwriter/src/utility.c in fast_excel-0.2.3 vs libxlsxwriter/src/utility.c in fast_excel-0.2.5

- old
+ new

@@ -1,11 +1,11 @@ /***************************************************************************** * utility - Utility functions for libxlsxwriter. * * Used in conjunction with the libxlsxwriter library. * - * Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt. + * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt. * */ #include <ctype.h> #include <stdio.h> @@ -26,10 +26,11 @@ "NULL function parameter ignored.", "Function parameter validation error.", "Worksheet name exceeds Excel's limit of 31 characters.", "Worksheet name contains invalid Excel character: '[]:*?/\\'", "Worksheet name is already in use.", + "Parameter exceeds Excel's limit of 32 characters.", "Parameter exceeds Excel's limit of 128 characters.", "Parameter exceeds Excel's limit of 255 characters.", "String exceeds Excel's limit of 32,767 characters.", "Error finding internal string index.", "Worksheet row or column index out of range.", @@ -417,10 +418,23 @@ memcpy(copy, str, len); return copy; } +/* Simple function to strdup() a formula string without the leading "=". */ +char * +lxw_strdup_formula(const char *formula) +{ + if (!formula) + return NULL; + + if (formula[0] == '=') + return lxw_strdup(formula + 1); + else + return lxw_strdup(formula); +} + /* Simple strlen that counts UTF-8 characters. Assumes well formed UTF-8. */ size_t lxw_utf8_strlen(const char *str) { size_t byte_count = 0; @@ -511,5 +525,31 @@ #else (void) tmpdir; return tmpfile(); #endif } + +/* + * Sample function to handle sprintf of doubles for locale portable code. This + * is usually handled by a lxw_sprintf_dbl() macro but it can be replaced with + * a function of the same name. + * + * The code below is a simplified example that changes numbers like 123,45 to + * 123.45. End-users can replace this with something more rigorous if + * required. + */ +#ifdef USE_DOUBLE_FUNCTION +int +lxw_sprintf_dbl(char *data, double number) +{ + char *tmp; + + lxw_snprintf(data, LXW_ATTR_32, "%.16g", number); + + /* Replace comma with decimal point. */ + tmp = strchr(data, ','); + if (tmp) + *tmp = '.'; + + return 0; +} +#endif