Querz / NBT

A java implementation of the NBT protocol, including a way to implement custom tags.
MIT License
182 stars 48 forks source link

Add array type indicator and string escaping #5

Closed jochembroekhoff closed 6 years ago

jochembroekhoff commented 6 years ago

This PR adds support for the following two new features:

To check if a string needs to be escaped, it simply checks if the pattern [A-z0-9_\\-+]+ does not match. I've tested that in-game and it seemed like the game only accepts non-escaped strings in that pattern.

This makes it possible to really use the output of toTagString() in a Minecraft command. Without the array type indicator and without the string escaping, it might sometimes not work.

I've updated the unit tests as well.

jochembroekhoff commented 6 years ago

Hi, what's the reason behind changing the + to *? The + was there to make sure that empty strings are transformed to "" instead of nothing.

Querz commented 6 years ago

You're right, i didn't see that you moved the quotes to that new method.

I also changed your pattern to A-Za-z, because A-z also includes all ASCII-characters between Z and a (which includes \, see http://www.asciitable.com/).