Skip to content

Commit 1ffd25b

Browse files
[FlxBitmapFont] allow extra whitespace when parsing bmfont rows (#3556)
* allow extra whitespace when parsing bmfont rows * formatting and modifications to tests * pull from correct capture group * make test spaces consistent * Move to separate test --------- Co-authored-by: George Kurelic <Gkurelic@gmail.com>
1 parent 203f45d commit 1ffd25b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

flixel/graphics/frames/bmfont/BMFontUtil.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ using StringTools;
88
@:noCompletion
99
class BMFontUtil
1010
{
11-
static var attFinder = ~/(\w+?)=("?)(.*?)\2(?=\s|$)/;
11+
static var attFinder = ~/(\w+?)=(\s*)("?)(.*?)\3(?=\s|$)/;
1212

1313
public static function forEachAttribute(text:UnicodeString, callback:(key:String, value:UnicodeString)->Void)
1414
{
1515
var index = 0;
1616
while (attFinder.match(text.substr(index)))
1717
{
1818
final key = attFinder.matched(1);
19-
final value = attFinder.matched(3);
19+
final value = attFinder.matched(4);
2020
callback(key, value);
2121

2222
final nextIndex = text.length - attFinder.matchedRight().length;

tests/unit/src/flixel/graphics/frames/bmfont/BMFontTest.hx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ class BMFontTest extends FlxTest
2424
assertFont(font);
2525
}
2626

27+
@Test
28+
function testTextFormatWithSpaces()
29+
{
30+
var text =
31+
'info face="Arial Black" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,2,3,4 spacing=2,1 outline=0'
32+
+ '\ncommon lineHeight=32 base=25 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0'
33+
+ '\npage id=0 file="arial_black_0.png"'
34+
+ '\nchars count=3'
35+
+ '\nchar id=64 x=0 y=0 width=25 height=24 xoffset=-5 yoffset=7 xadvance=17 page=0 chnl=15'
36+
+ '\nchar id= 65 x= 27 y= 0 width= 26 height= 21 xoffset= -5 yoffset= 7 xadvance= 18 page= 0 chnl= 15'
37+
+ '\nchar id= 84 x= 55 y= 0 width= 23 height= 21 xoffset= -4 yoffset= 7 xadvance= 16 page= 0 chnl= 15'
38+
+ '\nkernings count=2'
39+
+ '\nkerning first=84 second=65 amount=-2 '
40+
+ '\nkerning first= 65 second= 84 amount= -2 ';
41+
42+
var font = BMFont.parse(cast text);
43+
assertFont(font);
44+
}
45+
2746
@Test
2847
function testXMLFormat()
2948
{
@@ -149,4 +168,4 @@ class BMFontTest extends FlxTest
149168
Assert.areEqual(expected.second, actual.second);
150169
Assert.areEqual(expected.amount, actual.amount);
151170
}
152-
}
171+
}

0 commit comments

Comments
 (0)