moved cw_is_utf8 to format_is_utf8.
FossilOrigin-Name: d68e3bec6f9bcf6255ff7e71ae3980a77b207ed1e5bd03cef5778094484108c0
This commit is contained in:
parent
1dbb599802
commit
a1c9895cdb
@ -81,7 +81,7 @@ MAVLOBJS= \
|
||||
mavl_merge.o \
|
||||
mavl_create_conststr.o \
|
||||
mlist.o \
|
||||
utf8.o \
|
||||
format_is_utf8.o \
|
||||
cw_load_file.o \
|
||||
cw_save_file.o
|
||||
|
||||
|
@ -769,7 +769,7 @@ extern int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_
|
||||
int cw_out_ac_name_with_priority(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
|
||||
|
||||
int cw_send_request(struct conn *conn, int msg_id);
|
||||
int cw_is_utf8(unsigned char *str, size_t len);
|
||||
//int cw_is_utf8(unsigned char *str, size_t len);
|
||||
|
||||
int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
|
||||
struct sockaddr *from);
|
||||
|
@ -518,7 +518,7 @@ void cw_dbg_colored(int level, const char *file, int line, const char *format, .
|
||||
|
||||
}
|
||||
|
||||
int cw_is_utf8(unsigned char *str, size_t len);
|
||||
//int cw_is_utf8(unsigned char *str, size_t len);
|
||||
|
||||
|
||||
int cw_format_item(char *dst,mbag_item_t * item)
|
||||
@ -549,7 +549,7 @@ static int cw_format_version(char *s, bstrv_t ver, char * def)
|
||||
int i;
|
||||
|
||||
|
||||
if ( cw_is_utf8(version,len) ){
|
||||
if ( format_is_utf8(version,len) ){
|
||||
if (len != 0 )
|
||||
rs+=sprintf(s+rs,"%.*s",len,version);
|
||||
else
|
||||
|
@ -81,7 +81,7 @@ static inline int format_hdr_flags(char *dst,uint8_t *th)
|
||||
}
|
||||
|
||||
|
||||
int cw_is_utf8(unsigned char *str, size_t len);
|
||||
int format_is_utf8(unsigned char *str, size_t len);
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
66
src/cw/format_is_utf8.c
Normal file
66
src/cw/format_is_utf8.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
This file is part of actube.
|
||||
|
||||
actube is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
libcapwap is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Implementation for format_is_utf8
|
||||
*/
|
||||
|
||||
#include "format.h"
|
||||
|
||||
/**
|
||||
* Check if a string is in UTF8 format
|
||||
* @param str String to check
|
||||
* @param len Length of the string
|
||||
* @return 0 if the string is not in UTF8 format, otherwise it is UTF8.
|
||||
*/
|
||||
|
||||
int format_is_utf8(unsigned char *str, size_t len)
|
||||
{
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
size_t bytes = 0;
|
||||
|
||||
while (i < len) {
|
||||
j = i;
|
||||
if (str[i] < 0x20) {
|
||||
return 0;
|
||||
}
|
||||
if (str[i] <= 0x7F)
|
||||
bytes = 0;
|
||||
else if (str[i] >= 0xC0 /*11000000 */ && str[i] <= 0xDF /*11011111 */ )
|
||||
bytes = 1;
|
||||
else if (str[i] >= 0xE0 /*11100000 */ && str[i] <= 0xEF /*11101111 */ )
|
||||
bytes = 2;
|
||||
else if (str[i] >= 0xF0 /*11110000 */
|
||||
&& str[i] <= 0xF4 /* Cause of RFC 3629 */ )
|
||||
bytes = 3;
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
i += 1;
|
||||
while (i < len && bytes > 0 && str[i] >= 0x80 && str[i] <= 0xBF) {
|
||||
i += 1;
|
||||
bytes -= 1;
|
||||
}
|
||||
if (bytes != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
@ -15,7 +15,7 @@ static int to_str(void *item,char *dst)
|
||||
|
||||
|
||||
char *d = dst;
|
||||
int utf8 = cw_is_utf8(bstr16_data(i->data), bstr16_len(i->data));
|
||||
int utf8 = format_is_utf8(bstr16_data(i->data), bstr16_len(i->data));
|
||||
|
||||
|
||||
if (utf8) {
|
||||
|
@ -35,7 +35,7 @@ static int to_str(void *item,char *dst)
|
||||
char *d=dst;
|
||||
d+=sprintf(d,"%d,",bstrv_get_vendor_id(i->data));
|
||||
|
||||
if (cw_is_utf8(bstrv_data(i->data), bstrv_len(i->data))) {
|
||||
if (format_is_utf8(bstrv_data(i->data), bstrv_len(i->data))) {
|
||||
d += sprintf(d, "%.*s", bstrv_len(i->data),
|
||||
bstrv_data(i->data));
|
||||
} else {
|
||||
|
@ -1,36 +0,0 @@
|
||||
#include "capwap.h"
|
||||
|
||||
int cw_is_utf8(unsigned char *str, size_t len)
|
||||
{
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
size_t bytes = 0;
|
||||
|
||||
while (i < len) {
|
||||
j = i;
|
||||
if (str[i] < 0x20) {
|
||||
return 0;
|
||||
}
|
||||
if (str[i] <= 0x7F)
|
||||
bytes = 0;
|
||||
else if (str[i] >= 0xC0 /*11000000 */ && str[i] <= 0xDF /*11011111 */ )
|
||||
bytes = 1;
|
||||
else if (str[i] >= 0xE0 /*11100000 */ && str[i] <= 0xEF /*11101111 */ )
|
||||
bytes = 2;
|
||||
else if (str[i] >= 0xF0 /*11110000 */
|
||||
&& str[i] <= 0xF4 /* Cause of RFC 3629 */ )
|
||||
bytes = 3;
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
i += 1;
|
||||
while (i < len && bytes > 0 && str[i] >= 0x80 && str[i] <= 0xBF) {
|
||||
i += 1;
|
||||
bytes -= 1;
|
||||
}
|
||||
if (bytes != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user