aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorStephen Fisher <steve@stephen-fisher.com>2012-02-17 17:22:12 +0000
committerStephen Fisher <steve@stephen-fisher.com>2012-02-17 17:22:12 +0000
commit7a5294707533166dc657a6e3373e2b30adcefefb (patch)
tree9f9cb2c3f20f77cd2cc2d854cb30cdc41102fb9b /wsutil
parentd205085350663e7cb6b086226620151d8a3d868d (diff)
Move exec_isdigit_string() and exec_isprint_string() functions out of
the exec dissector and into wsutil/str_util.c. Rename them to isdigit_string() and isprint_string(). Also rename the variables they use for consistency: string -> str and position -> pos. svn path=/trunk/; revision=41053
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/libwsutil.def2
-rw-r--r--wsutil/str_util.c38
-rw-r--r--wsutil/str_util.h14
3 files changed, 54 insertions, 0 deletions
diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def
index 4d811c098c..c76e646d22 100644
--- a/wsutil/libwsutil.def
+++ b/wsutil/libwsutil.def
@@ -88,6 +88,8 @@ strptime
; str_util.c
ascii_strdown_inplace
ascii_strup_inplace
+isprint_string
+isdigit_string
; type_util.c
type_util_gdouble_to_guint64
diff --git a/wsutil/str_util.c b/wsutil/str_util.c
index e94fec9046..717fcb516d 100644
--- a/wsutil/str_util.c
+++ b/wsutil/str_util.c
@@ -29,6 +29,8 @@
#include <glib.h>
#include "str_util.h"
+#include <ctype.h>
+
/* Convert all ASCII letters to lower case, in place. */
gchar *
ascii_strdown_inplace(gchar *str)
@@ -52,3 +54,39 @@ ascii_strup_inplace(gchar *str)
return (str);
}
+
+/* Check if an entire string is printable. */
+gboolean
+isprint_string(guchar *str)
+{
+ guint pos;
+
+ /* Loop until we reach the end of the string (a null) */
+ for(pos = 0; str[pos] != '\0'; pos++){
+ if(!isprint(str[pos])){
+ /* The string contains a non-printable character */
+ return FALSE;
+ }
+ }
+
+ /* The string contains only printable characters */
+ return TRUE;
+}
+
+/* Check if an entire string is digits. */
+gboolean
+isdigit_string(guchar *str)
+{
+ guint pos;
+
+ /* Loop until we reach the end of the string (a null) */
+ for(pos = 0; str[pos] != '\0'; pos++){
+ if(!isdigit(str[pos])){
+ /* The string contains a non-digit character */
+ return FALSE;
+ }
+ }
+
+ /* The string contains only digits */
+ return TRUE;
+}
diff --git a/wsutil/str_util.h b/wsutil/str_util.h
index cbc6f2bad5..63537183fd 100644
--- a/wsutil/str_util.h
+++ b/wsutil/str_util.h
@@ -59,4 +59,18 @@ gchar *ascii_strdown_inplace(gchar *str);
*/
gchar *ascii_strup_inplace(gchar *str);
+/** Check if an entire string consists of printable characters
+ *
+ * @param str The string to be checked
+ * @return TRUE if the entire string is printable, otherwise FALSE
+ */
+gboolean isprint_string(guchar *string);
+
+/** Check if an entire string consists of digits
+ *
+ * @param str The string to be checked
+ * @return TRUE if the entire string is digits, otherwise FALSE
+ */
+gboolean isdigit_string(guchar *string);
+
#endif /* __STR_UTIL_H__ */