Git Product home page Git Product logo

Comments (2)

tlsa avatar tlsa commented on September 27, 2024

Why not just create wrappers that set and restore the locale around cyaml load/save calls?

For example something like this (untested):

bool my_yaml_loader(
		const char *path,
		my_data_t **data_out)
{
	char *old_locale, *saved_locale;
	unsigned sequence_count;
	bool ret = false;
	my_data_t *data;
	cyaml_err_t err;

	/* Get the name of the current locale.  */
	old_locale = setlocale (LC_ALL, NULL);

	/* Copy the name so it won’t be clobbered by setlocale. */
	saved_locale = strdup(old_locale);
	if (saved_locale == NULL) {
		fprintf(stderr, "Out of memory\n");
		return false;
	}

	/* Now change the locale to the one we want for loading. */
	setlocale (LC_ALL, "C");

	/* Do the load. */
	err = cyaml_load_file(path, config, schema, &data, &sequence_count);
	if (err != CYAML_OK) {
		fprintf(stderr, "Error loading %s: %s\n",
				path, cyaml_strerror(err));
		goto restore;
	}

	*data_out = data;
	ret = true;

restore:
	/* Restore the original locale. */
	setlocale (LC_ALL, saved_locale);
	free(saved_locale);

	return ret;
}

from libcyaml.

MasterMind2k avatar MasterMind2k commented on September 27, 2024

It is a work-around. I was hoping on using float parsing library that is not dependant on locale. To remove additional complexitz of setting locale.

from libcyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.