在1.13版中,Minecraft语言文件从一种简单的多行key = value格式切换为JSON。
挑战
编写一个从原始格式转换为返回JSON字符串的程序。可以使用任何标准输入方法进行输入,任何标准输出方法的输出必须为json
原始格式包含带有键=值对的行,例如
tile.dirt.name=Dirt
advMode.nearestPlayer=Use "@p" to target nearest player
build.tooHigh=Height limit for building is %s blocks
应该转换为key = value的一个大JSON对象
{
"tile.dirt.name": "Dirt",
"advMode.nearestPlayer": "Use \"@p\" to target nearest player",
"build.tooHigh": "Height limit for building is %s blocks"
}
一些细节
- 只要它包含正确的键/值对,就可以使用任何有效的JSON。允许使用尾部逗号,因为Minecraft允许使用逗号。
- 唯一必须避免的是引号。(1.13之前的语言文件中不存在换行符,反斜杠或其他破坏JSON的东西)
- 空行应忽略
- 行包含正好等于1的行
测试用例
输入:
tile.dirt.name=Dirt
advMode.nearestPlayer=Use "@p" to target nearest player
build.tooHigh=Height limit for building is %s blocks
输出:
{
"tile.dirt.name": "Dirt",
"advMode.nearestPlayer": "Use \"@p\" to target nearest player",
"build.tooHigh": "Height limit for building is %s blocks"
}
输入:
translation.test.none=Hello, world!
translation.test.complex=Prefix, %s%2$s again %s and %1$s lastly %s and also %1$s again!
translation.test.escape=%%s %%%s %%%%s %%%%%s
translation.test.invalid=hi %
translation.test.invalid2=hi % s
translation.test.args=%s %s
translation.test.world=world
输出:
{
"translation.test.none": "Hello, world!",
"translation.test.complex": "Prefix, %s%2$s again %s and %1$s lastly %s and also %1$s again!",
"translation.test.escape": "%%s %%%s %%%%s %%%%%s",
"translation.test.invalid": "hi %",
"translation.test.invalid2": "hi % s",
"translation.test.args": "%s %s",
"translation.test.world": "world",
}
输入:
stat.mineBlock=%1$s Mined
stat.craftItem=%1$s Crafted
stat.useItem=%1$s Used
stat.breakItem=%1$s Depleted
输出:
{
"stat.mineBlock": "%1$s Mined",
"stat.craftItem": "%1$s Crafted",
"stat.useItem": "%1$s Used",
"stat.breakItem": "%1$s Depleted"
}
=
?
tile.dirt.name
变成"block.minecraft.dirt"
?