srcclean: Added JSON cleaning support, and some cleanup.

Made pbobble parent of bublbust, as it seems to be more widespread and
more complete.  Also fixed some ROM labels for bublbust.

Made tbyahhoo parent of mtwinbee as the latter has substantial content
removed rather than being localised, making it less complete.

Applied srcclean to JSON files in bgfx subtree.
This commit is contained in:
Vas Crabb 2021-08-20 05:47:40 +10:00
parent 59c4e5fed6
commit 0c49c74ada
142 changed files with 4334 additions and 4032 deletions

View File

@ -41,11 +41,11 @@
{ "name": "aperture_strength", "type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "aperture_brightboost","type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "spot_size", "type": "vec4", "values": [ 0.3,0.0,0.0,0.0 ] },
{ "name": "spot_growth","type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] },
{ "name": "spot_growth", "type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] },
{ "name": "spot_growth_power", "type": "vec4", "values": [ 3.0,0.0,0.0,0.0 ] },
{ "name": "u_interp", "type": "vec4", "values": [ 2.0,0.0,0.0,0.0 ] },
{ "name": "halation", "type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] },
{ "name": "blurwidth", "type": "vec4", "values": [ 2.0,0.0,0.0,0.0 ] },
{ "name": "rasterbloom","type": "vec4", "values": [ 0.01,0.0,0.0,0.0 ] }
{ "name": "rasterbloom", "type": "vec4", "values": [ 0.01,0.0,0.0,0.0 ] }
]
}

View File

@ -39,7 +39,7 @@
{ "name": "aperture_strength", "type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "aperture_brightboost","type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "spot_size", "type": "vec4", "values": [ 0.3,0.0,0.0,0.0 ] },
{ "name": "spot_growth","type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] },
{ "name": "spot_growth", "type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] },
{ "name": "spot_growth_power", "type": "vec4", "values": [ 3.0,0.0,0.0,0.0 ] },
{ "name": "u_interp", "type": "vec4", "values": [ 2.0,0.0,0.0,0.0 ] }
]

View File

@ -21,7 +21,7 @@
"fragment": "chains/lcd-grid/fs_persistence",
"uniforms": [
{ "name": "s_screen", "type": "int", "values": [ 0 ] },
{ "name": "s_motionblur","type": "int", "values": [ 1 ] },
{ "name": "s_motionblur", "type": "int", "values": [ 1 ] },
{ "name": "u_persistence","type":"vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }
]
}

View File

@ -1814,6 +1814,7 @@ ifeq (posix,$(SHELLTYPE))
$(SILENT) find src -name \*.mm -exec ./srcclean {} \; >&2
$(SILENT) find hash -name \*.hsi -exec ./srcclean {} \; >&2
$(SILENT) find hash -name \*.xml -exec ./srcclean {} \; >&2
$(SILENT) find bgfx -name \*.json -exec ./srcclean {} \; >&2
$(SILENT) find plugins -name \*.lua -exec ./srcclean {} \; >&2
$(SILENT) find scripts -name \*.lua -exec ./srcclean {} \; >&2
else
@ -1829,6 +1830,7 @@ else
$(shell for /r src %%i in (*.mm) do srcclean %%i >&2 )
$(shell for /r hash %%i in (*.hsi) do srcclean %%i >&2 )
$(shell for /r hash %%i in (*.xml) do srcclean %%i >&2 )
$(shell for /r bgfx %%i in (*.json) do srcclean %%i >&2 )
$(shell for /r plugins %%i in (*.lua) do srcclean %%i >&2 )
$(shell for /r scripts %%i in (*.lua) do srcclean %%i >&2 )
endif

View File

@ -2181,39 +2181,6 @@ ROM_START( salmndr2a )
ROM_LOAD( "salmndr2a.nv", 0x0000, 0x080, CRC(3a98a8f9) SHA1(08c2d164620a4d8ad902d502acea8ad621931198) )
ROM_END
/* Magical Twinbee */
ROM_START( mtwinbee )
/* main program */
ROM_REGION( 0x800000, "maincpu", 0 )
GX_BIOS
ROM_LOAD32_WORD_SWAP( "424eaa02.31b", 0x200002, 512*1024, CRC(34659905) SHA1(011df093502644ab7ceb7fd1fbca41d09af89566) )
ROM_LOAD32_WORD_SWAP( "424eaa04.27b", 0x200000, 512*1024, CRC(f42d3139) SHA1(e03006b4a87a70dfba9ec5e4857442424269986c) )
/* sound program */
ROM_REGION( 0x40000, "soundcpu", 0 )
ROM_LOAD16_BYTE("424a06.9c", 0x000000, 128*1024, CRC(a4760e14) SHA1(78dbd309f3f7fa61e92c9554e594449a7d4eed5a) )
ROM_LOAD16_BYTE("424a07.7c", 0x000001, 128*1024, CRC(fa90d7e2) SHA1(6b6dee29643309005834416bdfdb18d74f34cb1b) )
/* tiles */
ROM_REGION( 0x500000, "k056832", ROMREGION_ERASE00 )
TILE_WORD_ROM_LOAD( "424a14.17h", 0x000000, 2*1024*1024, CRC(b1d9fce8) SHA1(143ed2f03ac10a0f18d878c0ee0509a5714e4664) )
TILE_BYTE_ROM_LOAD( "424a12.13g", 0x000004, 512*1024, CRC(7f9cb8b1) SHA1(f5e18d70fcb572bb85f9b064995fc0ab0bb581e8) )
/* sprites */
ROM_REGION( 0x500000, "k055673", ROMREGION_ERASE00 )
ROM_LOAD32_WORD( "424a11.25g", 0x000000, 2*1024*1024, CRC(29592688) SHA1(a4b44e9153988a510915af83116e3c18dd15642f) )
ROM_LOAD32_WORD( "424a10.28g", 0x000002, 2*1024*1024, CRC(cf24e5e3) SHA1(095bf2ae4f47c6e4768515ae5e22c982fbc660a5) )
ROM_LOAD( "424a09.30g", 0x400000, 1*1024*1024, CRC(daa07224) SHA1(198cafa3d0ead2aa2593be066c6f372e66c11c44) )
/* sound data */
ROM_REGION( 0x400000, "k054539", 0 )
ROM_LOAD( "424a17.9g", 0x000000, 2*1024*1024, CRC(e9dd9692) SHA1(c289019c8d1dd71b3cec26479c39b649de804707) )
ROM_LOAD( "424a18.7g", 0x200000, 2*1024*1024, CRC(0f0d9f3a) SHA1(57f6b113b80f06964b7e672ad517c1654c5569c5) )
ROM_REGION16_BE( 0x80, "eeprom", 0 ) // default eeprom to prevent game booting with error
ROM_LOAD( "mtwinbee.nv", 0x0000, 0x080, CRC(942b4323) SHA1(2f6799bf187510355df5e52c4d416f5c5e70fa05) )
ROM_END
/* Twinbee Yahhoo! */
ROM_START( tbyahhoo )
/* main program */
@ -2276,6 +2243,39 @@ ROM_START( daiskiss )
ROM_LOAD( "535a22.9g", 0x000000, 2*1024*1024, CRC(7ee59acb) SHA1(782bf15f205e9fe7bd069f6445eb8187837dee32) )
ROM_END
/* Magical Twinbee */
ROM_START( mtwinbee )
/* main program */
ROM_REGION( 0x800000, "maincpu", 0 )
GX_BIOS
ROM_LOAD32_WORD_SWAP( "424eaa02.31b", 0x200002, 512*1024, CRC(34659905) SHA1(011df093502644ab7ceb7fd1fbca41d09af89566) )
ROM_LOAD32_WORD_SWAP( "424eaa04.27b", 0x200000, 512*1024, CRC(f42d3139) SHA1(e03006b4a87a70dfba9ec5e4857442424269986c) )
/* sound program */
ROM_REGION( 0x40000, "soundcpu", 0 )
ROM_LOAD16_BYTE("424a06.9c", 0x000000, 128*1024, CRC(a4760e14) SHA1(78dbd309f3f7fa61e92c9554e594449a7d4eed5a) )
ROM_LOAD16_BYTE("424a07.7c", 0x000001, 128*1024, CRC(fa90d7e2) SHA1(6b6dee29643309005834416bdfdb18d74f34cb1b) )
/* tiles */
ROM_REGION( 0x500000, "k056832", ROMREGION_ERASE00 )
TILE_WORD_ROM_LOAD( "424a14.17h", 0x000000, 2*1024*1024, CRC(b1d9fce8) SHA1(143ed2f03ac10a0f18d878c0ee0509a5714e4664) )
TILE_BYTE_ROM_LOAD( "424a12.13g", 0x000004, 512*1024, CRC(7f9cb8b1) SHA1(f5e18d70fcb572bb85f9b064995fc0ab0bb581e8) )
/* sprites */
ROM_REGION( 0x500000, "k055673", ROMREGION_ERASE00 )
ROM_LOAD32_WORD( "424a11.25g", 0x000000, 2*1024*1024, CRC(29592688) SHA1(a4b44e9153988a510915af83116e3c18dd15642f) )
ROM_LOAD32_WORD( "424a10.28g", 0x000002, 2*1024*1024, CRC(cf24e5e3) SHA1(095bf2ae4f47c6e4768515ae5e22c982fbc660a5) )
ROM_LOAD( "424a09.30g", 0x400000, 1*1024*1024, CRC(daa07224) SHA1(198cafa3d0ead2aa2593be066c6f372e66c11c44) )
/* sound data */
ROM_REGION( 0x400000, "k054539", 0 )
ROM_LOAD( "424a17.9g", 0x000000, 2*1024*1024, CRC(e9dd9692) SHA1(c289019c8d1dd71b3cec26479c39b649de804707) )
ROM_LOAD( "424a18.7g", 0x200000, 2*1024*1024, CRC(0f0d9f3a) SHA1(57f6b113b80f06964b7e672ad517c1654c5569c5) )
ROM_REGION16_BE( 0x80, "eeprom", 0 ) // default eeprom to prevent game booting with error
ROM_LOAD( "mtwinbee.nv", 0x0000, 0x080, CRC(942b4323) SHA1(2f6799bf187510355df5e52c4d416f5c5e70fa05) )
ROM_END
/* Sexy Parodius version JAA (Japan) */
ROM_START( sexyparo )
/* main program */
@ -4042,8 +4042,8 @@ GAME( 1994, gokuparo, fantjour, gokuparo, gokuparo, konamigx_state, init_ko
GAME( 1994, crzcross, konamigx, gokuparo, puzldama, konamigx_state, init_posthack, ROT0, "Konami", "Crazy Cross (ver EAA)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1994, puzldama, crzcross, gokuparo, puzldama, konamigx_state, init_posthack, ROT0, "Konami", "Taisen Puzzle-dama (ver JAA)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1995, mtwinbee, konamigx, tbyahhoo, gokuparo, konamigx_state, init_posthack, ROT0, "Konami", "Magical Twin Bee (ver EAA)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1995, tbyahhoo, mtwinbee, tbyahhoo, gokuparo, konamigx_state, init_posthack, ROT0, "Konami", "Twin Bee Yahhoo! (ver JAA)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1995, tbyahhoo, konamigx, tbyahhoo, gokuparo, konamigx_state, init_posthack, ROT0, "Konami", "Twin Bee Yahhoo! (ver JAA)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1995, mtwinbee, tbyahhoo, tbyahhoo, gokuparo, konamigx_state, init_posthack, ROT0, "Konami", "Magical Twin Bee (ver EAA)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1995, tkmmpzdm, konamigx, konamigx_6bpp, tokkae, konamigx_state, init_konamigx, ROT0, "Konami", "Tokimeki Memorial Taisen Puzzle-dama (ver JAB)", MACHINE_IMPERFECT_GRAPHICS )

View File

@ -3055,24 +3055,6 @@ ROM_START( rambo3p ) /* Is this set a prototype or possible bootleg? */
ROM_LOAD( "r3-a4.rom", 0x60000, 0x20000, CRC(9cf4c21b) SHA1(756fc6bbc798a39a18eab3829e032cac8fe3f8ed) )
ROM_END
ROM_START( bublbust ) // Purportedly a location test version, but has the same version number and build date as the released Japanese set below
ROM_REGION( 0x80000, "maincpu", 0 ) // 512k for 68000 code - located on Taito C0503005B main board
ROM_LOAD16_BYTE( "p.bobble_prg_h_usa_6-15_c681.ic18", 0x00000, 0x40000, CRC(ba83e398) SHA1(2512ea5a805f0e5c470c4d216d679f3dc3c4aa82) ) // hand written label P.Bobble PRG H USA 6/15 C681 - "Bobble" written in Kanji
ROM_LOAD16_BYTE( "p.bobble_prg_l_usa_6-15_e9e1.ic2", 0x00001, 0x40000, CRC(a12cb3f2) SHA1(06271d3a0af101a959e6e777f1f9e99bae1e6076) ) // hand written label P.Bobble PRG L USA 6/15 E9E1 - "Bobble" written in Kanji
ROM_REGION( 0x20000, "audiocpu", 0 ) // 128k for Z80 code - located on Taito C0503005B main board
ROM_LOAD( "prg_snd.ic27", 0x00000, 0x20000, CRC(2f288fe0) SHA1(4ba707f4b3a1ca0e573652d1c733ee889f9fef8a) ) // hand written label PRG SND IC 27 - no checksum listed
ROM_REGION( 0x100000, "tc0180vcu", 0 ) // located on Taito C0503002A ROM PCB
ROM_LOAD16_BYTE( "p.bobble_chr-1l_6-14_eaa0.ic11_ch_1_0l", 0x00000, 0x40000, CRC(8d3fa2f0) SHA1(3d36944e35081740469df61a40e538eb94ea2ef6) ) // hand written label P.Bobble CHR 1L 6/14 EAA0 - "Bobble" written in Kanji
ROM_LOAD16_BYTE( "p.bobble_chr-1h_6-14_1515.ic12_ch_1_0h", 0x00001, 0x40000, CRC(a2eb4d32) SHA1(571811a543af50cc5e0f1d7aad9fc388919e93e6) ) // hand written label P.Bobble CHR 1H 6/14 1515 - "Bobble" written in Kanji
ROM_LOAD16_BYTE( "p.bobble_chr-0l_6-14_86d5.ic7_ch_0_0l", 0x80000, 0x40000, CRC(80f1aab0) SHA1(f5cdb93aa702fb8ba91eaf8f470b6e2a61a581b5) ) // hand written label P.Bobble CHR 0L 6/14 86D5 - "Bobble" written in Kanji
ROM_LOAD16_BYTE( "p.bobble_chr-0h_6-14_d180.ic8_ch_0_0h", 0x80001, 0x40000, CRC(d773cac8) SHA1(b008a21c39650a28cba402cd1c4de0567e275bc9) ) // hand written label P.Bobble CHR 0H 6/14 D180 - "Bobble" written in Kanji
ROM_REGION( 0x100000, "ymsnd:adpcma", 0 ) // located on Taito C0503002A ROM PCB - Half the size of the Japanese ADPCMA sample ROM
ROM_LOAD( "ach0-kaigai.ic15_ach_0", 0x00000, 0x80000, CRC(f203ae52) SHA1(d41b880ef17eea6614e2911318db5cd070473381) ) // hand written ???
ROM_END
ROM_START( pbobble )
ROM_REGION( 0x80000, "maincpu", 0 ) /* 512k for 68000 code */
ROM_LOAD16_BYTE( "pb-1c18.bin", 0x00000, 0x40000, CRC(5de14f49) SHA1(91d537748f26e19a5c32de4b8dad341750de39ef) )
@ -3089,6 +3071,24 @@ ROM_START( pbobble )
ROM_LOAD( "pb-ic15.bin", 0x000000, 0x100000, CRC(0840cbc4) SHA1(1adbd7aef44fa80832f63dfb8efdf69fd7256a57) )
ROM_END
ROM_START( bublbust ) // Purportedly a location test version, but has the same version number and build date as the released Japanese set below
ROM_REGION( 0x80000, "maincpu", 0 ) // 512k for 68000 code - located on Taito C0503005B main board
ROM_LOAD16_BYTE( "p.bobble_prg_h_kyotsu_6-15_c681.ic18", 0x00000, 0x40000, CRC(ba83e398) SHA1(2512ea5a805f0e5c470c4d216d679f3dc3c4aa82) ) // hand written label P.ボブル PRG H 共通 6/15 C681
ROM_LOAD16_BYTE( "p.bobble_prg_l_usa_6-15_e9e1.ic2", 0x00001, 0x40000, CRC(a12cb3f2) SHA1(06271d3a0af101a959e6e777f1f9e99bae1e6076) ) // hand written label P.ボブル PRG L USA 6/15 E9E1
ROM_REGION( 0x20000, "audiocpu", 0 ) // 128k for Z80 code - located on Taito C0503005B main board
ROM_LOAD( "prg_snd.ic27", 0x00000, 0x20000, CRC(2f288fe0) SHA1(4ba707f4b3a1ca0e573652d1c733ee889f9fef8a) ) // hand written label PRG SND IC 27 - no checksum listed
ROM_REGION( 0x100000, "tc0180vcu", 0 ) // located on Taito C0503002A ROM PCB
ROM_LOAD16_BYTE( "p.bobble_chr-1l_6-14_eaa0.ic11_ch_1_0l", 0x00000, 0x40000, CRC(8d3fa2f0) SHA1(3d36944e35081740469df61a40e538eb94ea2ef6) ) // hand written label P.ボブル CHR 1L 6/14 EAA0
ROM_LOAD16_BYTE( "p.bobble_chr-1h_6-14_1515.ic12_ch_1_0h", 0x00001, 0x40000, CRC(a2eb4d32) SHA1(571811a543af50cc5e0f1d7aad9fc388919e93e6) ) // hand written label P.ボブル CHR 1H 6/14 1515
ROM_LOAD16_BYTE( "p.bobble_chr-0l_6-14_86d5.ic7_ch_0_0l", 0x80000, 0x40000, CRC(80f1aab0) SHA1(f5cdb93aa702fb8ba91eaf8f470b6e2a61a581b5) ) // hand written label P.ボブル CHR 0L 6/14 86D5
ROM_LOAD16_BYTE( "p.bobble_chr-0h_6-14_d180.ic8_ch_0_0h", 0x80001, 0x40000, CRC(d773cac8) SHA1(b008a21c39650a28cba402cd1c4de0567e275bc9) ) // hand written label P.ボブル CHR 0H 6/14 D180 (label torn, checksum illegible besides final 0)
ROM_REGION( 0x100000, "ymsnd:adpcma", 0 ) // located on Taito C0503002A ROM PCB - Half the size of the Japanese ADPCMA sample ROM
ROM_LOAD( "cr40-kaigai-7bec.ic15_ach_0", 0x00000, 0x80000, CRC(f203ae52) SHA1(d41b880ef17eea6614e2911318db5cd070473381) ) // hand written label CR40 海外 7BEC
ROM_END
ROM_START( spacedx )
ROM_REGION( 0x80000, "maincpu", 0 ) /* 512k for 68000 code */
ROM_LOAD16_BYTE( "d89-06", 0x00000, 0x40000, CRC(7122751e) SHA1(4b4eb58af28f1988ff102251407449d0affbd4c2) )
@ -3574,8 +3574,8 @@ GAME( 1993, ryujina, ryujin, selfeena, ryujin, taitob_state, init_taito_b,
GAME( 1993, qzshowby, 0, qzshowby, qzshowby, taitob_state, init_taito_b, ROT0, "Taito Corporation", "Quiz Sekai wa SHOW by shobai (Japan)", MACHINE_SUPPORTS_SAVE )
GAME( 1994, bublbust, 0, pbobble, pbobble, taitob_state, init_taito_b, ROT0, "Taito America Corporation", "Bubble Buster (USA, B-System)", MACHINE_SUPPORTS_SAVE ) // PUZZLE VER 2.0A 1994/06/15 15:28:30 - Location test but same build as Japan release?
GAME( 1994, pbobble, bublbust,pbobble, pbobble, taitob_state, init_taito_b, ROT0, "Taito Corporation", "Puzzle Bobble (Japan, B-System)", MACHINE_SUPPORTS_SAVE ) // PUZZLE VER 2.0J 1994/06/15 15:28:30
GAME( 1994, pbobble, 0, pbobble, pbobble, taitob_state, init_taito_b, ROT0, "Taito Corporation", "Puzzle Bobble (Japan, B-System)", MACHINE_SUPPORTS_SAVE ) // PUZZLE VER 2.0J 1994/06/15 15:28:30
GAME( 1994, bublbust, pbobble, pbobble, pbobble, taitob_state, init_taito_b, ROT0, "Taito America Corporation", "Bubble Buster (USA, B-System)", MACHINE_SUPPORTS_SAVE ) // PUZZLE VER 2.0A 1994/06/15 15:28:30 - Location test but same build as Japan release?
GAME( 1994, spacedx, 0, spacedx, pbobble, taitob_state, init_taito_b, ROT0, "Taito Corporation", "Space Invaders DX (US, v2.1)", MACHINE_SUPPORTS_SAVE )
GAME( 1994, spacedxj, spacedx, spacedx, pbobble, taitob_state, init_taito_b, ROT0, "Taito Corporation", "Space Invaders DX (Japan, v2.1)", MACHINE_SUPPORTS_SAVE )

View File

@ -38,6 +38,9 @@
may have spacing adjusted in a way that affects behaviour when
uncommented
Known JSON limitations:
* Doesn't detect invalid numbers or literals
Known XML limitations:
* No special handling for CDATA
* No special handling for processing instructions
@ -102,14 +105,20 @@ protected:
static constexpr char32_t HORIZONTAL_TAB = 0x0000'0009U;
static constexpr char32_t LINE_FEED = 0x0000'000aU;
static constexpr char32_t VERTICAL_TAB = 0x0000'000bU;
static constexpr char32_t FORM_FEED = 0x0000'000cU;
static constexpr char32_t C0_CONTROL_LAST = 0x0000'001fU;
static constexpr char32_t SPACE = 0x0000'0020U;
static constexpr char32_t DOUBLE_QUOTE = 0x0000'0022U;
static constexpr char32_t SINGLE_QUOTE = 0x0000'0027U;
static constexpr char32_t ASTERISK = 0x0000'002aU;
static constexpr char32_t HYPHEN_MINUS = 0x0000'002dU;
static constexpr char32_t SLASH = 0x0000'002fU;
static constexpr char32_t QUESTION_MARK = 0x0000'003fU;
static constexpr char32_t BACKSLASH = 0x0000'005cU;
static constexpr char32_t BASIC_LATIN_LAST = 0x0000'007fU;
static constexpr char32_t CYRILLIC_SUPPLEMENT_LAST = 0x0000'052fU;
static constexpr char32_t LINE_SEPARATOR = 0x0000'2028U;
static constexpr char32_t PARAGRAPH_SEPARATOR = 0x0000'2029U;
template <typename OutputIt>
cleaner_base(OutputIt &&output, newline newline_mode, unsigned tab_width);
@ -825,8 +834,6 @@ protected:
void output_character(char32_t ch);
private:
static constexpr char32_t ASTERISK = 0x0000'002aU;
static constexpr char32_t SLASH = 0x0000'002fU;
static constexpr char32_t UPPERCASE_FIRST = 0x0000'0041U;
static constexpr char32_t UPPERCASE_B = 0x0000'0042U;
static constexpr char32_t UPPERCASE_X = 0x0000'0058U;
@ -1740,6 +1747,289 @@ void lua_cleaner::process_long_string_constant(char32_t ch)
/***************************************************************************
JSON DATA CLEANER CLASS
***************************************************************************/
class json_cleaner : public cleaner_base
{
public:
template <typename OutputIt>
json_cleaner(OutputIt &&output, newline newline_mode, unsigned tab_width);
virtual bool affected() const override;
virtual void summarise(std::ostream &os) const override;
protected:
void output_character(char32_t ch);
private:
enum class parse_state
{
DEFAULT,
COMMENT,
LINE_COMMENT,
STRING_CONSTANT
};
virtual void process_characters(char32_t const *begin, char32_t const *end) override;
virtual void input_complete() override;
void process_default(char32_t ch);
void process_comment(char32_t ch);
void process_line_comment(char32_t ch);
void process_text(char32_t ch);
parse_state m_parse_state = parse_state::DEFAULT;
std::uint64_t m_input_line = 1U;
bool m_escape = false;
std::uint64_t m_comment_line = 0U;
std::uint64_t m_tabs_escaped = 0U;
std::uint64_t m_newlines_escaped = 0U;
std::uint64_t m_form_feeds_escaped = 0U;
std::uint64_t m_line_separators_escaped = 0U;
std::uint64_t m_paragraph_separators_escaped = 0U;
std::uint64_t m_c0_control_escaped = 0U;
std::uint64_t m_non_ascii = 0U;
};
template <typename OutputIt>
json_cleaner::json_cleaner(
OutputIt &&output,
newline newline_mode,
unsigned tab_width)
: cleaner_base(std::forward<OutputIt>(output), newline_mode, tab_width)
{
}
bool json_cleaner::affected() const
{
return
cleaner_base::affected() ||
m_tabs_escaped ||
m_newlines_escaped ||
m_form_feeds_escaped ||
m_line_separators_escaped ||
m_paragraph_separators_escaped ||
m_c0_control_escaped ||
m_non_ascii;
}
void json_cleaner::summarise(std::ostream &os) const
{
cleaner_base::summarise(os);
if (m_tabs_escaped)
util::stream_format(os, "%1$u tab(s) escaped\n", m_tabs_escaped);
if (m_newlines_escaped)
util::stream_format(os, "%1$u line feed(s) escaped\n", m_newlines_escaped);
if (m_form_feeds_escaped)
util::stream_format(os, "%1$u form feed(s) escaped\n", m_form_feeds_escaped);
if (m_line_separators_escaped)
util::stream_format(os, "%1$u line separator(s) escaped\n", m_line_separators_escaped);
if (m_paragraph_separators_escaped)
util::stream_format(os, "%1$u paragraph separator(s) escaped\n", m_paragraph_separators_escaped);
if (m_c0_control_escaped)
util::stream_format(os, "%1$u C0 control character(s) escaped\n", m_c0_control_escaped);
if (m_non_ascii)
util::stream_format(os, "%1$u non-ASCII character(s) replaced\n", m_non_ascii);
}
void json_cleaner::output_character(char32_t ch)
{
switch (m_parse_state)
{
case parse_state::DEFAULT:
if (BASIC_LATIN_LAST < ch)
{
++m_non_ascii;
ch = QUESTION_MARK;
}
break;
case parse_state::COMMENT:
case parse_state::LINE_COMMENT:
case parse_state::STRING_CONSTANT:
break;
}
cleaner_base::output_character(ch);
}
void json_cleaner::process_characters(char32_t const *begin, char32_t const *end)
{
while (begin != end)
{
char32_t const ch(*begin++);
switch (m_parse_state)
{
case parse_state::DEFAULT:
process_default(ch);
break;
case parse_state::COMMENT:
process_comment(ch);
break;
case parse_state::LINE_COMMENT:
process_line_comment(ch);
break;
case parse_state::STRING_CONSTANT:
process_text(ch);
break;
}
if (LINE_FEED == ch)
++m_input_line;
}
}
void json_cleaner::input_complete()
{
switch (m_parse_state)
{
case parse_state::COMMENT:
throw std::runtime_error(util::string_format("unterminated multi-line comment beginning on line %1$u", m_comment_line));
case parse_state::STRING_CONSTANT:
throw std::runtime_error(util::string_format("unterminated string literal on line %1$u", m_input_line));
default:
break;
}
}
void json_cleaner::process_default(char32_t ch)
{
switch (ch)
{
case DOUBLE_QUOTE:
m_parse_state = parse_state::STRING_CONSTANT;
break;
case ASTERISK:
if (m_escape)
{
m_parse_state = parse_state::COMMENT;
m_comment_line = m_input_line;
set_tab_limit();
}
break;
case SLASH:
if (m_escape)
m_parse_state = parse_state::LINE_COMMENT;
break;
}
m_escape = (SLASH == ch) && !m_escape;
output_character(ch);
}
void json_cleaner::process_comment(char32_t ch)
{
switch (ch)
{
case SLASH:
if (m_escape)
{
m_parse_state = parse_state::DEFAULT;
m_comment_line = 0U;
output_character(ch);
reset_tab_limit();
}
else
{
output_character(ch);
}
m_escape = false;
break;
default:
m_escape = ASTERISK == ch;
output_character(ch);
}
}
void json_cleaner::process_line_comment(char32_t ch)
{
switch (ch)
{
case LINE_FEED:
m_parse_state = parse_state::DEFAULT;
[[fallthrough]];
default:
output_character(ch);
}
}
void json_cleaner::process_text(char32_t ch)
{
switch (ch)
{
case HORIZONTAL_TAB:
++m_tabs_escaped;
if (!m_escape)
output_character(BACKSLASH);
output_character(char32_t(std::uint8_t('t')));
break;
case LINE_FEED:
++m_newlines_escaped;
if (!m_escape)
output_character(BACKSLASH);
output_character(char32_t(std::uint8_t('n')));
break;
case FORM_FEED:
++m_form_feeds_escaped;
if (!m_escape)
output_character(BACKSLASH);
output_character(char32_t(std::uint8_t('f')));
break;
case LINE_SEPARATOR:
++m_line_separators_escaped;
if (!m_escape)
output_character(BACKSLASH);
output_character(char32_t(std::uint8_t('u')));
output_character(char32_t(std::uint8_t('2')));
output_character(char32_t(std::uint8_t('0')));
output_character(char32_t(std::uint8_t('2')));
output_character(char32_t(std::uint8_t('8')));
break;
case PARAGRAPH_SEPARATOR:
++m_paragraph_separators_escaped;
if (!m_escape)
output_character(BACKSLASH);
output_character(char32_t(std::uint8_t('u')));
output_character(char32_t(std::uint8_t('2')));
output_character(char32_t(std::uint8_t('0')));
output_character(char32_t(std::uint8_t('2')));
output_character(char32_t(std::uint8_t('9')));
break;
default:
if (C0_CONTROL_LAST >= ch)
{
++m_c0_control_escaped;
if (!m_escape)
output_character(BACKSLASH);
output_character(char32_t(std::uint8_t('u')));
output_character(char32_t(std::uint8_t('0')));
output_character(char32_t(std::uint8_t('0')));
output_character(char32_t(std::uint8_t('0') + (ch / 0x10U)));
output_character(char32_t(std::uint8_t('0') + (ch % 0x10U)));
}
else
{
output_character(ch);
if (!m_escape && (DOUBLE_QUOTE == ch))
m_parse_state = parse_state::DEFAULT;
}
}
m_escape = (BACKSLASH == ch) && !m_escape;
}
/***************************************************************************
XML DATA CLEANER CLASS
***************************************************************************/
@ -1894,6 +2184,13 @@ bool is_lua_source_extension(char const *ext)
}
bool is_json_extension(char const *ext)
{
return
!core_stricmp(ext, ".json");
}
bool is_xml_extension(char const *ext)
{
return
@ -1974,12 +2271,15 @@ int main(int argc, char *argv[])
char const *const ext(std::strrchr(argv[i], '.'));
bool const is_c_file(ext && is_c_source_extension(ext));
bool const is_lua_file(ext && is_lua_source_extension(ext));
bool const is_json_file(ext && is_json_extension(ext));
bool const is_xml_file(ext && is_xml_extension(ext));
std::unique_ptr<cleaner_base> cleaner;
if (is_c_file)
cleaner = std::make_unique<cpp_cleaner>(std::back_inserter(output), newline_mode, 4U);
else if (is_lua_file)
cleaner = std::make_unique<lua_cleaner>(std::back_inserter(output), newline_mode, 4U);
else if (is_json_file)
cleaner = std::make_unique<json_cleaner>(std::back_inserter(output), newline_mode, 4U);
else if (is_xml_file)
cleaner = std::make_unique<xml_cleaner>(std::back_inserter(output), newline_mode, 4U);
else