[system] / trunk / webwork2 / lib / WeBWorK / Utils.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/Utils.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 426 Revision 427
10our @EXPORT_OK = qw( 10our @EXPORT_OK = qw(
11 runtime_use 11 runtime_use
12 readFile 12 readFile
13 formatDateTime 13 formatDateTime
14 parseDateTime 14 parseDateTime
15 dbDecode
16 dbEncode
15 ref2string 17 ref2string
16 hash2string 18 hash2string
17 array2string 19 array2string
18); 20);
19 21
46} 48}
47 49
48sub parseDateTime($) { 50sub parseDateTime($) {
49 my $string = shift; 51 my $string = shift;
50 return str2time $string; 52 return str2time $string;
53}
54
55sub dbDecode($) {
56 my $string = shift;
57 return unless defined $string and $string;
58 my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g;
59 $hash{$_} =~ s/\\(&|=)/$1/g foreach (keys %hash); # unescape & and =
60 return %hash;
61}
62
63sub dbEncode(@) {
64 my %hash = @_;
65 my $string;
66 foreach (keys %hash) {
67 $hash{$_} = "" unless defined $hash{$_}; # promote undef to ""
68 $hash{$_} =~ s/(=|&)/\\$1/g; # escape & and =
69 $string .= "$_=$hash{$_}&";
70 }
71 chop $string; # remove final '&' from string for old code :p
72 return $string;
51} 73}
52 74
53# ----- 75# -----
54 76
55sub ref2string($;$); 77sub ref2string($;$);

Legend:
Removed from v.426  
changed lines
  Added in v.427

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9