diff --git a/src/tf.c b/src/tf.c index ddacf70a3b..3d695019ce 100644 --- a/src/tf.c +++ b/src/tf.c @@ -1487,7 +1487,7 @@ tf_func_strchr(ddb_tf_context_t *ctx, int argc, const uint16_t *arglens, const c TF_EVAL_CHECK(len, ctx, args, arglens[0], out, outlen, fail_on_undef); int32_t charpos; - char *pos = u8_strchr(out, needle, &charpos); + const char *pos = u8_strchr(out, needle, &charpos); if (!pos) { // 0 is used to indicate not found @@ -1517,7 +1517,7 @@ tf_func_strrchr(ddb_tf_context_t *ctx, int argc, const uint16_t *arglens, const uint32_t needle = u8_nextchar(str, &dummy); int32_t acc = 0, charpos; - char *pos = out; + const char *pos = out; do { pos = u8_strchr(pos, needle, &charpos); if (pos) { diff --git a/src/utf8.c b/src/utf8.c index 2657ad29f8..ca4ada3ed1 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -117,7 +117,7 @@ int u8_toucs(uint32_t *dest, int32_t sz, const char *src, int32_t srcsz) the NUL as well. the destination string will never be bigger than the source string. */ -int u8_toutf8(char *dest, int32_t sz, uint32_t *src, int32_t srcsz) +int u8_toutf8(char *dest, int32_t sz, const uint32_t *src, int32_t srcsz) { uint32_t ch; int32_t i = 0; @@ -199,7 +199,7 @@ int u8_offset(const char *str, int32_t charnum) } /* byte offset => charnum */ -int u8_charnum(char *s, int32_t offset) +int u8_charnum(const char *s, int32_t offset) { int32_t charnum = 0, offs=0; @@ -212,7 +212,7 @@ int u8_charnum(char *s, int32_t offset) } /* number of characters, not including a null terminator */ -int u8_strlen(char *s) +int u8_strlen(const char *s) { int32_t count = 0; int32_t i = 0; @@ -448,7 +448,7 @@ int u8_escape(char *buf, int32_t sz, const char *src, int32_t escape_quotes) return c; } -char *u8_strchr(char *s, uint32_t ch, int32_t *charn) +const char *u8_strchr(const char *s, uint32_t ch, int32_t *charn) { int32_t i = 0, lasti=0; uint32_t c; @@ -465,7 +465,7 @@ char *u8_strchr(char *s, uint32_t ch, int32_t *charn) return NULL; } -char *u8_memchr(char *s, uint32_t ch, size_t sz, int32_t *charn) +const char *u8_memchr(const char *s, uint32_t ch, size_t sz, int32_t *charn) { int32_t i = 0, lasti=0; uint32_t c; @@ -490,7 +490,7 @@ char *u8_memchr(char *s, uint32_t ch, size_t sz, int32_t *charn) return NULL; } -int u8_is_locale_utf8(char *locale) +int u8_is_locale_utf8(const char *locale) { /* this code based on libutf8 */ const char* cp = locale; @@ -509,7 +509,7 @@ int u8_is_locale_utf8(char *locale) return 0; } -int u8_vprintf(char *fmt, va_list ap) +int u8_vprintf(const char *fmt, va_list ap) { int32_t cnt, sz=0; char *buf; @@ -530,7 +530,7 @@ int u8_vprintf(char *fmt, va_list ap) return cnt; } -int u8_printf(char *fmt, ...) +int u8_printf(const char *fmt, ...) { int32_t cnt; va_list args; diff --git a/src/utf8.h b/src/utf8.h index 984a766711..23d9d223e4 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -44,7 +44,7 @@ int u8_toucs(uint32_t *dest, int32_t sz, const char *src, int32_t srcsz); /* the opposite conversion */ -int u8_toutf8(char *dest, int32_t sz, uint32_t *src, int32_t srcsz); +int u8_toutf8(char *dest, int32_t sz, const uint32_t *src, int32_t srcsz); /* single character to UTF-8 */ int u8_wc_toutf8(char *dest, uint32_t ch); @@ -53,7 +53,7 @@ int u8_wc_toutf8(char *dest, uint32_t ch); int u8_offset(const char *str, int32_t charnum); /* byte offset to character number */ -int u8_charnum(char *s, int32_t offset); +int u8_charnum(const char *s, int32_t offset); /* return next character, updating an index variable */ uint32_t u8_nextchar(const char *s, int32_t *i); @@ -100,22 +100,22 @@ int hex_digit(char c); /* return a pointer to the first occurrence of ch in s, or NULL if not found. character index of found character returned in *charn. */ -char *u8_strchr(char *s, uint32_t ch, int32_t *charn); +const char *u8_strchr(const char *s, uint32_t ch, int32_t *charn); /* same as the above, but searches a buffer of a given size instead of a NUL-terminated string. */ -char *u8_memchr(char *s, uint32_t ch, size_t sz, int32_t *charn); +const char *u8_memchr(const char *s, uint32_t ch, size_t sz, int32_t *charn); /* count the number of characters in a UTF-8 string */ -int u8_strlen(char *s); +int u8_strlen(const char *s); -int u8_is_locale_utf8(char *locale); +int u8_is_locale_utf8(const char *locale); /* printf where the format string and arguments may be in UTF-8. you can avoid this function and just use ordinary printf() if the current locale is UTF-8. */ -int u8_vprintf(char *fmt, va_list ap); -int u8_printf(char *fmt, ...); +int u8_vprintf(const char *fmt, va_list ap); +int u8_printf(const char *fmt, ...); // validate utf8 string // returns 1 if valid, 0 otherwise