aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/validate.h
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-02-14 08:07:38 -0500
committerGitHub <noreply@github.com>2023-02-14 05:07:38 -0800
commitff3d04b75b4a9314815c37d53ebc4d035a043335 (patch)
tree435a61efa5c036060b72aa945166e76bee34d7de /src/nvim/api/private/validate.h
parent3a6a7add57d2ac141f474b54659bbbf596b76059 (diff)
downloadrneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.tar.gz
rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.tar.bz2
rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.zip
refactor(api): VALIDATE macros #22256
- VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args
Diffstat (limited to 'src/nvim/api/private/validate.h')
-rw-r--r--src/nvim/api/private/validate.h27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/nvim/api/private/validate.h b/src/nvim/api/private/validate.h
index 8448b416be..4a1b99408e 100644
--- a/src/nvim/api/private/validate.h
+++ b/src/nvim/api/private/validate.h
@@ -24,19 +24,11 @@
} \
} while (0)
-#define VALIDATE_R(cond, name, code) \
- do { \
- if (!(cond)) { \
- api_set_error(err, kErrorTypeValidation, "'" name "' is required"); \
- code; \
- } \
- } while (0)
-
#define VALIDATE_EXP(cond, name, expected, actual, code) \
do { \
if (!(cond)) { \
- api_set_error(err, kErrorTypeValidation, "Invalid " name ": expected %s, got %s", \
- expected, actual); \
+ api_set_error(err, kErrorTypeValidation, "Invalid %s: expected %s, got %s", \
+ name, expected, actual); \
code; \
} \
} while (0)
@@ -50,20 +42,27 @@
} \
} while (0)
-#define VALIDATE(cond, msg_, code) \
+#define VALIDATE(cond, fmt_, fmt_arg1, code) \
do { \
if (!(cond)) { \
- api_set_error(err, kErrorTypeValidation, "%s", msg_); \
+ api_set_error(err, kErrorTypeValidation, fmt_, fmt_arg1); \
code; \
} \
} while (0)
-#define VALIDATE_FMT(cond, fmt_, msg_, code) \
+#define VALIDATE_RANGE(cond, name, code) \
do { \
if (!(cond)) { \
- api_set_error(err, kErrorTypeValidation, fmt_, msg_); \
+ api_set_error(err, kErrorTypeValidation, "Invalid '%s': out of range", name); \
code; \
} \
} while (0)
+#define VALIDATE_R(cond, name, code) \
+ VALIDATE(cond, "Required: '%s'", name, code);
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "api/private/validate.h.generated.h"
+#endif
+
#endif // NVIM_API_PRIVATE_VALIDATE_H