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.
10 #include FORMS_H_LOCATION
11 #include "support/lstrings.h"
12 #include "input_validators.h"
14 #if defined(__cplusplus)
19 int fl_int_filter(FL_OBJECT * ob,
20 char const *, char const *, int c)
22 if (c == 0 /* final test before handing contents to app */
23 || strchr("0123456789+-", c)) {
24 if (isStrInt(fl_get_input(ob)))
27 return FL_INVALID|FL_RINGBELL;
31 int fl_unsigned_int_filter(FL_OBJECT * /*ob*/,
32 char const *, char const *, int c)
34 if (c == 0 /* final test before handing contents to app */
35 || strchr("0123456789", c)) {
36 /* since we only accept numerals then it must be valid */
39 return FL_INVALID|FL_RINGBELL;
43 int fl_float_filter(FL_OBJECT * ob,
44 char const *, char const *, int c)
46 if (c == 0 /* final test before handing contents to app */
47 || strchr("0123456789.+-", c)) {
48 if (isStrDbl(fl_get_input(ob)))
51 return FL_INVALID|FL_RINGBELL;
55 int fl_unsigned_float_filter(FL_OBJECT * ob,
56 char const * /*not_used*/,
57 char const * /*unused*/,
60 if (c == 0 /* final test before handing contents to app */
61 || strchr("0123456789.", c)) {
62 if (isStrDbl(fl_get_input(ob)))
65 return FL_INVALID|FL_RINGBELL;
69 int fl_lowercase_filter(FL_OBJECT * /*ob*/,
70 char const * /*not_used*/,
71 char const * /*unused*/,
74 if (c == 0 /* final test before handing contents to app */
75 || strchr("abcdefghijklmnopqrstuvwxyz0123456789", c)) {
76 /* since we only accept numerals then it must be valid */
79 return FL_INVALID|FL_RINGBELL;
84 /* I've just moved this code here and written a few comments.
85 still to complete it. ARRae 20000518 */
87 void fl_print_range_filter(FL_OBJECT * ob,
88 char const * not_used,
92 /* Started life as changes to PrintApplyCB by Stephan Witt
93 (stephan.witt@beusen.de), 19-Jan-99
94 User may give a page (range) list */
96 if (strchr("0123456789", c)) {
97 /* Numerals are always valid */
99 } else if (strchr("-,", c)) {
100 /* make sure that the character can go there */
102 /* final test before handing contents to app
103 make sure the last char isn't a "-,"
104 That might be acceptable if there was a "to_page"
105 entry however if you start making a page range in the "from"
106 field you can do it all in the "from" field. That is, a
107 range in the "from" field immmediately blanks the "to"
110 return FL_INVALID|FL_RINGBELL;
112 /* The code above should do the same sort of checking as the
115 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
116 pages = trim(subst(pages, '+', ','));
118 while (!pages.empty()) { // a page range was given
120 pages = split (pages, piece, ',') ;
122 if (!stringOnlyContains (piece, "0123456789-")) {
123 Alert::alert(_("ERROR! Unable to print!"),
124 _("Check `range of pages'!"));
127 if (piece.find('-') == string::npos) { // not found
128 pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
129 } else if (suffixIs(piece, "-")) { // missing last page
130 pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
131 } else if (prefixIs(piece, "-")) { // missing first page
132 pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
134 pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
140 #if defined(__cplusplus)