Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e3b4a47c
Commit
e3b4a47c
authored
May 31, 2013
by
Edward Thomson
Committed by
Russell Belfer
Jun 17, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git__strcasesort_cmp: strcasecmp sorting rules but requires strict equality
parent
dfe8c8df
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
0 deletions
+40
-0
src/util.c
+25
-0
src/util.h
+2
-0
tests-clar/core/string.c
+13
-0
No files found.
src/util.c
View file @
e3b4a47c
...
@@ -279,6 +279,31 @@ int git__strcasecmp(const char *a, const char *b)
...
@@ -279,6 +279,31 @@ int git__strcasecmp(const char *a, const char *b)
return
(
tolower
(
*
a
)
-
tolower
(
*
b
));
return
(
tolower
(
*
a
)
-
tolower
(
*
b
));
}
}
int
git__strcasesort_cmp
(
const
char
*
a
,
const
char
*
b
)
{
int
cmp
=
0
;
const
char
*
orig_a
=
a
;
const
char
*
orig_b
=
b
;
while
(
*
a
&&
*
b
)
{
if
(
*
a
==
*
b
)
;
else
if
(
tolower
(
*
a
)
==
tolower
(
*
b
))
{
if
(
!
cmp
)
cmp
=
(
int
)(
*
(
const
unsigned
char
*
)
a
)
-
(
int
)(
*
(
const
unsigned
char
*
)
b
);
}
else
break
;
++
a
,
++
b
;
}
if
(
*
a
||
*
b
)
return
tolower
(
*
a
)
-
tolower
(
*
b
);
return
cmp
;
}
int
git__strncmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
)
int
git__strncmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
)
{
{
while
(
sz
&&
*
a
&&
*
b
&&
*
a
==
*
b
)
while
(
sz
&&
*
a
&&
*
b
&&
*
a
==
*
b
)
...
...
src/util.h
View file @
e3b4a47c
...
@@ -194,6 +194,8 @@ extern int git__strcasecmp(const char *a, const char *b);
...
@@ -194,6 +194,8 @@ extern int git__strcasecmp(const char *a, const char *b);
extern
int
git__strncmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
extern
int
git__strncmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
extern
int
git__strncasecmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
extern
int
git__strncasecmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
extern
int
git__strcasesort_cmp
(
const
char
*
a
,
const
char
*
b
);
#include "thread-utils.h"
#include "thread-utils.h"
typedef
struct
{
typedef
struct
{
...
...
tests-clar/core/string.c
View file @
e3b4a47c
...
@@ -26,3 +26,16 @@ void test_core_string__1(void)
...
@@ -26,3 +26,16 @@ void test_core_string__1(void)
cl_assert
(
git__suffixcmp
(
"zaz"
,
"ac"
)
>
0
);
cl_assert
(
git__suffixcmp
(
"zaz"
,
"ac"
)
>
0
);
}
}
/* compare icase sorting with case equality */
void
test_core_string__2
(
void
)
{
cl_assert
(
git__strcasesort_cmp
(
""
,
""
)
==
0
);
cl_assert
(
git__strcasesort_cmp
(
"foo"
,
"foo"
)
==
0
);
cl_assert
(
git__strcasesort_cmp
(
"foo"
,
"bar"
)
>
0
);
cl_assert
(
git__strcasesort_cmp
(
"bar"
,
"foo"
)
<
0
);
cl_assert
(
git__strcasesort_cmp
(
"foo"
,
"FOO"
)
>
0
);
cl_assert
(
git__strcasesort_cmp
(
"FOO"
,
"foo"
)
<
0
);
cl_assert
(
git__strcasesort_cmp
(
"foo"
,
"BAR"
)
>
0
);
cl_assert
(
git__strcasesort_cmp
(
"BAR"
,
"foo"
)
<
0
);
cl_assert
(
git__strcasesort_cmp
(
"fooBar"
,
"foobar"
)
<
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment