Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-05-20 06:31:41 +0300
committerCampbell Barton <campbell@blender.org>2022-05-20 06:35:28 +0300
commit838806be2869d0a91f1cd611ae0f9050e6847044 (patch)
tree1ba7289758c221b5ecac2cc9dc1491a708056c70 /source/blender/windowmanager/intern/wm_operators.c
parent780ad443fdfe2f381a646da5cc36e81459e46e3f (diff)
WM: return the string length from operator name conversion
- In some cases it avoids using strlen on the result. - Use ATTR_NONNULL for all arguments. - Remove NULL pointer check for WM_operator_bl_idname src argument. - Rename from/to to src/dst.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operators.c')
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c51
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,