Minor cleanup

Mark a function as static and use a std::string instead of malloc.
This commit is contained in:
ridiculousfish
2018-03-01 11:24:16 -08:00
committed by Fabian Homborg
parent fd6a1a436b
commit b49e1d7703

View File

@@ -113,7 +113,7 @@ static const wchar_t *math_get_arg(int *argidx, wchar_t **argv, wcstring *storag
return math_get_arg_argv(argidx, argv); return math_get_arg_argv(argidx, argv);
} }
wcstring math_describe_error(te_error_t& error) { static wcstring math_describe_error(te_error_t& error) {
if (error.position == 0) return L"NO ERROR?!?"; if (error.position == 0) return L"NO ERROR?!?";
assert(error.type != TE_ERROR_NONE && L"Error has no position"); assert(error.type != TE_ERROR_NONE && L"Error has no position");
@@ -136,13 +136,13 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_
int retval = STATUS_CMD_OK; int retval = STATUS_CMD_OK;
te_error_t error; te_error_t error;
char *narrow_str = wcs2str(expression); std::string narrow_str = wcs2string(expression);
// Switch locale while computing stuff. // Switch locale while computing stuff.
// This means that the "." is always the radix character, // This means that the "." is always the radix character,
// so numbers work the same across locales. // so numbers work the same across locales.
char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL)); char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
double v = te_interp(narrow_str, &error); double v = te_interp(narrow_str.c_str(), &error);
if (error.position == 0) { if (error.position == 0) {
if (opts.scale == 0) { if (opts.scale == 0) {
@@ -156,7 +156,6 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_
streams.err.append_format(L"%*lc^\n", error.position - 1, L' '); streams.err.append_format(L"%*lc^\n", error.position - 1, L' ');
retval = STATUS_CMD_ERROR; retval = STATUS_CMD_ERROR;
} }
free(narrow_str);
setlocale(LC_NUMERIC, saved_locale); setlocale(LC_NUMERIC, saved_locale);
free(saved_locale); free(saved_locale);
return retval; return retval;