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

Trouble with FileToKeyValues #627

Closed
joao-mambelli opened this issue Jun 22, 2017 · 1 comment
Closed

Trouble with FileToKeyValues #627

joao-mambelli opened this issue Jun 22, 2017 · 1 comment

Comments

@joao-mambelli
Copy link

joao-mambelli commented Jun 22, 2017

I'm having troubles trying to read a KeyValues tree from a file that is saved as UTF-8. I was having unexpected behaves in my code, so I decided to read and output the following file, just to see what happens:

"Test0"
{
	"test1"
	{
		"test"		"123"
	}
	"test2"
	{
		"test"		"123"
	}
}

And I read and output the file using:

char file[PLATFORM_MAX_PATH];
BuildPath(Path_SM, file, PLATFORM_MAX_PATH, "test1.txt");
Handle kv = CreateKeyValues("Test0");
FileToKeyValues(kv, file);
BuildPath(Path_SM, file, PLATFORM_MAX_PATH, "test2.txt");
KeyValuesToFile(kv, file);
CloseHandle(kv);

I received these on console:

KeyValues Error: LoadFromBuffer: missing { in file addons\sourcemod\test1.txt

KeyValues Error: LoadFromBuffer: missing { in file addons\sourcemod\test1.txt

KeyValues Error: LoadFromBuffer: missing { in file addons\sourcemod\test1.txt

KeyValues Error: LoadFromBuffer: missing { in file addons\sourcemod\test1.txt

KeyValues Error: LoadFromBuffer: missing { in file addons\sourcemod\test1.txt
(*test2*),

And my output was:

""
{
}

I think the symbols used by the file to tell it's an UTF-8, is messing with the sourcemod reading it.

P.S.: Ok, so I realized the cause of it, it's the BOM, the UTF-8 without BOM will work, but since I need to use special characters, it's useless, so I just request a feature to allow us to read an UTF-8 file with BOM.

@asherkin
Copy link
Member

UTF-8 without BOM is the correct format to use and will support all Unicode characters. None of the Source Engine or SourceMod file routines support byte order marks and it is not something that will be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants