App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/SocialCalcServersideUtilities.pm view on Meta::CPAN
my $lnest = length($1);
my $lchr = substr($1,-1);
my $ltype;
if ($lnest > @closingtag) {
for (my $i=@closingtag; $i<$lnest; $i++) {
if ($lchr eq '*') {
$ltype = "ul";
}
elsif ($lchr eq '#') {
$ltype = 'ol';
}
else {
$ltype = 'dl';
}
$str .= "<$ltype>";
push @closingtag, "</$ltype>";
}
}
elsif ($lnest < @closingtag) {
for (my $i=@closingtag; $i>$lnest; $i--) {
$str .= pop @closingtag;
}
}
if ($lchr eq ';') {
my $rest = $2;
if ($rest =~ m/\s*(.*?):(.*)$/) {
$str .= "<dt>$1</dt><dd>$2</dd>";
}
else {
$str .= "<dt>$rest</dt>";
}
}
else {
$str .= "<li>$2</li>";
}
next;
}
while (@closingtag) {
$str .= pop @closingtag;
}
if ($line =~ m/^(={1,5})\s(.+)\s\1$/) { # = heading =, with equal number of equals on both sides
my $neq = length($1);
$str .= "<h$neq>$2</h$neq>";
next;
}
if ($line =~ m/^(:{1,5})\s{0,1}(.+)$/) { # indent 20pts for each :
my $nindent = length($1) * 20;
$str .= "<div style=\"padding-left:${nindent}pt;\">$2</div>";
next;
}
$str .= "$line\n";
}
while (@closingtag) { # just in case any left at the end
$str .= pop @closingtag;
}
$estring = $str;
}
$estring =~ s/\n/<br>/g; # Line breaks are preserved
$estring =~ s/('*)'''(.*?)'''/$1<b>$2<\/b>/gs; # Wiki-style bold/italics
$estring =~ s/''(.*?)''/<i>$1<\/i>/gs;
$estring =~ s/\[b:(.+?)\:b]/<b>$1<\/b>/gs; # [b:text:b] for bold
$estring =~ s/\[i:(.+?)\:i]/<i>$1<\/i>/gs; # [i:text:i] for italic
$estring =~ s/\[quote:(.+?)\:quote]/<blockquote>$1<\/blockquote>/gs; # [quote:text:quote] to indent
$estring =~ s/\{\{amp}}/&/gs; # {{amp}} for ampersand
$estring =~ s/\{\{lt}}/</gs; # {{lt}} for less than
$estring =~ s/\{\{gt}}/>/gs; # {{gt}} for greater than
$estring =~ s/\{\{quot}}/"/gs; # {{quot}} for quote
$estring =~ s/\{\{lbracket}}/[/gs; # {{lbracket}} for left bracket
$estring =~ s/\{\{rbracket}}/]/gs; # {{rbracket}} for right bracket
$estring =~ s/\{\{lbrace}}/{/gs; # {{lbrace}} for brace
return $estring;
}
# * * * * * * * * * * * * * * * * * * * *
#
# Number Formatting code from SocialCalc 1.1.0
#
# * * * * * * * * * * * * * * * * * * * *
our %WKCStrings = (
"decimalchar" => ".",
"separatorchar" => ",",
"currencychar" => '$',
"daynames" => "Sunday Monday Tuesday Wednesday Thursday Friday Saturday",
"daynames3" => "Sun Mon Tue Wed Thu Fri Sat ",
"monthnames3" => "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",
"monthnames" => "January February March April May June July August September October November December",
"sheetdefaultlayoutstyle" => "padding:2px 2px 1px 2px;\nvertical-align:top;\n",
"sheetdefaultfontfamily" => "Verdana,Arial,Helvetica,sans-serif",
"linkformatstring" => '<span style="font-size:smaller;text-decoration:none !important;background-color:#66B;color:#FFF;">Link</span>', # you could make this an img tag if desired:
#"linkformatstring" => '<img border="0" src="http://www.domain.com/link.gif">',
"defaultformatdt" => 'd-mmm-yyyy h:mm:ss',
"defaultformatd" => 'd-mmm-yyyy',
"defaultformatt" => '[h]:mm:ss',
"displaytrue" => 'TRUE', # how TRUE shows when rendered
"displayfalse" => 'FALSE',
);
# # # # # # # # #
#
# $displayvalue = FormatValueForDisplay($sheet, $value, $coord, $options)
#
# # # # # # # # #
sub FormatValueForDisplay {
my ($sheet, $value, $coord, $options) = @_;
my $cell = $sheet->{cells}{$coord};
my $sheetattribs = $sheet->{attribs};
my ($valueformat, $has_parens, $has_commas, $valuetype, $valuesubtype);
# Get references to the parts
my $displayvalue = $value;
$valuetype = $cell->{valuetype}; # get type of value to determine formatting
$valuesubtype = substr($valuetype,1);
( run in 0.570 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )