Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a1dc79

Browse files
committed
0.6 commit
1 parent0fa6bba commit7a1dc79

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

‎src/sprintf.js‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
sprintf() for JavaScript 0.5
2+
sprintf() for JavaScript 0.6
33
44
Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com>
55
All rights reserved.
@@ -40,11 +40,17 @@ Changelog:
4040
- bug fix: 0 is now preceeded with a + sign
4141
- bug fix: the sign was not at the right position on padded results (Kamal Abdali)
4242
- switched from GPL to BSD license
43+
2010.05.22 - 0.6:
44+
- reverted to 0.4 and fixed the bug regarding the sign of the number 0
45+
Note:
46+
Thanks to Raphael Pigulla <raph (at] n3rd [dot) org> (http://www.n3rd.org/)
47+
who warned me about a bug in 0.5, I discovered that the last update was
48+
a regress. I appologize for that.
4349
**/
4450

4551
functionstr_repeat(i,m){
4652
for(varo=[];m>0;o[--m]=i);
47-
return(o.join(""));
53+
returno.join('');
4854
}
4955

5056
functionsprintf(){
@@ -54,14 +60,14 @@ function sprintf() {
5460
o.push(m[0]);
5561
}
5662
elseif(m=/^\x25{2}/.exec(f)){
57-
o.push("%");
63+
o.push('%');
5864
}
5965
elseif(m=/^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)){
6066
if(((a=arguments[m[1]||i++])==null)||(a==undefined)){
61-
throw("Too few arguments.");
67+
throw('Too few arguments.');
6268
}
63-
if(/[^s]/.test(m[7])&&(typeof(a)!="number")){
64-
throw("Expecting number but found"+typeof(a));
69+
if(/[^s]/.test(m[7])&&(typeof(a)!='number')){
70+
throw('Expecting number but found'+typeof(a));
6571
}
6672
switch(m[7]){
6773
case'b':a=a.toString(2);break;
@@ -75,19 +81,16 @@ function sprintf() {
7581
case'x':a=a.toString(16);break;
7682
case'X':a=a.toString(16).toUpperCase();break;
7783
}
78-
if(/[def]/.test(m[7])){
79-
s=(a>=0 ?(m[2] ?'+' :'') :'-');
80-
a=Math.abs(a);
81-
}
84+
a=(/[def]/.test(m[7])&&m[2]&&a>=0 ?'+'+a :a);
8285
c=m[3] ?m[3]=='0' ?'0' :m[3].charAt(1) :' ';
8386
x=m[5]-String(a).length-s.length;
8487
p=m[5] ?str_repeat(c,x) :'';
8588
o.push(s+(m[4] ?a+p :p+a));
8689
}
8790
else{
88-
throw("Huh ?!");
91+
throw('Huh ?!');
8992
}
9093
f=f.substring(m[0].length);
9194
}
92-
returno.join("");
95+
returno.join('');
9396
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp