diff options
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operators.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b8107a49a4c..f455f7f2719 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -106,47 +106,38 @@ /** \name Operator API * \{ */ -void WM_operator_py_idname(char *to, const char *from) +size_t WM_operator_py_idname(char *dst, const char *src) { - const char *sep = strstr(from, "_OT_"); + const char *sep = strstr(src, "_OT_"); if (sep) { - int ofs = (sep - from); + int ofs = (sep - src); /* NOTE: we use ascii `tolower` instead of system `tolower`, because the * latter depends on the locale, and can lead to `idname` mismatch. */ - memcpy(to, from, sizeof(char) * ofs); - BLI_str_tolower_ascii(to, ofs); + memcpy(dst, src, sizeof(char) * ofs); + BLI_str_tolower_ascii(dst, ofs); - to[ofs] = '.'; - BLI_strncpy(to + (ofs + 1), sep + 4, OP_MAX_TYPENAME - (ofs + 1)); - } - else { - /* should not happen but support just in case */ - BLI_strncpy(to, from, OP_MAX_TYPENAME); + dst[ofs] = '.'; + return BLI_strncpy_rlen(dst + (ofs + 1), sep + 4, OP_MAX_TYPENAME - (ofs + 1)) + (ofs + 1); } + /* Should not happen but support just in case. */ + return BLI_strncpy_rlen(dst, src, OP_MAX_TYPENAME); } -void WM_operator_bl_idname(char *to, const char *from) +size_t WM_operator_bl_idname(char *dst, const char *src) { - if (from) { - const char *sep = strchr(from, '.'); - - int from_len; - if (sep && (from_len = strlen(from)) < OP_MAX_TYPENAME - 3) { - const int ofs = (sep - from); - memcpy(to, from, sizeof(char) * ofs); - BLI_str_toupper_ascii(to, ofs); - memcpy(to + ofs, "_OT_", 4); - memcpy(to + (ofs + 4), sep + 1, (from_len - ofs)); - } - else { - /* should not happen but support just in case */ - BLI_strncpy(to, from, OP_MAX_TYPENAME); - } - } - else { - to[0] = 0; + const char *sep = strchr(src, '.'); + int from_len; + if (sep && (from_len = strlen(src)) < OP_MAX_TYPENAME - 3) { + const int ofs = (sep - src); + memcpy(dst, src, sizeof(char) * ofs); + BLI_str_toupper_ascii(dst, ofs); + memcpy(dst + ofs, "_OT_", 4); + memcpy(dst + (ofs + 4), sep + 1, (from_len - ofs)); + return (from_len - ofs) - 1; } + /* Should not happen but support just in case. */ + return BLI_strncpy_rlen(dst, src, OP_MAX_TYPENAME); } bool WM_operator_py_idname_ok_or_report(ReportList *reports, |