@@ -4,48 +4,38 @@ function get_html_translation_table(table, quote_style) {
44 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
55 // % note: It has been decided that we're not going to add global
66 // % note: dependencies to php.js. Meaning the constants are not
7- // % note: real constants.
8- // * example 1: get_html_translation_table('Kevin van Zonneveld');
9- // * returns 1: 1249991249
7+ // % note: real constants, but strings instead. integers are also supported if someone
8+ // % note: chooses to create the constants themselves.
9+ // % note: Table from http://www.the-art-of-web.com/html/character-codes/
10+ // * example 1: get_html_translation_table('HTML_SPECIALCHARS');
11+ // * returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'}
1012
11- var constMapping = { } , entities = { } , decimal = 0 , symbol = '' ;
13+ var entities = { } , histogram = { } , decimal = 0 , symbol = '' ;
14+ var constMappingTable = { } , constMappingQuoteStyle = { } ;
1215 var useTable = table , useQuoteStyle = quote_style ;
13-
16+
1417 // Translate arguments
15- constMapping [ 'table' ] [ 0 ] = 'HTML_SPECIALCHARS' ;
16- constMapping [ 'table' ] [ 1 ] = 'HTML_ENTITIES' ;
17- constMapping [ 'quote_style' ] [ 0 ] = 'ENT_NOQUOTES' ;
18- constMapping [ 'quote_style' ] [ 2 ] = 'ENT_COMPAT' ;
19- constMapping [ 'quote_style' ] [ 3 ] = 'ENT_QUOTES' ;
18+ constMappingTable [ 0 ] = 'HTML_SPECIALCHARS' ;
19+ constMappingTable [ 1 ] = 'HTML_ENTITIES' ;
20+ constMappingQuoteStyle [ 0 ] = 'ENT_NOQUOTES' ;
21+ constMappingQuoteStyle [ 2 ] = 'ENT_COMPAT' ;
22+ constMappingQuoteStyle [ 3 ] = 'ENT_QUOTES' ;
2023
21- // Map
22- if ( constMapping [ 'table' ] [ useTable ] ) {
23- useTable = constMapping [ 'table' ] [ useTable ] ;
24+ // Map or Default
25+ if ( ! ( useTable = constMappingTable [ useTable ] ) ) {
26+ useTable = 'HTML_SPECIALCHARS'
2427 }
25- if ( constMapping [ 'quote_style' ] [ useQuoteStyle ] ) {
26- useQuoteStyle = constMapping [ 'quote_style' ] [ useQuoteStyle ] ;
28+ if ( ! ( useQuoteStyle = constMappingQuoteStyle [ useQuoteStyle ] ) ) {
29+ useQuoteStyle = 'ENT_COMPAT' ;
2730 }
2831
29- // Default
30- if ( ! useTable ) useTable = 'HTML_SPECIALCHARS' ;
31- if ( ! useQuoteStyle ) useQuoteStyle = 'ENT_COMPAT' ;
32-
3332 if ( useTable == 'HTML_SPECIALCHARS' ) {
3433 // ascii decimals for better compatibility
3534 entities [ '60' ] = '<' ;
3635 entities [ '62' ] = '>' ;
3736 entities [ '38' ] = '&' ;
38-
39- if ( quote_style != 'ENT_QUOTES' ) {
40- entities [ '34' ] = '"' ;
41- }
42-
43- if ( quote_style == 'ENT_QUOTES' ) {
44- entities [ '39' ] = ''' ;
45- }
4637 } else if ( useTable == 'HTML_ENTITIES' ) {
4738 // ascii decimals for better compatibility
48- entities [ '34' ] = '"' ;
4939 entities [ '38' ] = '&' ;
5040 entities [ '60' ] = '<' ;
5141 entities [ '62' ] = '>' ;
@@ -148,7 +138,15 @@ function get_html_translation_table(table, quote_style) {
148138 } else {
149139 return false ;
150140 }
151-
141+
142+ if ( useQuoteStyle != 'ENT_QUOTES' ) {
143+ entities [ '34' ] = '"' ;
144+ }
145+
146+ if ( useQuoteStyle == 'ENT_QUOTES' ) {
147+ entities [ '39' ] = ''' ;
148+ }
149+
152150 // ascii decimals to real symbols
153151 for ( decimal in entities ) {
154152 symbol = String . fromCharCode ( decimal )
0 commit comments