arthur-debert / printf-as3 Goto Github PK
View Code? Open in Web Editor NEWA printf like facility for Actionscript, loosely inspired by Python's.
Home Page: http://www.stimuli.com.br/trane/2009/feb/21/printf-as3/
License: MIT License
A printf like facility for Actionscript, loosely inspired by Python's.
Home Page: http://www.stimuli.com.br/trane/2009/feb/21/printf-as3/
License: MIT License
What steps will reproduce the problem? 1. printf("%.2f", 0.0) What is the expected output? What do you see instead? 2. returns %.2f 3. instead of 0.00 What version of the product are you using? On what operating system? last Please provide any additional information below. SUBS_RE seems wrong. i changed it to this instead: var SUBS_RE : RegExp = /%(?!^%)(((?P<var_name>[\w_\d]+)))?(?P<padding>[0-9]{1,2})?(.(? P<precision>[0-9]+))?(?P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])/ig; note how the precision part is moved AFTER the padding and BEFORE the formater (as it should) this doesn't enforce .00 though (in case of %.2f when supplied integer arguments)
There ist no support for leading zeros. Means: ..("%03d", 6); -> "006" Please add this feature!
code should come with some basic unit tests
use rev19 of the code use the codeL trace( printf("You can also display numbers like PI: %f, and format them to a fixed precision, such as PI with 3 decimal places %.3f", Math.PI, Math.PI)); produces You can also display numbers like PI: 3.141592653589793, and format them to a fixed precision, such as PI with 3 decimal places %.3f it should display 3.141 not %.3f
I'm not sure why, but you've removed the perfectly sensible package structure for this as3 code. It's a real shame because as I use libraries like this using svn external properties, however having code like this dumped in the base package is messy and could cause conflicts with other packages/libraries. Would you please consider re-adding the package structure, it also helps identify the project and reveal code dependencies. While I'm writing this, I should thank you for a good idea well implemented.
printf("%03d%s",1,'A') outputs 00100A The A is being padded like the 1 because the padding variables are not reset from one pattern to the next.
What steps will reproduce the problem? 1. import the printf 2. execute the code v = printf("%.2f", v), with v an untyped variable originally containing a floating point number (eg, 0.4858329, 5.094833) 3. look at v What is the expected output? What do you see instead? v should contain a string with the numeric value to two DP (eg, "0.486", "5.095" for the example values). In fact, it simply repeats the formatting string (eg, "%.2f" for all values of v). Removing the ".2" qualification, leaving a format string of "%f", produces the expected result. What version of the product are you using? On what operating system? The ZIP file describes itself as "rev6". Running Adobe Flash CS3 and Flash Player 9 on Windows XP SP3. Please provide any additional information below.
printf("this is %03d%s",1,'A')
output
this is 0001A
should be
this is 001A
I checked your function
/** @Private */
function padString(str:String, paddingNum:int, paddingChar:String=" ") : String
{
if(paddingChar == null) return str;
return new Array(paddingNum + 1).join(paddingChar).concat(str);
}
it's not right for padding, array,joined the padding char at first And append the str at last
should be like this one
/** @Private */
function padString(str:String, paddingNum:int, paddingChar:String=" ") : String
{
if(paddingChar == null) return str;
return new Array(paddingNum + 1).join(paddingChar).substr(0,paddingNum-str.length).concat(str);
}
Attached is a proposal of extension to printf function with the following features: 1. Nested property references are supported, i.e. %(user.account.login)s 2. Special support for array indexing of nested properties is implemented as well, for example: %(user.roles.item4.name)s // roles.item4 is in fact roles[4], hence the name of fifth role (zero based) of array-like\* property "roles" is printed %(user.roles.first.name)s // name of first role, syntactic sugar %(call.arguments.last)s // last argument of array-like property "arguments" syntactic sugar *"Array-like" means that object must support "length" property and allows indexed access to items; examples are Array, ArrayCollection and similar. Regrds, Valery Silaev Farata Systems http://flexblog.faratasystems.com/
What steps will reproduce the problem? 1. Alert.show(printf("This is an %s library", "Actionscript 3.0")); What is the expected output? What do you see instead? Expected an alert with the message "This is an Actionscript 3.0 library". Instead I get this error: ReferenceError: Error #1069: Property not found on String and there is no default value. at global/br.com.stimuli.string::printf()[/Users/daniel/laplace/reg_web/app/flex/br/com/stimuli/string/p rintf.as:74] What version of the product are you using? On what operating system? Revision 1. Mac OS X 10.5. Please provide any additional information below. I'm using Flex Builder 3.0.194161. If I add a third parameter to printf it works. Alert.show(printf("This is an %s library", "Actionscript 3.0", "")); // works Alert.show(printf("This is an %s library", "Actionscript 3.0")); // doesn't work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.