Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
zaide
BakuJS
Commits
d9b8f8ef
Commit
d9b8f8ef
authored
Feb 17, 2016
by
Zéfling
🎨
Browse files
String format : correction of escape suppression for {}
parent
3596ca76
Changes
2
Hide whitespace changes
Inline
Side-by-side
baku.string.js
View file @
d9b8f8ef
...
...
@@ -74,20 +74,22 @@ String.prototype._format = function (){
args
=
args
[
0
];
}
return
baku
.
string
.
formatter
.
_parse
(
this
,
/**
* remplace the tag by a formated string
* @param base compled string respect the replace pattern (not used) (see : baku.string.formatter._parsePattern )
* @param key the key tag (ex. 0 for {0})
* @param func name of function (optional)
* @param params a paramter object (optional)
* @return string
*/
function
(
base
,
key
,
func
,
params
)
{
return
(
func
!==
undefined
&&
typeof
baku
.
string
.
formatter
[
func
]
===
'
function
'
)
?
(
params
!==
undefined
?
baku
.
string
.
formatter
[
func
](
args
[
key
],
args
,
params
)
:
baku
.
string
.
formatter
[
func
](
args
[
key
],
args
)
)
:
args
[
key
];
}).
replace
(
'
\\
}
'
,
'
}
'
).
replace
(
'
\\
{
'
,
'
{
'
);
return
baku
.
string
.
formatter
.
_parse
(
this
,
/**
* remplace the tag by a formated string
* @param base compled string respect the replace pattern (not used) (see : baku.string.formatter._parsePattern )
* @param key the key tag (ex. 0 for {0})
* @param func name of function (optional)
* @param params a paramter object (optional)
* @return string
*/
function
(
base
,
key
,
func
,
params
)
{
return
(
func
!==
undefined
&&
typeof
baku
.
string
.
formatter
[
func
]
===
'
function
'
)
?
(
params
!==
undefined
?
baku
.
string
.
formatter
[
func
](
args
[
key
],
args
,
params
)
:
baku
.
string
.
formatter
[
func
](
args
[
key
],
args
)
)
:
args
[
key
];
})
.
replace
(
/
\\([
{}
])
/g
,
'
$1
'
);
};
...
...
test.js
View file @
d9b8f8ef
...
...
@@ -289,10 +289,12 @@ window.onload = function(){
Test
.
equals
(
"
'{0}{0}{0}'._format(1)
"
,
'
111
'
,
'
1 + {0}{0}{0} → 111
'
);
Test
.
equals
(
"
'a{0}b{0}c'._format(1)
"
,
'
a1b1c
'
,
'
1 + a{0}b{0}c → a1b1c
'
);
Test
.
equals
(
"
'{0}
\\\\
{0
\\\\
}{0}'._format(1)
"
,
'
1{0}1
'
,
'
1 + {0}
\\
{0
\\
}{0} → 1{0}1
'
);
Test
.
equals
(
"
'
\\\\
{0
\\\\
}{0}
\\\\
{0
\\\\
}'._format(1)
"
,
'
{0}1{0}
'
,
'
1 +
\\
{0
\\
}{0}
\\
{0
\\
} → {0}1{0}
'
);
Test
.
error
(
"
'{0}
\\\\
{0}{0}'._format(1)
"
);
Test
.
error
(
"
'{0}{0
\\\\
}{0}'._format(1)
"
);
Test
.
error
(
"
'{0}{0,}{0}'._format(1)
"
);
Test
.
title
(
"
String.prototype._format() + number
"
);
Test
.
equals
(
"
'{0, number, #,###}'._format(1)
"
,
'
1
'
,
'
1 + {0, number, #,###} → 1
'
);
Test
.
equals
(
"
'{0, number, #,###:fr}'._format([1000.10])
"
,
'
1
\
u00A0000
'
,
'
[1000.10] + {0, number, #,###:fr} → 1
\
u00A0000
'
);
...
...
@@ -314,6 +316,7 @@ window.onload = function(){
Test
.
equals
(
"
'{0, choice, 1#{1}|2#{2}}'._format([1, 2, 3])
"
,
'
2
'
,
'
[1, 2, 3] + {0, choice, 1#{1}|2#{2}} → 2
'
);
Test
.
equals
(
"
'{0, choice, 1#{1}|2#{2}}'._format('a')
"
,
''
,
'
"a" + {0, choice, 1#{1}|2#{2}} → ""
'
);
Test
.
title
(
"
String.prototype._format() + date
"
);
Test
.
equals
(
"
'{0, date, d/M/yy}'._format('2015-02-08')
"
,
'
8/2/15
'
,
'
2015-02-08 + {0, date, d/M/yy} → 8/2/15
'
);
Test
.
equals
(
"
'{0, date, dd/MM/yyyy}'._format('2015-10-20')
"
,
'
20/10/2015
'
,
'
2015-10-20 + {0, date, dd/MM/yyyy} → 20/10/2015
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment