2 * A collection of input filtering and validating functions for use in
3 * XForms dialogs. Mainly meant for filtering input boxes although may
4 * be extended to include other generally useful xforms-specific tools.
8 #include FORMS_H_LOCATION
9 #include "support/lstrings.h"
10 #include "input_validators.h"
12 #if defined(__cplusplus)
17 int fl_int_filter(FL_OBJECT * ob,
18 char const *, char const *, int c)
20 if (c == 0 /* final test before handing contents to app */
21 || strchr("0123456789+-", c)) {
22 if (isStrInt(fl_get_input(ob)))
25 return FL_INVALID|FL_RINGBELL;
29 int fl_unsigned_int_filter(FL_OBJECT * /*ob*/,
30 char const *, char const *, int c)
32 if (c == 0 /* final test before handing contents to app */
33 || strchr("0123456789", c)) {
34 /* since we only accept numerals then it must be valid */
37 return FL_INVALID|FL_RINGBELL;
41 int fl_float_filter(FL_OBJECT * ob,
42 char const *, char const *, int c)
44 if (c == 0 /* final test before handing contents to app */
45 || strchr("0123456789.+-", c)) {
46 if (isStrDbl(fl_get_input(ob)))
49 return FL_INVALID|FL_RINGBELL;
53 int fl_unsigned_float_filter(FL_OBJECT * ob,
54 char const * /*not_used*/,
55 char const * /*unused*/,
58 if (c == 0 /* final test before handing contents to app */
59 || strchr("0123456789.", c)) {
60 if (isStrDbl(fl_get_input(ob)))
63 return FL_INVALID|FL_RINGBELL;
67 int fl_lowercase_filter(FL_OBJECT * /*ob*/,
68 char const * /*not_used*/,
69 char const * /*unused*/,
72 if (c == 0 /* final test before handing contents to app */
73 || strchr("abcdefghijklmnopqrstuvwxyz0123456789", c)) {
74 /* since we only accept numerals then it must be valid */
77 return FL_INVALID|FL_RINGBELL;
82 /* I've just moved this code here and written a few comments.
83 still to complete it. ARRae 20000518 */
85 void fl_print_range_filter(FL_OBJECT * ob,
86 char const * not_used,
90 /* Started life as changes to PrintApplyCB by Stephan Witt
91 (stephan.witt@beusen.de), 19-Jan-99
92 User may give a page (range) list */
94 if (strchr("0123456789", c)) {
95 /* Numerals are always valid */
97 } else if (strchr("-,", c)) {
98 /* make sure that the character can go there */
100 /* final test before handing contents to app
101 make sure the last char isn't a "-,"
102 That might be acceptable if there was a "to_page"
103 entry however if you start making a page range in the "from"
104 field you can do it all in the "from" field. That is, a
105 range in the "from" field immmediately blanks the "to"
108 return FL_INVALID|FL_RINGBELL;
110 /* The code above should do the same sort of checking as the
113 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
114 pages = subst(pages, '+',',');
115 pages = frontStrip(strip(pages)) ;
116 while (!pages.empty()) { // a page range was given
118 pages = split (pages, piece, ',') ;
119 piece = strip(piece) ;
120 piece = frontStrip(piece) ;
121 if (!stringOnlyContains (piece, "0123456789-")) {
122 WriteAlert(_("ERROR! Unable to print!"),
123 _("Check 'range of pages'!"));
126 if (piece.find('-') == string::npos) { // not found
127 pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
128 } else if (suffixIs(piece, "-")) { // missing last page
129 pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
130 } else if (prefixIs(piece, "-")) { // missing first page
131 pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
133 pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
139 #if defined(__cplusplus)