Cleanup: use BLI_str_utf8 prefix
Rename: - BLI_str_utf8_invalid_byte (was BLI_utf8_invalid_byte) - BLI_str_utf8_invalid_strip (was BLI_utf8_invalid_strip)
This commit is contained in:
parent
0de3d4e8c7
commit
aa067bef5e
|
@ -1481,7 +1481,7 @@ static bool id_name_final_build(char *name, char *base_name, size_t base_name_le
|
|||
|
||||
/* Code above may have generated invalid utf-8 string, due to raw truncation.
|
||||
* Ensure we get a valid one now. */
|
||||
base_name_len -= (size_t)BLI_utf8_invalid_strip(base_name, base_name_len);
|
||||
base_name_len -= (size_t)BLI_str_utf8_invalid_strip(base_name, base_name_len);
|
||||
|
||||
/* Also truncate orig name, and start the whole check again. */
|
||||
name[base_name_len] = '\0';
|
||||
|
@ -1731,7 +1731,7 @@ bool BKE_id_new_name_validate(ListBase *lb, ID *id, const char *tname, const boo
|
|||
else {
|
||||
/* disallow non utf8 chars,
|
||||
* the interface checks for this but new ID's based on file names don't */
|
||||
BLI_utf8_invalid_strip(name, strlen(name));
|
||||
BLI_str_utf8_invalid_strip(name, strlen(name));
|
||||
}
|
||||
|
||||
ID *id_sorting_hint = NULL;
|
||||
|
|
|
@ -308,7 +308,7 @@ int txt_extended_ascii_as_utf8(char **str)
|
|||
int added = 0;
|
||||
|
||||
while ((*str)[i]) {
|
||||
if ((bad_char = BLI_utf8_invalid_byte(*str + i, length - i)) == -1) {
|
||||
if ((bad_char = BLI_str_utf8_invalid_byte(*str + i, length - i)) == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ int txt_extended_ascii_as_utf8(char **str)
|
|||
i = 0;
|
||||
|
||||
while ((*str)[i]) {
|
||||
if ((bad_char = BLI_utf8_invalid_byte((*str) + i, length - i)) == -1) {
|
||||
if ((bad_char = BLI_str_utf8_invalid_byte((*str) + i, length - i)) == -1) {
|
||||
memcpy(newstr + mi, (*str) + i, length - i + 1);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t
|
|||
ATTR_NONNULL();
|
||||
size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy)
|
||||
ATTR_NONNULL();
|
||||
ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL();
|
||||
int BLI_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL();
|
||||
ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL();
|
||||
int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL();
|
||||
|
||||
/* warning, can return -1 on bad chars */
|
||||
int BLI_str_utf8_size(const char *p) ATTR_NONNULL();
|
||||
|
|
|
@ -302,7 +302,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
|
|||
/* Get the name. */
|
||||
if (face->family_name) {
|
||||
BLI_snprintf(vfd->name, sizeof(vfd->name), "%s %s", face->family_name, face->style_name);
|
||||
BLI_utf8_invalid_strip(vfd->name, strlen(vfd->name));
|
||||
BLI_str_utf8_invalid_strip(vfd->name, strlen(vfd->name));
|
||||
}
|
||||
|
||||
/* Select a character map. */
|
||||
|
|
|
@ -70,7 +70,7 @@ static const size_t utf8_skip_data[256] = {
|
|||
*
|
||||
* \return the offset of the first invalid byte.
|
||||
*/
|
||||
ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length)
|
||||
ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length)
|
||||
{
|
||||
const unsigned char *p, *perr, *pend = (const unsigned char *)str + length;
|
||||
unsigned char c;
|
||||
|
@ -200,14 +200,14 @@ utf8_error:
|
|||
*
|
||||
* \return number of stripped bytes.
|
||||
*/
|
||||
int BLI_utf8_invalid_strip(char *str, size_t length)
|
||||
int BLI_str_utf8_invalid_strip(char *str, size_t length)
|
||||
{
|
||||
ptrdiff_t bad_char;
|
||||
int tot = 0;
|
||||
|
||||
BLI_assert(str[length] == '\0');
|
||||
|
||||
while ((bad_char = BLI_utf8_invalid_byte(str, length)) != -1) {
|
||||
while ((bad_char = BLI_str_utf8_invalid_byte(str, length)) != -1) {
|
||||
str += bad_char;
|
||||
length -= (size_t)(bad_char + 1);
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ static const char *utf8_invalid_tests[][3] = {
|
|||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* BLI_utf8_invalid_strip (and indirectly, BLI_utf8_invalid_byte). */
|
||||
/* BLI_str_utf8_invalid_strip (and indirectly, BLI_str_utf8_invalid_byte). */
|
||||
TEST(string, Utf8InvalidBytes)
|
||||
{
|
||||
for (int i = 0; utf8_invalid_tests[i][0] != nullptr; i++) {
|
||||
|
@ -277,7 +277,7 @@ TEST(string, Utf8InvalidBytes)
|
|||
char buff[80];
|
||||
memcpy(buff, tst, sizeof(buff));
|
||||
|
||||
const int num_errors_found = BLI_utf8_invalid_strip(buff, sizeof(buff) - 1);
|
||||
const int num_errors_found = BLI_str_utf8_invalid_strip(buff, sizeof(buff) - 1);
|
||||
|
||||
printf("[%02d] -> [%02d] \"%s\" -> \"%s\"\n", num_errors, num_errors_found, tst, buff);
|
||||
EXPECT_EQ(num_errors_found, num_errors);
|
||||
|
|
|
@ -3350,7 +3350,7 @@ static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const in
|
|||
|
||||
if (pbuf) {
|
||||
if (UI_but_is_utf8(but)) {
|
||||
buf_len -= BLI_utf8_invalid_strip(pbuf, (size_t)buf_len);
|
||||
buf_len -= BLI_str_utf8_invalid_strip(pbuf, (size_t)buf_len);
|
||||
}
|
||||
|
||||
ui_textedit_insert_buf(but, data, pbuf, buf_len);
|
||||
|
@ -3527,7 +3527,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
|
|||
|
||||
if (but) {
|
||||
if (UI_but_is_utf8(but)) {
|
||||
const int strip = BLI_utf8_invalid_strip(but->editstr, strlen(but->editstr));
|
||||
const int strip = BLI_str_utf8_invalid_strip(but->editstr, strlen(but->editstr));
|
||||
/* not a file?, strip non utf-8 chars */
|
||||
if (strip) {
|
||||
/* won't happen often so isn't that annoying to keep it here for a while */
|
||||
|
|
|
@ -178,7 +178,7 @@ void outputNumInput(NumInput *n, char *str, UnitSettings *unit_settings)
|
|||
}
|
||||
/* We might have cut some multi-bytes utf8 chars
|
||||
* (e.g. trailing '°' of degrees values can become only 'A')... */
|
||||
BLI_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln]));
|
||||
BLI_str_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
static void rna_idname_validate(const char *name, char *r_name)
|
||||
{
|
||||
BLI_strncpy(r_name, name, MAX_ID_NAME - 2);
|
||||
BLI_utf8_invalid_strip(r_name, strlen(r_name));
|
||||
BLI_str_utf8_invalid_strip(r_name, strlen(r_name));
|
||||
}
|
||||
|
||||
static void rna_Main_ID_remove(Main *bmain,
|
||||
|
|
|
@ -476,6 +476,6 @@ bool SEQ_edit_remove_gaps(Scene *scene,
|
|||
void SEQ_edit_sequence_name_set(Scene *scene, Sequence *seq, const char *new_name)
|
||||
{
|
||||
BLI_strncpy_utf8(seq->name + 2, new_name, MAX_NAME - 2);
|
||||
BLI_utf8_invalid_strip(seq->name + 2, strlen(seq->name + 2));
|
||||
BLI_str_utf8_invalid_strip(seq->name + 2, strlen(seq->name + 2));
|
||||
SEQ_sequence_lookup_tag(scene, SEQ_LOOKUP_TAG_INVALID);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue