about summary refs log tree commit diff
path: root/string/test-strcspn.c
blob: 50a06e44c4801b63c6814ec892aea99833d30b05 (plain) (blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
/* Test and measure strcspn functions.
   Copyright (C) 1999-2015 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Written by Jakub Jelinek <jakub@redhat.com>, 1999.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#define STRPBRK_RESULT(s, pos) (pos)
#define RES_TYPE size_t
#define TEST_MAIN
#define TEST_NAME "strcspn"
#include "test-string.h"

typedef size_t (*proto_t) (const char *, const char *);
size_t simple_strcspn (const char *, const char *);
size_t stupid_strcspn (const char *, const char *);

IMPL (stupid_strcspn, 0)
IMPL (simple_strcspn, 0)
IMPL (strcspn, 1)

#define AS_STRCSPN
#define STRPBRK simple_strcspn
#include "string/strpbrk.c"

size_t
stupid_strcspn (const char *s, const char *rej)
{
  size_t ns = strlen (s), nrej = strlen (rej);
  size_t i, j;

  for (i = 0; i < ns; ++i)
    for (j = 0; j < nrej; ++j)
      if (s[i] == rej[j])
	return i;
  return i;
}

#include "test-strpbrk.c"