mirror of
https://github.com/neovim/neovim.git
synced 2025-10-03 00:18:33 +00:00
refactor(api): VALIDATE macros #22256
- VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args
This commit is contained in:
28
src/nvim/api/private/validate.c
Normal file
28
src/nvim/api/private/validate.c
Normal file
@@ -0,0 +1,28 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/api/private/validate.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "api/private/validate.c.generated.h"
|
||||
#endif
|
||||
|
||||
bool check_string_array(Array arr, char *name, bool disallow_nl, Error *err)
|
||||
{
|
||||
snprintf(IObuff, sizeof(IObuff), "'%s' item", name);
|
||||
for (size_t i = 0; i < arr.size; i++) {
|
||||
VALIDATE_T(IObuff, kObjectTypeString, arr.items[i].type, {
|
||||
return false;
|
||||
});
|
||||
// Disallow newlines in the middle of the line.
|
||||
if (disallow_nl) {
|
||||
const String l = arr.items[i].data.string;
|
||||
VALIDATE(!memchr(l.data, NL, l.size), "'%s' item contains newlines", name, {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user