Acme-StringFormat
view release on metacpan or search on metacpan
- fix some bugs
- improve efficiency
- add examples in other languages (C++, Ruby, Python)
0.03 Tue Aug 12 11:34:23 2008
- update Module::Install
- use PERL_NO_GET_CONTEXT for efficiency
0.02 Wed Jul 23 15:35:51 2008
- fix to work with overloaded right-hand operand
- fix to work with tainted left-hand operand
0.01 Fri Jul 18 15:09:37 2008
- original version; created by Module::Starter
StringFormat.xs view on Meta::CPAN
SV* lhs = TOPm1s; /* top minus 1 scalar */
SV* rhs = TOPs;
if( my_SvPOK(lhs) ){
dTARGET;
STRLEN len;
const char* start = SvPV_const(lhs, len);
register const char* p = start;
register const char* end = start + len;
bool maybe_tainted = FALSE; /* maybe not used */
/* start of formatter */
while(p < end){
if(*p == '%'){
p++;
if(*p != '%'){
break;
}
}
p++;
StringFormat.xs view on Meta::CPAN
printf("#%s\n#", start);
{
int i;
for(i = 0; i < (p - start); i++){
printf(" ");
}
printf("^\n");
}
#endif
sv_vsetpvfn(TARG, start, (STRLEN)(p - start), NULL, &rhs, 1, &maybe_tainted);
if(end != p) sv_catpvn(TARG, p, (STRLEN)(end - p));
if(SvTAINTED(lhs)) SvTAINTED_on(TARG);
if(SvUTF8(lhs)) SvUTF8_on(TARG);
if(opASSIGN){
sv_setsv(lhs, TARG);
TARG = lhs;
}
t/03_flags.t view on Meta::CPAN
#!perl -wT
use strict;
use Test::More tests => 12;
use Scalar::Util qw(tainted);
use Acme::StringFormat;
# TAINT
my $tainted = substr($^X, 0, 0);
ok tainted($tainted), 'running in taint mode';
ok !tainted('[%s]' % 'foo'), 'untainted';
ok tainted( "[%s]$tainted" % 'foo' ), 'lhs';
ok tainted( '[%s]' % "foo$tainted" ), 'rhs';
my $fmt = '[%s]';
$fmt %= "foo$tainted";
ok tainted($fmt), 'assign';
# UTF8
my $unistr = "\x{307b}\x{3052}\x{ff01}"; # [hoge] in Japanese hiragana
ok utf8::is_utf8($unistr), 'deals with utf8 string';
ok utf8::is_utf8("[%s]$unistr" % 'foo'), 'lhs';
is "[%s]$unistr" % 'foo', "[foo]$unistr";
( run in 0.387 second using v1.01-cache-2.11-cpan-4e96b696675 )