Skip to content
Newer
Older
100644 99 lines (80 sloc) 1.75 KB
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored Jan 14, 2011
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored Jan 2, 2009
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
23 */
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
24
25 #include "common-internal.h"
7bb65a7 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@956 5dc97367-97…
alobbs authored Dec 15, 2007
26 #include "human_strcmp.h"
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
27
28 #include <ctype.h>
29
30
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
31 static int
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
32 parsenum (const char *a, const char **a_ret)
33 {
34 int result = *a - '0';
35
36 /* Parse the number
37 */
38 ++a;
1b84f9c fixes to human_strcmp and handler_dirlist
ADF authored Dec 21, 2007
39 while (isdigit(*a)) {
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
40 result *= 10;
41 result += *a - '0';
42 ++a;
43 }
44
45 /* Return the new pointer
46 */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
47 if (a_ret)
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
48 *a_ret = a - 1;
49
50 /* .. and the number
51 */
52 return result;
53 }
54
55
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
56 int
7bb65a7 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@956 5dc97367-97…
alobbs authored Dec 15, 2007
57 cherokee_human_strcmp (const char *a, const char *b)
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
58 {
59 int a0;
60 int b0;
61
62 /* Check corner cases
63 */
64 if (unlikely (a == b))
65 return 0;
66 if (unlikely (a == NULL))
67 return -1;
68 if (unlikely (b == NULL))
69 return 1;
70
71 /* Iterate
72 */
73 while (*a && *b) {
1b84f9c fixes to human_strcmp and handler_dirlist
ADF authored Dec 21, 2007
74 if (isdigit(*a))
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
75 a0 = parsenum(a, &a) + 256;
76 else
77 a0 = tolower(*a);
78
1b84f9c fixes to human_strcmp and handler_dirlist
ADF authored Dec 21, 2007
79 if (isdigit(*b))
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
80 b0 = parsenum(b, &b) + 256;
81 else
82 b0 = tolower(*b);
83
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
84 if (a0 < b0)
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
85 return -1;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
86 if (a0 > b0)
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
87 return 1;
88
89 a++;
90 b++;
91 }
92
93 if (*a) return 1;
94 if (*b) return -1;
95
96 return 0;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
97
2d9b4d3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@955 5dc97367-97…
alobbs authored Dec 15, 2007
98 }
Something went wrong with that request. Please try again.