Changeset 18342
- Timestamp:
- 2009-01-09T18:16:31+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/unicode.pm
r18338 r18342 36 36 use strict; 37 37 use util; 38 use MIME::Base64; # for base64 encoding 38 39 39 40 no strict 'refs'; … … 629 630 } 630 631 632 sub base64_encode { 633 my ($text) = @_; 634 if(!is_safe_filename_chars($text)) { #if(!&is_base64_or_alphanumeric($text)) { # a subset 635 $text = &MIME::Base64::encode_base64($text); 636 } 637 return $text; 638 } 639 640 sub base64_decode { 641 my ($text) = @_; 642 # If the input fits the base64 pattern, this will try decoding it. 643 # Still, this does not guarantee the return value is the 'original' 644 if(&is_base64_or_alphanumeric($text)) { 645 $text = &MIME::Base64::decode_base64($text); 646 } 647 return $text; 648 } 649 650 # Returns through if the given string is compatible with base64 (which 651 # includes regular ASCII alphanumeric values). This method does not 652 # guarantee that base64_decoding will return anything meanigful, since 653 # this will return true for any simple alphanumeric ASCII string as well. 654 sub is_base64_or_alphanumeric { 655 my ($text) = @_; 656 # base 64 takes alphanumeric and [+/=] 657 # (note that in some cases - and _ replace + and /) 658 return ($text =~ m/^[A-Za-z0-9\+\/\=]+$/); 659 } 660 661 # Returns true if the text is base64 chars or additionally contains - and/or _ 662 sub is_safe_filename_chars { 663 my ($text) = @_; 664 return ($text =~ m/^[A-Za-z0-9\+\/\=\-\_]+$/); #alphanumeric,[+/=-_] 665 } 631 666 632 667 sub substr
Note:
See TracChangeset
for help on using the changeset viewer.