← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:10 2015

Filename/var/www/foswiki11/lib/Foswiki/Plugins/WysiwygPlugin/Constants.pm
StatementsExecuted 26 statements in 1.97ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.65ms5.24msFoswiki::Plugins::WysiwygPlugin::Constants::::BEGIN@8Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@8
11128µs131µsFoswiki::Plugins::WysiwygPlugin::Constants::::BEGIN@7Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@7
11122µs41µsFoswiki::Plugins::WysiwygPlugin::Constants::::BEGIN@4Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@4
11117µs39µsFoswiki::Plugins::WysiwygPlugin::Constants::::BEGIN@9Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@9
11116µs34µsFoswiki::Plugins::WysiwygPlugin::Constants::::BEGIN@359Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@359
11114µs22µsFoswiki::Plugins::WysiwygPlugin::Constants::::BEGIN@5Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@5
0000s0sFoswiki::Plugins::WysiwygPlugin::Constants::::chCodesFoswiki::Plugins::WysiwygPlugin::Constants::chCodes
0000s0sFoswiki::Plugins::WysiwygPlugin::Constants::::convertNotRepresentabletoEntityFoswiki::Plugins::WysiwygPlugin::Constants::convertNotRepresentabletoEntity
0000s0sFoswiki::Plugins::WysiwygPlugin::Constants::::decodeRepresentableEntitiesFoswiki::Plugins::WysiwygPlugin::Constants::decodeRepresentableEntities
0000s0sFoswiki::Plugins::WysiwygPlugin::Constants::::encodingFoswiki::Plugins::WysiwygPlugin::Constants::encoding
0000s0sFoswiki::Plugins::WysiwygPlugin::Constants::::reinitialiseForTestingFoswiki::Plugins::WysiwygPlugin::Constants::reinitialiseForTesting
0000s0sFoswiki::Plugins::WysiwygPlugin::Constants::::safeEntitiesFoswiki::Plugins::WysiwygPlugin::Constants::safeEntities
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2package Foswiki::Plugins::WysiwygPlugin::Constants;
3
4241µs261µs
# spent 41µs (22+20) within Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@4 which was called: # once (22µs+20µs) by Foswiki::Plugins::WysiwygPlugin::Handlers::BEGIN@18 at line 4
use strict;
# spent 41µs making 1 call to Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@4 # spent 20µs making 1 call to strict::import
5237µs230µs
# spent 22µs (14+8) within Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@5 which was called: # once (14µs+8µs) by Foswiki::Plugins::WysiwygPlugin::Handlers::BEGIN@18 at line 5
use warnings;
# spent 22µs making 1 call to Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@5 # spent 8µs making 1 call to warnings::import
6
7251µs2235µs
# spent 131µs (28+104) within Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@7 which was called: # once (28µs+104µs) by Foswiki::Plugins::WysiwygPlugin::Handlers::BEGIN@18 at line 7
use Encode;
# spent 131µs making 1 call to Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@7 # spent 104µs making 1 call to Exporter::import
82270µs25.28ms
# spent 5.24ms (4.65+593µs) within Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@8 which was called: # once (4.65ms+593µs) by Foswiki::Plugins::WysiwygPlugin::Handlers::BEGIN@18 at line 8
use HTML::Entities;
# spent 5.24ms making 1 call to Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@8 # spent 40µs making 1 call to Exporter::import
921.33ms261µs
# spent 39µs (17+22) within Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@9 which was called: # once (17µs+22µs) by Foswiki::Plugins::WysiwygPlugin::Handlers::BEGIN@18 at line 9
use Assert;
# spent 39µs making 1 call to Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@9 # spent 22µs making 1 call to Assert::import
10
11# HTML elements that are strictly block type, as defined by
12# http://www.htmlhelp.com/reference/html40/block.html.
13# Block type elements do not require
14# <br /> to be generated for newlines on the boundary - see WC::isInline.
15128µsour %ALWAYS_BLOCK = map { $_ => 1 }
16 qw( ADDRESS BLOCKQUOTE CENTER DIR DIV DL FIELDSET FORM H1 H2 H3 H4 H5 H6
17 HR ISINDEX MENU NOFRAMES NOSCRIPT OL P PRE TABLE UL );
1818µsour $ALWAYS_BLOCK_S = join( '|', keys %ALWAYS_BLOCK );
19
20# STARTWW should match Foswiki::Render, execpt need to include protected whitespace spans.
21111µsour $STARTWW =
22 qr/^|(?<=[ \t\n\(])|(?<=<p>)|(?<=nbsp;<\/span>)|(?<=160;<\/span>)/om;
2311µsour $ENDWW = qr/$|(?=[ \t\n\,\.\;\:\!\?\)])|(?=<\/p>)|(?=<span\b[^>]*> )/om;
2411µsour $PROTOCOL = qr/^(file|ftp|gopher|https?|irc|news|nntp|telnet|mailto):/;
25
26# Colours with colour settings in DefaultPreferences.
2714µsour @TML_COLOURS = (
28 'BLACK', 'MAROON', 'PURPLE', 'PINK', 'RED', 'ORANGE',
29 'YELLOW', 'LIME', 'AQUA', 'AQUAMARINE', 'GREEN', 'OLIVE',
30 'BROWN', 'NAVY', 'TEAL', 'BLUE', 'GRAY', 'SILVER',
31 'WHITE',
32);
33
34# Map of possible colours back to TML %COLOUR%...%ENDCOLOR%
35125µsour %HTML2TML_COLOURMAP = (
36 BLACK => 'BLACK',
37 '#000000' => 'BLACK',
38 MAROON => 'MAROON',
39 '#800000' => 'MAROON',
40 PURPLE => 'PURPLE',
41 '#800080' => 'PURPLE',
42 FUCHSIA => 'PINK',
43 '#FF00FF' => 'PINK',
44 RED => 'RED',
45 '#FF0000' => 'RED',
46 ORANGE => 'ORANGE',
47 '#FF6600' => 'ORANGE',
48 YELLOW => 'YELLOW',
49 '#FFFF00' => 'YELLOW',
50 LIME => 'LIME',
51 '#00FF00' => 'LIME',
52 AQUA => 'AQUA',
53 AQUAMARINE => 'AQUA',
54 '#00FFFF' => 'AQUA',
55 GREEN => 'GREEN',
56 '#008000' => 'GREEN',
57 OLIVE => 'OLIVE',
58 '#808000' => 'OLIVE',
59 BROWN => 'BROWN',
60 '#996633' => 'BROWN',
61 NAVY => 'NAVY',
62 '#000080' => 'NAVY',
63 TEAL => 'TEAL',
64 '#008080' => 'TEAL',
65 BLUE => 'BLUE',
66 '#0000FF' => 'BLUE',
67 GRAY => 'GRAY',
68 '#808080' => 'GRAY',
69 SILVER => 'SILVER',
70 '#C0C0C0' => 'SILVER',
71 WHITE => 'WHITE',
72 '#FFFFFF' => 'WHITE',
73);
74
75# Genuine HTML colors as follows:
76# '#4682B4' => 'steelblue',
77# '#041690' => 'royalblue',
78# '#6495ED' => 'cornflowerblue',
79# '#B0C4DE' => 'lightsteelblue',
80# '#7B68EE' => 'mediumslateblue',
81# '#6A5ACD' => 'slateblue',
82# '#483D8B' => 'darkslateblue',
83# '#191970' => 'midnightblue',
84# '#000080' => 'navy',
85# '#00008B' => 'darkblue',
86# '#0000CD' => 'mediumblue',
87# '#0000FF' => 'blue',
88# '#1E90FF' => 'dodgerblue',
89# '#00BFFF' => 'deepskyblue',
90# '#87CEFA' => 'lightskyblue',
91# '#87CEEB' => 'skyblue',
92# '#ADD8E6' => 'lightblue',
93# '#B0E0E6' => 'powderblue',
94# '#F0FFFF' => 'azure',
95# '#E0FFFF' => 'lightcyan',
96# '#AFEEEE' => 'paleturquoise',
97# '#48D1CC' => 'mediumturquoise',
98# '#20B2AA' => 'lightseagreen',
99# '#008B8B' => 'darkcyan',
100# '#008080' => 'teal',
101# '#5F9EA0' => 'cadetblue',
102# '#00CED1' => 'darkturquoise',
103# '#00FFFF' => 'aqua',
104# '#00FFFF' => 'cyan',
105# '#40E0D0' => 'turquoise',
106# '#7FFFD4' => 'aquamarine',
107# '#66CDAA' => 'mediumaquamarine',
108# '#8FBC8F' => 'darkseagreen',
109# '#3CB371' => 'mediumseagreen',
110# '#2E8B57' => 'seagreen',
111# '#006400' => 'darkgreen',
112# '#008000' => 'green',
113# '#228B22' => 'forestgreen',
114# '#32CD32' => 'limegreen',
115# '#00FF00' => 'lime',
116# '#7FFF00' => 'chartreuse',
117# '#7CFC00' => 'lawngreen',
118# '#ADFF2F' => 'greenyellow',
119# '#9ACD32' => 'yellowgreen',
120# '#98FB98' => 'palegreen',
121# '#90EE90' => 'lightgreen',
122# '#00FF7F' => 'springgreen',
123# '#00FA9A' => 'mediumspringgreen',
124# '#556B2F' => 'darkolivegreen',
125# '#6B8E23' => 'olivedrab',
126# '#808000' => 'olive',
127# '#BDB76B' => 'darkkhaki',
128# '#B8860B' => 'darkgoldenrod',
129# '#DAA520' => 'goldenrod',
130# '#FFD700' => 'gold',
131# '#FFFF00' => 'yellow',
132# '#F0E68C' => 'khaki',
133# '#EEE8AA' => 'palegoldenrod',
134# '#FFEBCD' => 'blanchedalmond',
135# '#FFE4B5' => 'moccasin',
136# '#F5DEB3' => 'wheat',
137# '#FFDEAD' => 'navajowhite',
138# '#DEB887' => 'burlywood',
139# '#D2B48C' => 'tan',
140# '#BC8F8F' => 'rosybrown',
141# '#A0522D' => 'sienna',
142# '#8B4513' => 'saddlebrown',
143# '#D2691E' => 'chocolate',
144# '#CD853F' => 'peru',
145# '#F4A460' => 'sandybrown',
146# '#8B0000' => 'darkred',
147# '#800000' => 'maroon',
148# '#A52A2A' => 'brown',
149# '#B22222' => 'firebrick',
150# '#CD5C5C' => 'indianred',
151# '#F08080' => 'lightcoral',
152# '#FA8072' => 'salmon',
153# '#E9967A' => 'darksalmon',
154# '#FFA07A' => 'lightsalmon',
155# '#FF7F50' => 'coral',
156# '#FF6347' => 'tomato',
157# '#FF8C00' => 'darkorange',
158# '#FFA500' => 'orange',
159# '#FF4500' => 'orangered',
160# '#DC143C' => 'crimson',
161# '#FF0000' => 'red',
162# '#FF1493' => 'deeppink',
163# '#FF00FF' => 'fuchsia',
164# '#FF00FF' => 'magenta',
165# '#FF69B4' => 'hotpink',
166# '#FFB6C1' => 'lightpink',
167# '#FFC0CB' => 'pink',
168# '#DB7093' => 'palevioletred',
169# '#C71585' => 'mediumvioletred',
170# '#800080' => 'purple',
171# '#8B008B' => 'darkmagenta',
172# '#9370DB' => 'mediumpurple',
173# '#8A2BE2' => 'blueviolet',
174# '#4B0082' => 'indigo',
175# '#9400D3' => 'darkviolet',
176# '#9932CC' => 'darkorchid',
177# '#BA55D3' => 'mediumorchid',
178# '#DA70D6' => 'orchid',
179# '#EE82EE' => 'violet',
180# '#DDA0DD' => 'plum',
181# '#D8BFD8' => 'thistle',
182# '#E6E6FA' => 'lavender',
183# '#F8F8FF' => 'ghostwhite',
184# '#F0F8FF' => 'aliceblue',
185# '#F5FFFA' => 'mintcream',
186# '#F0FFF0' => 'honeydew',
187# '#FAFAD2' => 'lightgoldenrodyellow',
188# '#FFFACD' => 'lemonchiffon',
189# '#FFF8DC' => 'cornsilk',
190# '#FFFFE0' => 'lightyellow',
191# '#FFFFF0' => 'ivory',
192# '#FFFAF0' => 'floralwhite',
193# '#FAF0E6' => 'linen',
194# '#FDF5E6' => 'oldlace',
195# '#FAEBD7' => 'antiquewhite',
196# '#FFE4C4' => 'bisque',
197# '#FFDAB9' => 'peachpuff',
198# '#FFEFD5' => 'papayawhip',
199# '#F5F5DC' => 'beige',
200# '#FFF5EE' => 'seashell',
201# '#FFF0F5' => 'lavenderblush',
202# '#FFE4E1' => 'mistyrose',
203# '#FFFAFA' => 'snow',
204# '#FFFFFF' => 'white',
205# '#F5F5F5' => 'whitesmoke',
206# '#DCDCDC' => 'gainsboro',
207# '#D3D3D3' => 'lightgrey',
208
209############ Encodings ###############
210
2111100nsour $encoding;
212
213sub encoding {
214 unless ($encoding) {
215 $encoding =
216 Encode::resolve_alias( $Foswiki::cfg{Site}{CharSet} || 'iso-8859-1' );
217
218 $encoding = 'windows-1252' if $encoding =~ /^iso-8859-1$/i;
219 }
220 return $encoding;
221}
222
2231200nsmy $siteCharsetRepresentable;
224
225# Convert characters (unicode codepoints) that cannot be represented in
226# the site charset to entities. Prefer named entities to numeric entities.
227sub convertNotRepresentabletoEntity {
228 if ( encoding() =~ /^utf-?8/ ) {
229
230 # UTF-8 can represent all characters, so no entities needed
231 }
232 else {
233 unless ($siteCharsetRepresentable) {
234
235 # Produce a string of unicode characters that contains all of the
236 # characters representable in the site charset
237 $siteCharsetRepresentable = '';
238 for my $code ( 0 .. 255 ) {
239 eval {
240 my $unicodeChar =
241 Encode::decode( encoding(), chr($code),
242 Encode::FB_CROAK );
243
244 # Escape codes in the standard ASCII range, as necessary,
245 # to avoid special interpretation by perl
246 $unicodeChar = quotemeta($unicodeChar)
247 if ord($unicodeChar) <= 127;
248
249 $siteCharsetRepresentable .= $unicodeChar;
250 };
251
252 # otherwise ignore
253 }
254 }
255
256 $_[0] =
257 HTML::Entities::encode_entities( $_[0],
258 "^$siteCharsetRepresentable" );
259
260# All characters that cannot be represented in the site charset are now encoded as entities
261# Named entities are used if available, otherwise numeric entities,
262# because named entities produce more readable TML
263 }
264}
265
266# Named entities that we want to convert back to characters, rather
267# than leaving them as HTML entities.
268122µsour @safeEntities = qw(
269 euro iexcl cent pound curren yen brvbar sect
270 uml copy ordf laquo not shy reg macr
271 deg plusmn sup2 sup3 acute micro para middot
272 cedil sup1 ordm raquo frac14 frac12 frac34 iquest
273 Agrave Aacute Acirc Atilde Auml Aring AElig Ccedil
274 Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml
275 ETH Ntilde Ograve Oacute Ocirc Otilde Ouml times
276 Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig
277 agrave aacute acirc atilde auml aring aelig ccedil
278 egrave eacute ecirc euml igrave iacute icirc iuml
279 eth ntilde ograve oacute ocirc otilde ouml divide
280 oslash ugrave uacute ucirc uuml yacute thorn yuml
281);
282
283# Get a hash that maps the safe entities values to unicode characters
2841100nsour $safe_entities;
285
286sub safeEntities {
287 unless ($safe_entities) {
288 foreach my $entity (@safeEntities) {
289
290 # Decode the entity name to unicode
291 my $unicode = HTML::Entities::decode_entities("&$entity;");
292
293 $safe_entities->{$entity} = $unicode;
294 }
295 }
296 return $safe_entities;
297}
298
299# Given a string encoded using {Site}{CharSet}, decode all entities in
300# it that can be mapped to the encoding, and return a string encoded
301# used the {Site}{CharSet}
3021100nsour $representable_entities;
303
304sub decodeRepresentableEntities {
305 if ( !$representable_entities ) {
306 if ( encoding() =~ /^utf-?8/ ) {
307
308 # UTF-8 can do all entities
309 $representable_entities = \%HTML::Entities::entity2char;
310 }
311 else {
312
313 # Filter the entity set to those that can be
314 # represented in the site charset
315 while ( my ( $entity, $unicode ) =
316 each %HTML::Entities::entity2char )
317 {
318 eval {
319 my $uncool = $unicode;
320 Encode::encode( encoding(), $uncool, Encode::FB_CROAK );
321 };
322 unless ($@) {
323
324 # $unicode can be encoded in the site charset
325 $representable_entities->{$entity} = $unicode;
326 }
327 }
328 }
329 }
330 HTML::Entities::_decode_entities( $_[0], $representable_entities );
331 $_[0] = Encode::encode( encoding(), $_[0] );
332 return $_[0];
333}
334
335# Debug
336sub chCodes {
337 my $text = shift;
338 my $s = "";
339 for ( my $i = 0 ; $i < length($text) ; $i++ ) {
340 my $ch = substr( $text, $i, 1 );
341 if ( ord($ch) < 32 || ord($ch) > 127 ) {
342 $s = $s . '#' . ord($ch) . ';';
343 }
344 else {
345 $s .= $ch;
346 }
347 }
348 return $s;
349}
350
351# Allow the unit tests to force re-initialisation of
352# %Foswiki::cfg-dependent cached data
353sub reinitialiseForTesting {
354 undef $encoding;
355 undef $siteCharsetRepresentable;
356}
357
358# Create shorter alias for other modules
359283µs252µs
# spent 34µs (16+18) within Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@359 which was called: # once (16µs+18µs) by Foswiki::Plugins::WysiwygPlugin::Handlers::BEGIN@18 at line 359
no strict 'refs';
# spent 34µs making 1 call to Foswiki::Plugins::WysiwygPlugin::Constants::BEGIN@359 # spent 18µs making 1 call to strict::unimport
360120µs*{'WC::'} = \*{'Foswiki::Plugins::WysiwygPlugin::Constants::'};
361
362140µs1;
363__END__