File: cmp_nocase.cpp

package info (click to toggle)
html2text 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,144 kB
  • sloc: cpp: 5,891; sh: 5,747; yacc: 891; makefile: 84
file content (39 lines) | stat: -rw-r--r-- 1,104 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 1999
 *      GMRS Software GmbH, Innsbrucker Ring 159, 81669 Munich, Germany.
 *      http://www.gmrs.de
 *      All rights reserved.
 *      Author: Arno Unkrig (arno.unkrig@gmrs.de)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License in the file COPYING for more details.
 */

#include <ctype.h>

#include "cmp_nocase.h"

int
_cmp_nocase(const char *s1, size_t l1, const char *s2, size_t l2)
{
	const char *e1 = s1 + l1;
	const char *e2 = s2 + l2;

	while (s1 != e1 && s2 != e2) {
		int c1 = toupper(*s1);
		int c2 = toupper(*s2);
		if (c1 < c2)
			return -1;
		if (c1 > c2)
			return 1;
		++s1, ++s2;
	}
	return s1 != e1 ? 1 : s2 != e2 ? -1 : 0;
}