Skip to content

Commit

Permalink
Fix failing locale test on cygwin.
Browse files Browse the repository at this point in the history
* Cygwin does not support setting a std::locale to anything other than
  the "classic" locale. Adjust "double parsing is locale-independent"
  test accordingly.

* Remove unintended use of C++11 features in AspifTextInput
  implementation.
  • Loading branch information
BenKaufmann committed Sep 30, 2024
1 parent 4434358 commit e8107a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/aspif_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <ostream>
#include <string>
Expand Down Expand Up @@ -344,7 +345,7 @@ struct AspifTextOutput::Data {
static int atomArity(const std::string& name, std::size_t* sepPos = 0) {
if (name.empty() || name[0] == '&') return -1;
std::size_t pos = std::min(name.find('('), name.size());
POTASSCO_REQUIRE(pos == name.size() || name.back() == ')', "invalid name");
POTASSCO_REQUIRE(pos == name.size() || *name.rbegin() == ')', "invalid name");
if (sepPos) *sepPos = pos;
if (name.size() - pos <= 2) {
return 0;
Expand Down Expand Up @@ -659,7 +660,7 @@ void AspifTextOutput::writeDirectives() {
}
else if (last.second != arity || n->compare(0, ep, last.first) != 0) {
last.first.resize(n->size());
auto w = snprintf(&last.first[0], n->size(), "%.*s/%d", (int) ep, n->c_str(), arity);
int w = snprintf(&last.first[0], n->size(), "%.*s/%d", (int) ep, n->c_str(), arity);
assert(w > ep);
last.first.resize(w);
if (data_->strings.insert(Data::StringMapVal(last.first, idMax)).second) {
Expand Down
3 changes: 2 additions & 1 deletion tests/test_string_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ TEST_CASE("String conversion", "[string]") {
std::string loc(it->first);
loc.append(1, *s).append(it->second).append(*code);
if (setlocale(LC_ALL, loc.c_str())) {
restore.second = std::locale::global(std::locale(loc));
INFO("Set locale to " << loc);
set = true;
CHECK_NOFAIL((restore.second = std::locale::global(std::locale(loc)), true));
}
}
}
Expand Down

0 comments on commit e8107a4

Please sign in to comment.