Browse Source

Add function to check if value is word (\w+)

Alois Mahdal 9 years ago
parent
commit
97025fa740
2 changed files with 13 additions and 0 deletions
  1. 12
    0
      src/include/pretty.sh
  2. 1
    0
      test/tests/ffoo_api/oracle/functions.stdout

+ 12
- 0
src/include/pretty.sh View File

@@ -346,3 +346,15 @@ __echo_vars() {
346 346
         esac
347 347
     done
348 348
 }
349
+
350
+
351
+__is_word() {
352
+    #
353
+    # Check if $1 contains only alphanumeric chars or _
354
+    #
355
+    local tainted="$1"
356
+    local clean=$(tr -c -d '_[:alnum:]' <<< "$tainted")
357
+    debug "tainted='$tainted'"
358
+    debug "clean='$clean'"
359
+    test "$tainted" = "$clean"
360
+}

+ 1
- 0
test/tests/ffoo_api/oracle/functions.stdout View File

@@ -52,6 +52,7 @@ pretty.__echo_trace
52 52
 pretty.__echo_usage
53 53
 pretty.__echo_vars
54 54
 pretty.__ffoo_pretty__init
55
+pretty.__is_clean
55 56
 pretty.debug
56 57
 pretty.debug_pipe
57 58
 pretty.die