Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshal to SNBT with indent #224

Open
maxsupermanhd opened this issue Nov 26, 2022 · 2 comments
Open

Unmarshal to SNBT with indent #224

maxsupermanhd opened this issue Nov 26, 2022 · 2 comments
Labels
enhancement New feature or request nbt

Comments

@maxsupermanhd
Copy link
Contributor

I would really appreciate indentation option for SNBT format, just like with JSON.

@maxsupermanhd maxsupermanhd added the enhancement New feature or request label Nov 26, 2022
@Tnze Tnze added the nbt label Nov 27, 2022
@Tnze
Copy link
Owner

Tnze commented Dec 4, 2022

When trying to write this, my head hurts. 下次一定

It's hard

@tester2024
Copy link

tester2024 commented Nov 21, 2024

func normalizeSNBT(snbt string) string {
	snbt = strings.NewReplacer("\t", " ", "\n", " ", "\r", " ").Replace(snbt)
	snbt = regexp.MustCompile(`\s+`).ReplaceAllString(snbt, " ")
	
	snbt = regexp.MustCompile(`,\s*}`).ReplaceAllString(snbt, "}")
	snbt = regexp.MustCompile(`,\s*]`).ReplaceAllString(snbt, "]")
	
	return strings.TrimSpace(snbt)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request nbt
Projects
None yet
Development

No branches or pull requests

3 participants