Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenLDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lukas However
OpenLDAP
Commits
7a3c92f2
Commit
7a3c92f2
authored
24 years ago
by
Stig Venaas
Browse files
Options
Downloads
Patches
Plain Diff
Adding UTF8normcmp() for normalizing and comparing two UTF8 strings
parent
a8b77998
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/ldap_pvt_uc.h
+6
-1
6 additions, 1 deletion
include/ldap_pvt_uc.h
libraries/liblunicode/ucstr.c
+72
-0
72 additions, 0 deletions
libraries/liblunicode/ucstr.c
with
78 additions
and
1 deletion
include/ldap_pvt_uc.h
+
6
−
1
View file @
7a3c92f2
...
...
@@ -131,7 +131,12 @@ LDAP_LUNICODE_F(void) ucstr2upper(
LDAP_LUNICODE_F
(
char
*
)
UTF8normalize
(
const
char
*
,
char
casefold
);
char
);
LDAP_LUNICODE_F
(
int
)
UTF8normcmp
(
const
char
*
,
const
char
*
,
char
);
LDAP_END_DECL
...
...
This diff is collapsed.
Click to expand it.
libraries/liblunicode/ucstr.c
+
72
−
0
View file @
7a3c92f2
...
...
@@ -207,3 +207,75 @@ char * UTF8normalize(
out
[
outpos
]
=
'\0'
;
return
out
;
}
/* compare UTF8-strings, optionally ignore casing, string pointers must not be NULL */
/* slow, should be optimized */
int
UTF8normcmp
(
const
char
*
s1
,
const
char
*
s2
,
char
casefold
)
{
int
i
,
l1
,
l2
,
len
,
ulen
,
res
;
unsigned
long
*
ucs
,
*
ucsout1
,
*
ucsout2
;
l1
=
strlen
(
s1
);
l2
=
strlen
(
s2
);
if
(
(
l1
==
0
)
||
(
l2
==
0
)
)
{
if
(
l1
==
l2
)
{
return
0
;
}
return
*
s1
-
*
s2
>
0
?
1
:
-
1
;
}
ucs
=
(
long
*
)
malloc
(
(
l1
>
l2
?
l1
:
l2
)
*
sizeof
(
*
ucs
)
);
if
(
ucs
==
NULL
)
{
return
l1
>
l2
?
1
:
-
1
;
/* what to do??? */
}
/*
* XXYYZ: we convert to ucs4 even though -llunicode
* expects ucs2 in an unsigned long
*/
/* convert and normalize 1st string */
for
(
i
=
0
,
ulen
=
0
;
i
<
l1
;
i
+=
len
,
ulen
++
)
{
ucs
[
ulen
]
=
ldap_utf8_to_ucs4
(
s1
+
i
);
if
(
ucs
[
ulen
]
==
LDAP_UCS4_INVALID
)
{
free
(
ucs
);
return
-
1
;
/* what to do??? */
}
len
=
LDAP_UTF8_CHARLEN
(
s1
+
i
);
}
uccanondecomp
(
ucs
,
ulen
,
&
ucsout1
,
&
l1
);
l1
=
uccanoncomp
(
ucsout1
,
l1
);
/* convert and normalize 2nd string */
for
(
i
=
0
,
ulen
=
0
;
i
<
l2
;
i
+=
len
,
ulen
++
)
{
ucs
[
ulen
]
=
ldap_utf8_to_ucs4
(
s2
+
i
);
if
(
ucs
[
ulen
]
==
LDAP_UCS4_INVALID
)
{
free
(
ucsout1
);
free
(
ucs
);
return
1
;
/* what to do??? */
}
len
=
LDAP_UTF8_CHARLEN
(
s2
+
i
);
}
uccanondecomp
(
ucs
,
ulen
,
&
ucsout2
,
&
l2
);
l2
=
uccanoncomp
(
ucsout2
,
l2
);
free
(
ucs
);
res
=
casefold
?
ucstrncasecmp
(
ucsout1
,
ucsout2
,
l1
<
l2
?
l1
:
l2
)
:
ucstrncmp
(
ucsout1
,
ucsout2
,
l1
<
l2
?
l1
:
l2
);
free
(
ucsout1
);
free
(
ucsout2
);
if
(
res
!=
0
)
{
return
res
;
}
if
(
l1
==
l2
)
{
return
0
;
}
return
l1
>
l2
?
1
:
-
1
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment