summaryrefslogtreecommitdiff
path: root/wsutil/str_util.c
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/str_util.c
parentd205085350663e7cb6b086226620151d8a3d868d (diff)
downloadwireshark-7a5294707533166dc657a6e3373e2b30adcefefb.tar.gz
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/str_util.c')
-rw-r--r--wsutil/str_util.c38
1 files changed, 38 insertions, 0 deletions
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;
+}