Blender
V3.3
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include <wcwidth.h>
#include "BLI_utildefines.h"
#include "BLI_string_utf8.h"
Go to the source code of this file.
Macros | |
#define | BLI_STR_UTF8_CPY(dst, src, maxncpy) |
#define | UTF8_COMPUTE(Char, Mask, Len, Err) |
#define | UTF8_GET(Result, Chars, Count, Mask, Len, Err) |
#define | UTF8_VARS_FROM_CHAR32(Char, First, Len) |
Functions | |
ptrdiff_t | BLI_str_utf8_invalid_byte (const char *str, size_t length) |
int | BLI_str_utf8_invalid_strip (char *str, size_t length) |
char * | BLI_strncpy_utf8 (char *__restrict dst, const char *__restrict src, size_t maxncpy) |
size_t | BLI_strncpy_utf8_rlen (char *__restrict dst, const char *__restrict src, size_t maxncpy) |
size_t | BLI_strncpy_wchar_as_utf8 (char *__restrict dst, const wchar_t *__restrict src, const size_t maxncpy) |
size_t | BLI_wstrlen_utf8 (const wchar_t *src) |
size_t | BLI_strlen_utf8_ex (const char *strc, size_t *r_len_bytes) |
size_t | BLI_strlen_utf8 (const char *strc) |
size_t | BLI_strnlen_utf8_ex (const char *strc, const size_t maxlen, size_t *r_len_bytes) |
size_t | BLI_strnlen_utf8 (const char *strc, const size_t maxlen) |
size_t | BLI_strncpy_wchar_from_utf8 (wchar_t *__restrict dst_w, const char *__restrict src_c, const size_t maxncpy) |
int | BLI_wcwidth (char32_t ucs) |
int | BLI_wcswidth (const char32_t *pwcs, size_t n) |
int | BLI_str_utf8_char_width (const char *p) |
int | BLI_str_utf8_char_width_safe (const char *p) |
int | BLI_str_utf8_size (const char *p) |
int | BLI_str_utf8_size_safe (const char *p) |
uint | BLI_str_utf8_as_unicode (const char *p) |
uint | BLI_str_utf8_as_unicode_step_or_error (const char *__restrict p, const size_t p_len, size_t *__restrict index) |
uint | BLI_str_utf8_as_unicode_step (const char *__restrict p, const size_t p_len, size_t *__restrict index) |
size_t | BLI_str_utf8_from_unicode_len (const uint c) |
size_t | BLI_str_utf8_from_unicode (uint c, char *outbuf, const size_t outbuf_len) |
size_t | BLI_str_utf8_as_utf32 (char32_t *__restrict dst_w, const char *__restrict src_c, const size_t maxncpy) |
size_t | BLI_str_utf32_as_utf8 (char *__restrict dst, const char32_t *__restrict src, const size_t maxncpy) |
size_t | BLI_str_utf32_as_utf8_len (const char32_t *src) |
const char * | BLI_str_find_prev_char_utf8 (const char *p, const char *str_start) |
const char * | BLI_str_find_next_char_utf8 (const char *p, const char *str_end) |
size_t | BLI_str_partition_utf8 (const char *str, const uint delim[], const char **sep, const char **suf) |
size_t | BLI_str_rpartition_utf8 (const char *str, const uint delim[], const char **sep, const char **suf) |
size_t | BLI_str_partition_ex_utf8 (const char *str, const char *end, const uint delim[], const char **sep, const char **suf, const bool from_right) |
Offset Conversion in Strings | |
int | BLI_str_utf8_offset_to_index (const char *str, int offset) |
int | BLI_str_utf8_offset_from_index (const char *str, int index) |
int | BLI_str_utf8_offset_to_column (const char *str, int offset) |
int | BLI_str_utf8_offset_from_column (const char *str, int column) |
Variables | |
static const size_t | utf8_skip_data [256] |
Compatible with BLI_strncpy, but ensure no partial UTF8 chars.
Definition at line 207 of file string_utf8.c.
Definition at line 409 of file string_utf8.c.
Definition at line 440 of file string_utf8.c.
#define UTF8_VARS_FROM_CHAR32 | ( | Char, | |
First, | |||
Len | |||
) |
Definition at line 536 of file string_utf8.c.
const char* BLI_str_find_next_char_utf8 | ( | const char * | p, |
const char * | str_end | ||
) |
Definition at line 680 of file string_utf8.c.
References BLI_assert.
Referenced by BLI_str_utf8_as_utf32().
const char* BLI_str_find_prev_char_utf8 | ( | const char * | p, |
const char * | str_start | ||
) |
Definition at line 665 of file string_utf8.c.
References BLI_assert.
Referenced by BLI_str_partition_ex_utf8().
size_t BLI_str_partition_ex_utf8 | ( | const char * | str, |
const char * | end, | ||
const uint | delim[], | ||
const char ** | sep, | ||
const char ** | suf, | ||
const bool | from_right | ||
) |
Definition at line 709 of file string_utf8.c.
References BLI_assert, BLI_str_find_prev_char_utf8(), BLI_str_utf8_as_unicode(), BLI_str_utf8_as_unicode_step_or_error(), BLI_UTF8_ERR, Freestyle::c, NULL, and str.
Referenced by BLI_str_partition_utf8(), and BLI_str_rpartition_utf8().
size_t BLI_str_partition_utf8 | ( | const char * | str, |
const uint | delim[], | ||
const char ** | sep, | ||
const char ** | suf | ||
) |
Definition at line 693 of file string_utf8.c.
References BLI_str_partition_ex_utf8(), NULL, and str.
size_t BLI_str_rpartition_utf8 | ( | const char * | str, |
const uint | delim[], | ||
const char ** | sep, | ||
const char ** | suf | ||
) |
Definition at line 701 of file string_utf8.c.
References BLI_str_partition_ex_utf8(), NULL, and str.
size_t BLI_str_utf32_as_utf8 | ( | char *__restrict | dst, |
const char32_t *__restrict | src, | ||
const size_t | maxncpy | ||
) |
Definition at line 634 of file string_utf8.c.
References BLI_assert, BLI_str_utf8_from_unicode(), len, src, and UNLIKELY.
size_t BLI_str_utf32_as_utf8_len | ( | const char32_t * | src | ) |
Definition at line 654 of file string_utf8.c.
References BLI_str_utf8_from_unicode_len(), len, and src.
Referenced by BKE_vfont_clipboard_set(), and ED_curve_editfont_load().
uint BLI_str_utf8_as_unicode | ( | const char * | p | ) |
p | a pointer to Unicode character encoded as UTF-8 |
Converts a sequence of bytes encoded as UTF-8 to a Unicode character. If p does not point to a valid UTF-8 encoded character, results are undefined. If you are not sure that the bytes are complete valid Unicode characters, you should use g_utf8_get_char_validated() instead.
Return value: the resulting character
Definition at line 478 of file string_utf8.c.
References BLI_UTF8_ERR, Freestyle::c, len, mask(), result, UNLIKELY, UTF8_COMPUTE, and UTF8_GET.
Referenced by BLI_str_partition_ex_utf8(), BLI_str_utf8_char_width(), BLI_str_utf8_char_width_safe(), blender::string_search::extract_normalized_words(), blender::string_search::get_fuzzy_match_errors(), insert_text_invoke(), key_event_glyph_or_text(), text_autocomplete_build(), and text_insert_invoke().
uint BLI_str_utf8_as_unicode_step | ( | const char *__restrict | p, |
const size_t | p_len, | ||
size_t *__restrict | index | ||
) |
Definition at line 521 of file string_utf8.c.
References BLI_assert, BLI_str_utf8_as_unicode_step_or_error(), BLI_UTF8_ERR, result, and UNLIKELY.
uint BLI_str_utf8_as_unicode_step_or_error | ( | const char *__restrict | p, |
const size_t | p_len, | ||
size_t *__restrict | index | ||
) |
Definition at line 496 of file string_utf8.c.
References BLI_assert, BLI_UTF8_ERR, Freestyle::c, len, mask(), result, UNLIKELY, UTF8_COMPUTE, and UTF8_GET.
Referenced by BLI_str_partition_ex_utf8(), BLI_str_utf8_as_unicode_step(), and BLI_str_utf8_as_utf32().
size_t BLI_str_utf8_as_utf32 | ( | char32_t *__restrict | dst_w, |
const char *__restrict | src_c, | ||
const size_t | maxncpy | ||
) |
Definition at line 599 of file string_utf8.c.
References BLI_assert, BLI_str_find_next_char_utf8(), BLI_str_utf8_as_unicode_step_or_error(), BLI_UTF8_ERR, and len.
Referenced by BLI_strncpy_wchar_from_utf8().
int BLI_str_utf8_char_width | ( | const char * | p | ) |
Definition at line 378 of file string_utf8.c.
References BLI_str_utf8_as_unicode(), BLI_UTF8_ERR, and BLI_wcwidth().
int BLI_str_utf8_char_width_safe | ( | const char * | p | ) |
Definition at line 388 of file string_utf8.c.
References BLI_str_utf8_as_unicode(), BLI_UTF8_ERR, and BLI_wcwidth().
Referenced by BLI_str_utf8_offset_from_column(), BLI_str_utf8_offset_to_column(), console_cursor_wrap_offset(), flatten_column_to_offset(), flatten_width(), text_cursor_set_to_pos_wrapped(), text_get_cursor_rel(), textview_wrap_offsets(), txt_wrap_move_bol(), and txt_wrap_move_eol().
size_t BLI_str_utf8_from_unicode | ( | unsigned int | c, |
char * | outbuf, | ||
size_t | outbuf_len | ||
) |
BLI_str_utf8_from_unicode:
c | a Unicode character code |
outbuf | output buffer, must have at least outbuf_len bytes of space. If the length required by c exceeds outbuf_len , the bytes available bytes will be zeroed and outbuf_len returned. |
Converts a single character to UTF-8.
Definition at line 575 of file string_utf8.c.
References Freestyle::c, len, UNLIKELY, and UTF8_VARS_FROM_CHAR32.
Referenced by BLI_str_utf32_as_utf8(), BLI_strncpy_wchar_as_utf8(), find_family_object(), txt_add_char_intern(), txt_extended_ascii_as_utf8(), txt_replace_char(), and wm_event_add_ghostevent().
size_t BLI_str_utf8_from_unicode_len | ( | const uint | c | ) |
Definition at line 563 of file string_utf8.c.
References Freestyle::c, len, UTF8_VARS_FROM_CHAR32, and void.
Referenced by BLI_str_utf32_as_utf8_len(), and BLI_wstrlen_utf8().
ptrdiff_t BLI_str_utf8_invalid_byte | ( | const char * | str, |
size_t | length | ||
) |
Find first UTF-8 invalid byte in given str, of length bytes.
Definition at line 46 of file string_utf8.c.
References Freestyle::c, ELEM, blender::math::length(), str, and utf8_skip_data.
Referenced by BLI_str_utf8_invalid_strip(), and txt_extended_ascii_as_utf8().
int BLI_str_utf8_invalid_strip | ( | char * | str, |
size_t | length | ||
) |
Remove any invalid UTF-8 byte (taking into account multi-bytes sequence of course).
Definition at line 181 of file string_utf8.c.
References BLI_assert, BLI_str_utf8_invalid_byte(), blender::math::length(), and str.
Referenced by BKE_id_new_name_validate(), id_name_final_build(), objfnt_to_ftvfontdata(), outputNumInput(), SEQ_edit_sequence_name_set(), TEST(), ui_textedit_copypaste(), and ui_textedit_end().
int BLI_str_utf8_offset_from_column | ( | const char * | str, |
int | column | ||
) |
Definition at line 791 of file string_utf8.c.
References BLI_str_utf8_char_width_safe(), BLI_str_utf8_size_safe(), col, offset, pos, and str.
Referenced by textview_draw_string(), txt_move_down(), txt_move_up(), and txt_wrap_move_bol().
int BLI_str_utf8_offset_from_index | ( | const char * | str, |
int | index | ||
) |
Definition at line 771 of file string_utf8.c.
References BLI_str_utf8_size(), offset, pos, and str.
Referenced by blender::nodes::node_fn_slice_string_cc::fn_node_slice_string_build_multi_function(), blender::nodes::node_geo_string_to_curves_cc::get_text_layout(), and txt_sel_set().
int BLI_str_utf8_offset_to_column | ( | const char * | str, |
int | offset | ||
) |
Definition at line 781 of file string_utf8.c.
References BLI_str_utf8_char_width_safe(), BLI_str_utf8_size_safe(), offset, pos, and str.
Referenced by textview_draw_sel(), txt_move_down(), and txt_move_up().
int BLI_str_utf8_offset_to_index | ( | const char * | str, |
int | offset | ||
) |
Definition at line 761 of file string_utf8.c.
References BLI_str_utf8_size(), offset, pos, and str.
int BLI_str_utf8_size | ( | const char * | p | ) |
Definition at line 452 of file string_utf8.c.
References Freestyle::c, len, mask(), UTF8_COMPUTE, and void.
Referenced by BLI_str_utf8_offset_from_index(), BLI_str_utf8_offset_to_index(), blender::string_search::get_fuzzy_match_errors(), handleNumInput(), txt_move_right(), ui_do_but_textedit(), ui_text_clip_cursor(), wm_event_add_ghostevent(), WM_event_print(), and WM_event_utf8_to_ascii().
int BLI_str_utf8_size_safe | ( | const char * | p | ) |
Use when we want to skip errors.
Definition at line 466 of file string_utf8.c.
References Freestyle::c, len, mask(), UTF8_COMPUTE, and void.
Referenced by BLI_str_utf8_offset_from_column(), BLI_str_utf8_offset_to_column(), BLI_strlen_utf8_ex(), BLI_strnlen_utf8_ex(), console_cursor_wrap_offset(), console_indent_or_autocomplete_exec(), console_insert_invoke(), flatten_column_to_offset(), flatten_string(), flatten_width(), text_convert_whitespace_exec(), text_cursor_set_to_pos_wrapped(), text_font_draw_character_utf8(), text_format_fill(), text_get_cursor_rel(), text_insert_invoke(), textview_wrap_offsets(), txt_wrap_move_bol(), txt_wrap_move_eol(), txtfmt_lua_format_line(), txtfmt_osl_format_line(), txtfmt_pov_format_line(), txtfmt_pov_ini_format_line(), and txtfmt_py_format_line().
size_t BLI_strlen_utf8 | ( | const char * | strc | ) |
Definition at line 317 of file string_utf8.c.
References BLI_strlen_utf8_ex().
Referenced by blo_do_versions_260(), blender::nodes::node_fn_slice_string_cc::fn_node_slice_string_build_multi_function(), blender::nodes::node_fn_string_length_cc::fn_node_string_length_build_multi_function(), insert_text_exec(), key_event_glyph_or_text(), radial_control_paint_cursor(), blender::io::obj::TEST(), txt_sel_set(), ui_but_text_password_hide(), and voxel_size_edit_draw().
size_t BLI_strlen_utf8_ex | ( | const char * | strc, |
size_t * | r_len_bytes | ||
) |
Definition at line 304 of file string_utf8.c.
References BLI_str_utf8_size_safe(), and len.
Referenced by BLI_strlen_utf8().
char* BLI_strncpy_utf8 | ( | char *__restrict | dst, |
const char *__restrict | src, | ||
size_t | maxncpy | ||
) |
Definition at line 236 of file string_utf8.c.
References BLI_assert, BLI_STR_UTF8_CPY, and src.
size_t BLI_strncpy_utf8_rlen | ( | char *__restrict | dst, |
const char *__restrict | src, | ||
size_t | maxncpy | ||
) |
Definition at line 252 of file string_utf8.c.
References BLI_assert, BLI_STR_UTF8_CPY, and src.
size_t BLI_strncpy_wchar_as_utf8 | ( | char *__restrict | dst, |
const wchar_t *__restrict | src, | ||
const size_t | maxncpy | ||
) |
Definition at line 273 of file string_utf8.c.
References BLI_assert, BLI_str_utf8_from_unicode(), len, src, and UNLIKELY.
size_t BLI_strncpy_wchar_from_utf8 | ( | wchar_t *__restrict | dst_w, |
const char *__restrict | src_c, | ||
const size_t | maxncpy | ||
) |
Definition at line 348 of file string_utf8.c.
References BLI_str_utf8_as_utf32(), and conv_utf_8_to_16().
size_t BLI_strnlen_utf8 | ( | const char * | strc, |
size_t | maxlen | ||
) |
strc | the string to measure the length. |
maxlen | the string length (in bytes) |
Definition at line 342 of file string_utf8.c.
References BLI_strnlen_utf8_ex().
Referenced by blender::string_search::count_utf8_code_points(), and ui_text_position_to_hidden().
size_t BLI_strnlen_utf8_ex | ( | const char * | strc, |
const size_t | maxlen, | ||
size_t * | r_len_bytes | ||
) |
Definition at line 323 of file string_utf8.c.
References BLI_str_utf8_size_safe(), and len.
Referenced by BLI_strnlen_utf8().
int BLI_wcswidth | ( | const char32_t * | pwcs, |
size_t | n | ||
) |
Definition at line 373 of file string_utf8.c.
int BLI_wcwidth | ( | char32_t | ucs | ) |
Count columns that character/string occupies (based on wcwidth.co
).
Definition at line 364 of file string_utf8.c.
Referenced by blf_font_draw_mono(), blf_glyph_render(), BLI_str_utf8_char_width(), and BLI_str_utf8_char_width_safe().
size_t BLI_wstrlen_utf8 | ( | const wchar_t * | src | ) |
wchar_t
length in UTF-8. Definition at line 293 of file string_utf8.c.
References BLI_str_utf8_from_unicode_len(), len, and src.
|
static |
Array copied from GLIB's gutf8.c
.
Definition at line 35 of file string_utf8.c.
Referenced by BLI_str_utf8_invalid_byte().