bool streq_underscore(const char *const s1, const char *const s2)
{
- if (s2[0] == '_' && s2[1] == '_') {
- size_t len2 = strlen(s2);
- size_t len1 = strlen(s1);
- if (len1 == len2 - 4 && s2[len2 - 2] == '_' && s2[len2 - 1] == '_') {
- return strncmp(s1, s2 + 2, len2 - 4) == 0;
- }
+ char const* const middle = strstart(s2, "__");
+ if (middle) {
+ char const* const rest = strstart(middle, s1);
+ if (rest && streq(rest, "__"))
+ return true;
}
return streq(s1, s2);
*/
#include "config.h"
+#include "adt/strutil.h"
#include "type_t.h"
#include "types.h"
#include "entity_t.h"
/* Disregard prefix _, __, __x or __builtin_. */
if (name[0] == '_') {
- if (!strncmp(name + 1, "_builtin_", 9))
+ if (strstart(name + 1, "_builtin_"))
name += 10;
else if (name[1] == '_' && name[2] == 'x')
name += 3;
static bool firm_opt_option(const char *opt)
{
- bool enable = true;
- if (strncmp(opt, "no-", 3) == 0) {
- enable = false;
- opt = opt + 3;
- }
+ char const* const rest = strstart(opt, "no-");
+ bool const enable = rest ? opt = rest, false : true;
opt_config_t *config = get_opt(opt);
if (config == NULL || (config->flags & OPT_FLAG_HIDE_OPTIONS))
#include <stdio.h>
#include <string.h>
+#include "adt/strutil.h"
#include "adt/util.h"
#include "warning.h"
#include "help.h"
{
/* Process prefixes: -W[no-][error=] */
char const *s = opt;
- bool const no = strncmp(s, "no-", 3) == 0 ? s += 3, true : false;
- bool const error = strncmp(s, "error=", 6) == 0 ? s += 6, true : false;
+ char const *rest;
+ bool const no = (rest = strstart(s, "no-")) ? s = rest, true : false;
+ bool const error = (rest = strstart(s, "error=")) ? s = rest, true : false;
warn_state_t on = WARN_STATE_NONE;
warn_state_t off = WARN_STATE_NONE;
#include <errno.h>
#include <string.h>
+#include "adt/strutil.h"
#include "write_jna.h"
#include "symbol_t.h"
#include "ast_t.h"
static bool is_system_header(const char *fname)
{
- if (strncmp(fname, "/usr/include", 12) == 0)
+ if (strstart(fname, "/usr/include"))
return true;
if (fname == builtin_source_position.input_name)
return true;