xer_is_whitespace()


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@534 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/skeletons/BOOLEAN.c b/skeletons/BOOLEAN.c
index cfecd49..7473b62 100644
--- a/skeletons/BOOLEAN.c
+++ b/skeletons/BOOLEAN.c
@@ -137,7 +137,6 @@
 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 @@
 			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;
diff --git a/skeletons/asn_codecs_prim.c b/skeletons/asn_codecs_prim.c
index e6725b3..089e54e 100644
--- a/skeletons/asn_codecs_prim.c
+++ b/skeletons/asn_codecs_prim.c
@@ -143,29 +143,6 @@
 	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 @@
 	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 @@
 	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.
diff --git a/skeletons/xer_decoder.c b/skeletons/xer_decoder.c
index 9cbccf8..b7bc83b 100644
--- a/skeletons/xer_decoder.c
+++ b/skeletons/xer_decoder.c
@@ -290,3 +290,26 @@
 	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 */
+}
+
diff --git a/skeletons/xer_decoder.h b/skeletons/xer_decoder.h
index b8aef66..1c26ef7 100644
--- a/skeletons/xer_decoder.h
+++ b/skeletons/xer_decoder.h
@@ -79,4 +79,12 @@
 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_ */