Blender  V3.3
BLI_string_utf8.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 #include "BLI_compiler_attrs.h"
10 #include "BLI_sys_types.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy)
17  ATTR_NONNULL(1, 2);
18 size_t BLI_strncpy_utf8_rlen(char *__restrict dst,
19  const char *__restrict src,
20  size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
26 ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(1);
33 
54 unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
65 unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p,
66  size_t p_len,
67  size_t *__restrict index) ATTR_WARN_UNUSED_RESULT
68  ATTR_NONNULL(1, 3);
83  const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT
84  ATTR_NONNULL(1, 3);
85 
99 size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2);
100 size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w,
101  const char *__restrict src_c,
102  size_t maxncpy) ATTR_NONNULL(1, 2);
103 size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy)
104  ATTR_NONNULL(1, 2);
109 
125 const char *BLI_str_find_prev_char_utf8(const char *p, const char *str_start)
139 const char *BLI_str_find_next_char_utf8(const char *p, const char *str_end)
141 
145 size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
146 size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes)
148 size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
149 size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes)
150  ATTR_NONNULL(1, 3);
156 size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
157 size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst,
158  const wchar_t *__restrict src,
159  size_t maxncpy) ATTR_NONNULL(1, 2);
160 size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst,
161  const char *__restrict src,
162  size_t maxncpy) ATTR_NONNULL(1, 2);
163 
167 int BLI_wcwidth(char32_t ucs) ATTR_WARN_UNUSED_RESULT;
168 int BLI_wcswidth(const char32_t *pwcs, size_t n) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
174 
175 size_t BLI_str_partition_utf8(const char *str,
176  const unsigned int delim[],
177  const char **sep,
178  const char **suf) ATTR_NONNULL(1, 2, 3, 4);
179 size_t BLI_str_rpartition_utf8(const char *str,
180  const unsigned int delim[],
181  const char **sep,
182  const char **suf) ATTR_NONNULL(1, 2, 3, 4);
183 size_t BLI_str_partition_ex_utf8(const char *str,
184  const char *end,
185  const unsigned int delim[],
186  const char **sep,
187  const char **suf,
188  bool from_right) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 3, 4, 5);
189 
191  ATTR_NONNULL(1);
193  ATTR_NONNULL(1);
195  ATTR_NONNULL(1);
197  ATTR_NONNULL(1);
198 
200 #define BLI_UTF8_MAX 6
201 #define BLI_UTF8_WIDTH_MAX 2 /* columns */
202 #define BLI_UTF8_ERR ((unsigned int)-1)
203 
204 /* -------------------------------------------------------------------- */
210 #define STRNCPY_UTF8(dst, src) BLI_strncpy_utf8(dst, src, ARRAY_SIZE(dst))
211 #define STRNCPY_UTF8_RLEN(dst, src) BLI_strncpy_utf8_rlen(dst, src, ARRAY_SIZE(dst))
212 
215 #ifdef __cplusplus
216 }
217 #endif
#define ATTR_RETURNS_NONNULL
#define ATTR_NONNULL(...)
size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, size_t maxncpy) ATTR_NONNULL(1
int BLI_str_utf8_offset_from_column(const char *str, int column) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:791
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, size_t maxncpy) ATTR_NONNULL(1
size_t BLI_str_partition_utf8(const char *str, const unsigned int delim[], const char **sep, const char **suf) ATTR_NONNULL(1
int BLI_str_utf8_char_width(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:378
int BLI_str_utf8_size(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:452
char size_t ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(1)
Definition: string_utf8.c:46
size_t size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy) ATTR_NONNULL(1
unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:478
int BLI_str_utf8_offset_from_index(const char *str, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:771
size_t size_t BLI_str_rpartition_utf8(const char *str, const unsigned int delim[], const char **sep, const char **suf) 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 size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: string_utf8.c:342
unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_str_utf8_char_width_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:388
int BLI_str_utf8_offset_to_column(const char *str, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:781
size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes) 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
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:466
size_t ATTR_WARN_UNUSED_RESULT
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
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: string_utf8.c:317
char size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
size_t size_t size_t int BLI_str_utf8_offset_to_index(const char *str, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:761
const char const char size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: string_utf8.c:293
int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL(1)
Definition: string_utf8.c:181
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(1
unsigned int unsigned int size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT
Definition: string_utf8.c:563
size_t size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(1
size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2)
Definition: string_utf8.c:575
int BLI_wcswidth(const char32_t *pwcs, size_t n) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:373
size_t size_t size_t BLI_str_utf32_as_utf8_len(const char32_t *src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: string_utf8.c:654
size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1
size_t size_t int BLI_wcwidth(char32_t ucs) ATTR_WARN_UNUSED_RESULT
Definition: string_utf8.c:364
size_t size_t size_t BLI_str_partition_ex_utf8(const char *str, const char *end, const unsigned int delim[], const char **sep, const char **suf, bool from_right) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
SyclQueue void void * src
#define str(s)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
static unsigned c
Definition: RandGen.cpp:83
T length(const vec_base< T, Size > &a)