Blender V4.3
BLI_string_utf8.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include "BLI_compiler_attrs.h"
12#include "BLI_sys_types.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy)
19 ATTR_NONNULL(1, 2);
20size_t BLI_strncpy_utf8_rlen(char *__restrict dst,
21 const char *__restrict src,
22 size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
28ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(1);
34int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL(1);
35
57 ATTR_NONNULL(1);
68unsigned int BLI_str_utf8_as_unicode_step_safe(const char *__restrict p,
69 size_t p_len,
70 size_t *__restrict index) ATTR_WARN_UNUSED_RESULT
71 ATTR_NONNULL(1, 3);
86 const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT
87 ATTR_NONNULL(1, 3);
88
102size_t BLI_str_utf8_from_unicode(unsigned int c, char *dst, size_t dst_maxncpy) ATTR_NONNULL(2);
103size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w,
104 const char *__restrict src_c,
105 size_t dst_w_maxncpy) ATTR_NONNULL(1, 2);
106size_t BLI_str_utf32_as_utf8(char *__restrict dst,
107 const char32_t *__restrict src,
108 size_t dst_maxncpy) ATTR_NONNULL(1, 2);
112size_t BLI_str_utf32_as_utf8_len_ex(const char32_t *src, size_t src_maxlen) ATTR_WARN_UNUSED_RESULT
113 ATTR_NONNULL(1);
118
134const char *BLI_str_find_prev_char_utf8(const char *p, const char *str_start)
148const char *BLI_str_find_next_char_utf8(const char *p, const char *str_end)
150
154size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
155size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes)
157size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
158size_t BLI_strnlen_utf8_ex(const char *strc, size_t strc_maxlen, size_t *r_len_bytes)
159 ATTR_NONNULL(1, 3);
165size_t BLI_strnlen_utf8(const char *strc, size_t strc_maxlen)
167size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst,
168 const wchar_t *__restrict src,
169 size_t dst_maxncpy) ATTR_NONNULL(1, 2);
170size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst_w,
171 const char *__restrict src_c,
172 size_t dst_w_maxncpy) ATTR_NONNULL(1, 2);
173
179int BLI_wcswidth_or_error(const char32_t *pwcs, size_t n) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
180
186char32_t BLI_str_utf32_char_to_upper(char32_t wc);
192char32_t BLI_str_utf32_char_to_lower(char32_t wc);
193
199
200size_t BLI_str_partition_utf8(const char *str,
201 const unsigned int delim[],
202 const char **r_sep,
203 const char **r_suf) ATTR_NONNULL(1, 2, 3, 4);
204size_t BLI_str_rpartition_utf8(const char *str,
205 const unsigned int delim[],
206 const char **r_sep,
207 const char **r_suf) ATTR_NONNULL(1, 2, 3, 4);
209 const char *end,
210 const unsigned int delim[],
211 const char **r_sep,
212 const char **r_suf,
213 bool from_right) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 3, 4, 5);
214
215int BLI_str_utf8_offset_to_index(const char *str,
216 size_t str_len,
217 int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
224int BLI_str_utf8_offset_from_index(const char *str,
225 size_t str_len,
226 int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
227int BLI_str_utf8_offset_to_column(const char *str,
228 size_t str_len,
229 int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
231 size_t str_len,
232 int column_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
234 size_t str_len,
235 int offset_target,
236 int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
238 size_t str_len,
239 int column_target,
240 int tab_width) ATTR_WARN_UNUSED_RESULT
241 ATTR_NONNULL(1);
242
244#define BLI_UTF8_MAX 6
245#define BLI_UTF8_WIDTH_MAX 2 /* columns */
246#define BLI_UTF8_ERR ((unsigned int)-1)
247
248/* -------------------------------------------------------------------- */
254#define STRNCPY_UTF8(dst, src) BLI_strncpy_utf8(dst, src, ARRAY_SIZE(dst))
255#define STRNCPY_UTF8_RLEN(dst, src) BLI_strncpy_utf8_rlen(dst, src, ARRAY_SIZE(dst))
256
259#ifdef __cplusplus
260}
261#endif
#define ATTR_RETURNS_NONNULL
#define ATTR_NONNULL(...)
size_t size_t size_t BLI_str_utf32_as_utf8_len_ex(const char32_t *src, size_t src_maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char size_t ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(1)
const char const char * BLI_str_find_next_char_utf8(const char *p, const char *str_end) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
size_t BLI_str_utf32_as_utf8_len(const char32_t *src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char32_t BLI_str_utf32_char_to_lower(char32_t wc)
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_char_width_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst_w, const char *__restrict src_c, size_t dst_w_maxncpy) ATTR_NONNULL(1
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
size_t size_t BLI_str_rpartition_utf8(const char *str, const unsigned int delim[], const char **r_sep, const char **r_suf) ATTR_NONNULL(1
int BLI_str_utf8_char_width_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t size_t BLI_strnlen_utf8(const char *strc, size_t strc_maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t ATTR_WARN_UNUSED_RESULT
size_t BLI_str_partition_utf8(const char *str, const unsigned int delim[], const char **r_sep, const char **r_suf) ATTR_NONNULL(1
unsigned int unsigned int BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_wcswidth_or_error(const char32_t *pwcs, size_t n) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
size_t size_t size_t int BLI_str_utf8_offset_to_index(const char *str, size_t str_len, int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
size_t size_t int BLI_wcwidth_or_error(char32_t ucs) ATTR_WARN_UNUSED_RESULT
unsigned int BLI_str_utf8_as_unicode_step_safe(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_str_utf8_offset_from_column(const char *str, size_t str_len, int column_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_strnlen_utf8_ex(const char *strc, size_t strc_maxlen, size_t *r_len_bytes) ATTR_NONNULL(1
size_t size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
const char const char size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char32_t BLI_str_utf32_char_to_upper(char32_t wc)
size_t size_t size_t BLI_str_partition_ex_utf8(const char *str, const char *end, const unsigned int delim[], const char **r_sep, const char **r_suf, bool from_right) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL(1)
size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, size_t dst_w_maxncpy) ATTR_NONNULL(1
unsigned int unsigned int size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT
int BLI_str_utf8_offset_to_column(const char *str, size_t str_len, int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
size_t BLI_str_utf8_from_unicode(unsigned int c, char *dst, size_t dst_maxncpy) ATTR_NONNULL(2)
unsigned int BLI_str_utf8_as_unicode_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1
int BLI_wcwidth_safe(char32_t ucs) ATTR_WARN_UNUSED_RESULT
int BLI_str_utf8_offset_from_column_with_tabs(const char *str, size_t str_len, int column_target, int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int BLI_str_utf8_as_unicode_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_size_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_offset_to_column_with_tabs(const char *str, size_t str_len, int offset_target, int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define str(s)