Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Joe Martin
OpenLDAP
Commits
14210f5e
Commit
14210f5e
authored
Jan 22, 2000
by
Kurt Zeilenga
Browse files
Fix charlen and add getc
parent
23afcd5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
libraries/libldap/utf-8.c
View file @
14210f5e
...
...
@@ -38,16 +38,18 @@ ber_len_t ldap_utf8_bytes( const char * p )
ber_len_t
ldap_utf8_chars
(
const
char
*
p
)
{
/* could be optimized */
int
chars
=
0
;
int
i
=
0
;
unsigned
char
*
u
;
/* could be optimized and could check for invalid sequences */
ber_len_t
chars
;
for
(
i
=
0
;
u
[
i
];
i
++
)
{
if
(
u
[
i
]
&
0xC0
!=
0x80
)
chars
++
;
}
for
(
chars
=
0
;
*
p
;
chars
++
)
{
int
charlen
=
ldap_utf8_charlen
(
p
);
if
(
!
charlen
)
return
chars
;
p
=
&
p
[
charlen
];
};
return
i
;
return
chars
;
}
int
ldap_utf8_charlen
(
const
char
*
p
)
...
...
@@ -179,3 +181,43 @@ int ldap_utf8_isspace( const char * p )
return
0
;
}
char
*
ldap_utf8_fgetc
(
FILE
*
s
,
char
*
buf
)
{
int
i
;
unsigned
char
*
p
;
unsigned
int
c
;
int
len
;
if
(
s
==
NULL
)
return
NULL
;
p
=
buf
;
c
=
fgetc
(
s
);
if
(
c
==
EOF
)
{
p
[
0
]
=
-
1
;
return
NULL
;
}
p
[
0
]
=
c
;
len
=
ldap_utf8_charlen
(
buf
);
if
(
len
<
1
)
return
NULL
;
for
(
i
=
1
;
i
<
len
;
i
++
)
{
unsigned
int
c
=
fgetc
(
s
);
if
(
c
==
EOF
)
{
p
[
i
]
=
-
1
;
return
NULL
;
}
if
(
c
&
0xC0
!=
0x80
)
{
ungetc
(
c
,
s
);
p
[
i
]
=
-
1
;
return
NULL
;
}
p
[
i
]
=
c
;
}
return
buf
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment