Log Message:
-----------
Restored str_filters -- removing it broke some of the other answer evaluators.
str_filters takes a string, filters it and then returns the filtered string.
The actual filters have been changed to work with answer hashes rather than with
strings, so str_filters warps the string in an answer hash before sending it through
the filters.
sorry for the breakage.
-- Mike
Modified Files:
--------------
pg/macros:
PGanswermacros.pl
Revision Data
-------------
Index: PGanswermacros.pl
===================================================================
RCS file: /webwork/cvs/system/pg/macros/PGanswermacros.pl,v
retrieving revision 1.31
retrieving revision 1.32
diff -Lmacros/PGanswermacros.pl -Lmacros/PGanswermacros.pl -u -r1.31 -r1.32
--- macros/PGanswermacros.pl
+++ macros/PGanswermacros.pl
@@ -2080,47 +2080,52 @@
## Use this subroutine instead of the
## individual filters below it
-# sub str_filters {
-# my $stringToFilter = shift @_;
-# my @filters_to_use = @_;
-# my %known_filters = (
-# 'remove_whitespace' => &remove_whitespace,
-# 'compress_whitespace' => &compress_whitespace,
-# 'trim_whitespace' => &trim_whitespace,
-# 'ignore_case' => &ignore_case,
-# 'ignore_order' => &ignore_order,
-# );
-#
-# #test for unknown filters
-# foreach my $filter ( @filters_to_use ) {
-# #check that filter is known
-# die "Unknown string filter $filter (try checking the parameters to str_cmp() )"
-# unless exists $known_filters{$filter};
-# $stringToFilter = $known_filters{$filter}($stringToFilter); # apply filter.
-# }
+sub str_filters {
+ my $stringToFilter = shift @_;
+ # filters now take an answer hash, so encapsulate the string
+ # in the answer hash.
+ my $rh_ans = new AnswerHash;
+ $rh_ans->{student_ans} = $stringToFilter;
+ $rh_ans->{correct_ans}='';
+ my @filters_to_use = @_;
+ my %known_filters = (
+ 'remove_whitespace' => \&remove_whitespace,
+ 'compress_whitespace' => \&compress_whitespace,
+ 'trim_whitespace' => \&trim_whitespace,
+ 'ignore_case' => \&ignore_case,
+ 'ignore_order' => \&ignore_order,
+ );
+
+ #test for unknown filters
+ foreach my $filter ( @filters_to_use ) {
+ #check that filter is known
+ die "Unknown string filter $filter (try checking the parameters to str_cmp() )"
+ unless exists $known_filters{$filter};
+ $rh_ans = $known_filters{$filter}($rh_ans); # apply filter.
+ }
# foreach $filter (@filters_to_use) {
# die "Unknown string filter $filter (try checking the parameters to str_cmp() )"
# unless exists $known_filters{$filter};
# }
#
# if( grep( /remove_whitespace/i, @filters_to_use ) ) {
-# $stringToFilter = remove_whitespace( $stringToFilter );
+# $rh_ans = remove_whitespace( $rh_ans );
# }
# if( grep( /compress_whitespace/i, @filters_to_use ) ) {
-# $stringToFilter = compress_whitespace( $stringToFilter );
+# $rh_ans = compress_whitespace( $rh_ans );
# }
# if( grep( /trim_whitespace/i, @filters_to_use ) ) {
-# $stringToFilter = trim_whitespace( $stringToFilter );
+# $rh_ans = trim_whitespace( $rh_ans );
# }
# if( grep( /ignore_case/i, @filters_to_use ) ) {
-# $stringToFilter = ignore_case( $stringToFilter );
+# $rh_ans = ignore_case( $rh_ans );
# }
# if( grep( /ignore_order/i, @filters_to_use ) ) {
-# $stringToFilter = ignore_order( $stringToFilter );
+# $rh_ans = ignore_order( $rh_ans );
# }
-# return $stringToFilter;
-# }
+ return $rh_ans->{student_ans};
+}
sub remove_whitespace {
my $rh_ans = shift;
die "expected an answer hash" unless ref($rh_ans)=~/HASH/i;
@@ -2632,14 +2637,14 @@
my $correctQ = ($in eq $correctAnswer) ? 1: 0;
my $ans_hash = new AnswerHash(
- 'score' => $correctQ,
- 'correct_ans' => "$correctAnswer",
- 'student_ans' => $in,
- 'ans_message' => "",
- 'type' => "checkbox_cmp",
- 'preview_text_string' => $in,
- 'preview_latex_string' => $in,
- 'original_student_ans' => $original_student_ans
+ 'score' => $correctQ,
+ 'correct_ans' => "$correctAnswer",
+ 'student_ans' => $in,
+ 'ans_message' => "",
+ 'type' => "checkbox_cmp",
+ 'preview_text_string' => $in,
+ 'preview_latex_string' => $in,
+ 'original_student_ans' => $original_student_ans
);
return $ans_hash;
|