This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit db18f67e4aa29737ff417edd2e88581a8e46e048
Author: Massimo Manghi <mxman...@apache.org>
AuthorDate: Tue Sep 12 00:46:38 2023 +0200

    update formbroker documentation
---
 doc/xml/commands.xml                     |  2 +-
 doc/xml/formbroker.xml                   | 45 +++++++++++++++++++++
 rivet/packages/formbroker/formbroker.tcl | 68 +++++++++++++++++++++++++-------
 3 files changed, 100 insertions(+), 15 deletions(-)

diff --git a/doc/xml/commands.xml b/doc/xml/commands.xml
index c17668e..a52cbcc 100644
--- a/doc/xml/commands.xml
+++ b/doc/xml/commands.xml
@@ -865,7 +865,7 @@
                 value in which every content preference is matched to its
                 precedence value
             </para>
-            <programlisting>load_headers
+            <programlisting>::rivet::load_headers
 set language_precedence [::rivet::http_accept $headers(Accept-Language)]
 foreach lan [dict keys $language_precedence] {
                 puts "$lan -> [dict get $language_precedence $lan]"
diff --git a/doc/xml/formbroker.xml b/doc/xml/formbroker.xml
index 6ea64ab..3070bdf 100644
--- a/doc/xml/formbroker.xml
+++ b/doc/xml/formbroker.xml
@@ -315,6 +315,51 @@ a(var4) = 0</programlisting>
 
             </variablelist>
         </refsect1>
+        <refsect1>
+                       <title>Validator Error codes</title>
+                       <para>
+                               Variable type validators returned specific code
+                               <itemizedlist>
+                                       <listitem><emphasis>string</emphasis>:
+                                               <itemizedlist>
+                                                       
<listitem><emphasis>FB_EMPTY_STRING</emphasis> if
+                                                       the variable descriptor 
has the 'nonempty' flag set and the
+                                                       trimmed string is 
empty</listitem>
+                                                       
<listitem><emphasis>FB_STRING_TOO_LONG</emphasis> if the string
+                                                       length exceeds the max 
string length set with the maxlength option.
+                                                       This error is not 
returned if maxlength was not set</listitem>
+                                               </itemizedlist>
+                                       </listitem>
+                                       <listitem><emphasis>integer</emphasis>:
+                                               <itemizedlist>
+                                                       
<listitem><emphasis>FB_OUT_OF_BOUNDS</emphasis> if
+                                                       bounds were assigned to 
the variable but it's value lies outside of them.
+                                                       This error is not 
returned if bounds were not set or the
+                                                       variable was defined 
with the flag <emphasis>constrain</emphasis>
+                                                       which forces its value 
to be the closest boundary value</listitem>
+                                               </itemizedlist>
+                                       </listitem>
+                                       <listitem>
+                                               <emphasis>unsigned</emphasis>:
+                                               <itemizedlist>
+                                                       
<listitem><emphasis>FB_OUT_OF_BOUNDS</emphasis> the variable
+                                                       value is either 
negative or outside the bounds assigned to the
+                                                       variable descriptor. 
The error is not returned if the
+                                                       variable was defined 
with the flag <emphasis>constrain</emphasis>
+                                                       which forces its value 
to be the closest boundary value</listitem>
+                                                       or set to zero if the 
value was negative
+                                               </itemizedlist>
+                                               </listitem>     
+                                       <listitem>
+                                               <emphasis>email</emphasis>:
+                                               <itemizedlist>
+                                                       
<listitem><emphasis>FB_INVALID_EMAIL</emphasis> the variable is
+                                                       an invalid email 
address representation</listitem>
+                                               </itemizedlist>
+                                               </listitem>     
+                               </itemizedlist>
+                       </para>
+        </refsect1>
         <refsect1>
             <title>Writing a custom variable validator</title>
             <para>
diff --git a/rivet/packages/formbroker/formbroker.tcl 
b/rivet/packages/formbroker/formbroker.tcl
index f81363f..e32fc9e 100644
--- a/rivet/packages/formbroker/formbroker.tcl
+++ b/rivet/packages/formbroker/formbroker.tcl
@@ -128,6 +128,18 @@ namespace eval FormBroker {
     }
     
     # -- base validators
+    #
+    # 
+
+    # -- validate_string
+    #
+    # returned error codes
+    #
+    #   - FB_EMPTY_STRING: error condition ignored if
+    #   variable descriptor has the 'noempty' flag set
+    #   - FB_STRING_TOO_LONG: error condition ignored if
+    #   variable descriptor has the 'constrain' flag set
+    #
     
     proc validate_string {_var_d} {
         upvar $_var_d var_d
@@ -158,6 +170,15 @@ namespace eval FormBroker {
     #
     # If needed the variable is constrained within the bounds.
     # 
+    # Returned error codes:
+    #
+    #   - FB_OUT_OF_BOUNDS: the integer value lies outside the 
+    #   bounds set in the variable descriptor. Ths error condition
+    #   ignored if the 'constrain' flag is set and the bounded
+    #   variable value is returned instead
+    #   - NOT_INTEGER: the variable value is not an integer
+    #   as checked by the [string is integer <variable value>]
+    #   command
 
     proc validate_integer {_var_d} {
         upvar $_var_d var_d
@@ -199,27 +220,40 @@ namespace eval FormBroker {
         return $valid
     }
 
+    # -- validate_unsigned
+    #
+    # see validate_integer
+    # 
+    # Returned error code:
+    #
+    #   - NOT_INTEGER: the variable value is not an integer
+    #   as checked by the [string is integer <variable value>]
+    #   command
+    #   - FB_OUT_OF_BOUNDS: the value is negative or out of
+    #   the bounds set in the descriptor
+    #   
+
     proc validate_unsigned {_var_d} {
         upvar $_var_d var_d
 
+        set valid FB_OK
         dict with var_d {
             if {![string is integer $var]} {
                 return NOT_INTEGER
             }
+
             if {[llength $bounds] == 2} {
                 ::lassign $bounds min_v max_v
+
                 if {$constrain} {
                     set var [expr min($var,$max_v)]
                     set var [expr max($var,$min_v)]
                     set valid FB_OK
                 } elseif {($var > $max_v) || ($var < $min_v)} {
                     set valid FB_OUT_OF_BOUNDS
-                } else {
-                    set valid FB_OK
-                }
+                } 
 
-            } elseif {([llength $bounds] == 1) && \
-                      ($bounds > 0)} {
+            } elseif {([llength $bounds] == 1) && ($bounds > 0)} {
                 
                 if {$constrain} {
                     set var [expr max(0,$var)]
@@ -227,9 +261,7 @@ namespace eval FormBroker {
                     set valid FB_OK
                 } elseif {($var > $bounds) || ($var < 0)} {
                     set valid FB_OUT_OF_BOUNDS
-                } else {
-                    set valid FB_OK
-                }
+                } 
 
             } else {
 
@@ -238,15 +270,18 @@ namespace eval FormBroker {
                     set valid FB_OK
                 } elseif {$var < 0} {
                     set valid FB_OUT_OF_BOUNDS
-                } else {
-                    set valid FB_OK
-                }
+                } 
 
             }
         }
         return $valid
     }
 
+    # -- validate_email
+    #
+    # Returned error code: FB_INVALID_EMAIL
+    #
+
     proc validate_email {_var_d} {
         upvar $_var_d var_d
 
@@ -259,14 +294,18 @@ namespace eval FormBroker {
         }
     }
 
+    # -- validate_boolean
+    #
+    # checks in the variable descriptor whether the variable
+    # representation is a valid boolean representation
+    #
+    # Returned error code: FB_INVALID_BOOLEAN
+
     proc validate_boolean {_var_d} {
         upvar $_var_d var_d
 
         dict with var_d {
             if {[string is boolean $var]} {
-                if {$constrain} {
-                    set var [string is true $var]
-                }
                 return FB_OK
             } else {
                 return FB_INVALID_BOOLEAN
@@ -344,6 +383,7 @@ namespace eval FormBroker {
                     if {$l2 < 0} { set l2 0 }
 
                     set bounds [list [expr min($l1,$l2)] [expr max($l1,$l2)]]
+
                 } else {
                     set bounds 0
                 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@tcl.apache.org
For additional commands, e-mail: commits-h...@tcl.apache.org

Reply via email to