Artifact a2f9f516074ecb1550557c2031afac33025396d3:
- File
library/ATWF/Filters/HtmlEntities.tcl
— part of check-in
[72081dd817]
at
2010-12-02 14:20:47
on branch trunk
— fixed type ditcs to dicts
git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@584 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db (user: arnulf@wiedemann-pri.de size: 4848)
#************************************************************************* #* #* $Author$ #* $URL$ #* #* This module has been implemented in Tcl by using mostly the corresponding module #* Filter/HtmlEntities.php from the Zend framework see: http://framework.zend.com #* So the ideas are also copyrighted by Zend Technologies USA Inc. (http://www.zend.com) #* The implementation in Tcl uses dicts and lists instead of php arrays. #* #* The Contents of this file are made available subject to the terms of #* the following license see @license below #* #* Copyright 2010 Arnulf Wiedemann #* #* Author: Arnulf Wiedemann #* #* Contributor(s): #* # @category ATWF # @package library # @subpackage Filters # @license BSD License (see file license.terms in the source top drectory) # @version $Id$ #************************************************************************/ namespace eval ::ATWF { ::itcl::extendedclass Filters::HtmlEntities { inherit ::ATWF::Filter # Corresponds to the second htmlentities() argument # # @variable integer protected variable _quoteStyle [list] # Corresponds to the third htmlentities() argument # # @variable string protected variable _charSet [list] # Corresponds to the forth htmlentities() argument # # @variable unknown_type protected variable _doubleQuote [list] constructor {{options {}}} {} public method getQuoteStyle {} public method setQuoteStyle {quoteStyle} public method getCharSet {} public method setCharSet {charSet} public method getDoubleQuote {} public method setDoubleQuote {doubleQuote} public method filter {value} } #============================ constructor ==================================== # Sets filter options # # @param integer|array $quoteStyle # @param string $charSet # @return void ::itcl::body Filters::HtmlEntities::constructor {{options {}}} { if {[::itcl::is object $options]} { return -code error "Support for multiple arguments is deprecated in favor of a single options array E_USER_NOTICE" set temp [dict create] set argv [func_get_args] dict set temp quotestyle [array_shift $options] if {$argv ne ""} { dict set tempcharset [array_shift $options] } set options $temp } if {![dict exists $options quotestyle]} { diect set options quotestyle ENT_COMPAT } if {![dict exists $options charset]} { dict set options charset "ISO-8859-1" } if {![dict exists $options doublequote]} { dict set options doublequote true } setQuoteStyle [dict get $options quotestyle] setCharSet [dict get $options charset] setDoubleQuote [dict get $options doublequote] } #============================ getQuoteStyle ================================== # Returns the quoteStyle option # # @return integer ::itcl::body Filters::HtmlEntities::getQuoteStyle {} { return $_quoteStyle } #============================ setQuoteStyle ================================== # Sets the quoteStyle option # # @param integer $quoteStyle # @return Filters::HtmlEntities Provides a fluent interface ::itcl::body Filters::HtmlEntities::setQuoteStyle {quoteStyle} { set _quoteStyle $quoteStyle return $this } #============================ getCharSet ===================================== # Returns the charSet option # # @return string ::itcl::body Filters::HtmlEntities::getCharSet {} { return $_charSet } #============================ setCharSet ===================================== # Sets the charSet option # # @param string $charSet # @return Filters::HtmlEntities Provides a fluent interface ::itcl::body Filters::HtmlEntities::setCharSet {charSet} { set _charSet $charSet return $this } #============================ getDoubleQuote ================================= # Returns the doubleQuote option # # @return boolean ::itcl::body Filters::HtmlEntities::getDoubleQuote {} { return $_doubleQuote } #============================ setDoubleQuote ================================= # Sets the doubleQuote option # # @param boolean $doubleQuote # @return Filters::HtmlEntities Provides a fluent interface ::itcl::body Filters::HtmlEntities::setDoubleQuote {doubleQuote} { set _doubleQuote $doubleQuote return $this } #============================ filter ========================================= # Defined by Filter # # Returns the string $value, converting characters to their corresponding HTML entity # equivalents where they exist # # @param string $value # @return string ::itcl::body Filters::HtmlEntities::filter {value} { return [htmlentities $value $_quoteStyle $_charSet $_doubleQuote] } } ; # END ::ATWF