File: strutils.c

package info (click to toggle)
openvas-scanner 23.35.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,416 kB
  • sloc: ansic: 41,615; xml: 6,251; pascal: 3,723; yacc: 1,250; sh: 1,068; makefile: 333; sql: 273; javascript: 12
file content (39 lines) | stat: -rw-r--r-- 849 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* SPDX-FileCopyrightText: 2023 Greenbone AG
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "strutils.h"

#include "support.h"

#include <glib.h>

/**
 * @brief Matches a string against a pattern.
 *
 * @param[in] string  String to match.
 * @param[in] pattern Pattern to match against.
 * @param[in] icase   Case insensitivity enabled.
 *
 * @return 1 if it matches. 0 otherwise.
 */
int
str_match (const gchar *string, const gchar *pattern, int icase)
{
  gboolean res;
  GPatternSpec *patt = NULL;

  if (icase)
    {
      patt = g_pattern_spec_new (g_ascii_strdown (pattern, -1));
      res = g_pattern_spec_match_string (patt, g_ascii_strdown (string, -1));
    }
  else
    {
      patt = g_pattern_spec_new (pattern);
      res = g_pattern_spec_match_string (patt, string);
    }
  g_pattern_spec_free (patt);
  return res;
}