source: trunk/kStuff/kHlp/Generic/kHlpMemICompAscii.c@ 3574

Last change on this file since 3574 was 3574, checked in by bird, 18 years ago

Generic kHlpString.h implementation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1/* $Id: kHlpMemICompAscii.c 3574 2007-09-02 19:30:58Z bird $ */
2/** @file
3 * kHlpString - kHlpMemICompAscii.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * This file is part of kStuff.
10 *
11 * kStuff is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * kStuff is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with kStuff; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <k/kHlpString.h>
31
32
33KHLP_DECL(int) kHlpMemICompAscii(const void *pv1, const void *pv2, KSIZE cb)
34{
35 union
36 {
37 const void *pv;
38 const KU8 *pb;
39 const KUPTR *pu;
40 } u1, u2;
41
42 u1.pv = pv1;
43 u2.pv = pv2;
44
45 if (cb >= 32)
46 {
47 while (cb > sizeof(KUPTR))
48 {
49 if (*u1.pu != *u2.pu)
50 break; /* hand it on to the byte-by-byte routine. */
51 u1.pu++;
52 u2.pu++;
53 cb -= sizeof(KUPTR);
54 }
55 }
56
57 while (cb-- > 0)
58 {
59 if (u1.pb != u2.pb)
60 {
61 KU8 ch1 = *u1.pb;
62 KU8 ch2 = *u2.pb;
63 if (ch1 <= 'Z' && ch1 >= 'A')
64 ch1 += 'a' - 'A';
65 if (ch2 <= 'Z' && ch2 >= 'A')
66 ch2 += 'a' - 'A';
67 if (ch1 != ch2)
68 return ch1 > ch2 ? 1 : -1;
69 }
70 u1.pb++;
71 u2.pb++;
72 }
73
74 return 0;
75}
76
Note: See TracBrowser for help on using the repository browser.