Commit dde25b3e authored by Lev Walkin's avatar Lev Walkin

xer_is_whitespace()

parent 867ac199
......@@ -137,7 +137,6 @@ static ssize_t
BOOLEAN__xer_body_decode(void *sptr, void *chunk_buf, size_t chunk_size) {
BOOLEAN_t *st = (BOOLEAN_t *)sptr;
char *p = (char *)chunk_buf;
char *pend = p + chunk_size;
if(chunk_size == 0) return -1;
......@@ -158,14 +157,8 @@ BOOLEAN__xer_body_decode(void *sptr, void *chunk_buf, size_t chunk_size) {
return -1;
}
} else {
for(; p < pend; p++) {
switch(*p) {
case 0x09: case 0x0a: case 0x0d: case 0x20:
break;
default:
return -1; /* Not whitespace */
}
}
if(!xer_is_whitespace(chunk_buf, chunk_size))
return -1;
}
return chunk_size;
......
......@@ -143,29 +143,6 @@ struct xdp_arg_s {
int want_more;
};
/*
* Check whether this buffer consists of entirely XER whitespace characters.
*/
static int
xer_decode__check_whitespace(void *chunk_buf, size_t chunk_size) {
char *p = (char *)chunk_buf;
char *pend = p + chunk_size;
for(; p < pend; p++) {
switch(*p) {
/* X.693, #8.1.4
* HORISONTAL TAB (9)
* LINE FEED (10)
* CARRIAGE RETURN (13)
* SPACE (32)
*/
case 0x09: case 0x0a: case 0x0d: case 0x20:
break;
default:
return 0;
}
}
return 1; /* All whitespace */
}
static int
xer_decode__unexpected_tag(void *key, void *chunk_buf, size_t chunk_size) {
......@@ -173,7 +150,7 @@ xer_decode__unexpected_tag(void *key, void *chunk_buf, size_t chunk_size) {
ssize_t decoded;
if(arg->decoded_something) {
if(xer_decode__check_whitespace(chunk_buf, chunk_size))
if(xer_is_whitespace(chunk_buf, chunk_size))
return chunk_size;
/*
* Decoding was done once already. Prohibit doing it again.
......@@ -197,7 +174,7 @@ xer_decode__body(void *key, void *chunk_buf, size_t chunk_size, int have_more) {
ssize_t decoded;
if(arg->decoded_something) {
if(xer_decode__check_whitespace(chunk_buf, chunk_size))
if(xer_is_whitespace(chunk_buf, chunk_size))
return chunk_size;
/*
* Decoding was done once already. Prohibit doing it again.
......
......@@ -290,3 +290,26 @@ xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
RETURN(RC_FAIL);
}
int
xer_is_whitespace(void *chunk_buf, size_t chunk_size) {
char *p = (char *)chunk_buf;
char *pend = p + chunk_size;
for(; p < pend; p++) {
switch(*p) {
/* X.693, #8.1.4
* HORISONTAL TAB (9)
* LINE FEED (10)
* CARRIAGE RETURN (13)
* SPACE (32)
*/
case 0x09: case 0x0a: case 0x0d: case 0x20:
break;
default:
return 0;
}
}
return 1; /* All whitespace */
}
......@@ -79,4 +79,12 @@ ssize_t xer_next_token(int *stateContext, void *buffer, size_t size,
xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
const char *need_tag);
/*
* Check whether this buffer consists of entirely XER whitespace characters.
* RETURN VALUES:
* 1: Whitespace or empty string
* 0: Non-whitespace
*/
int xer_is_whitespace(void *chunk_buf, size_t chunk_size);
#endif /* _XER_DECODER_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment