From 6f1d851e94b7fb296b538293546c685dc4ee8345 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 24 Aug 2026 21:14:07 +0800 Subject: [PATCH 1/3] Replace boost/regex with std locale --- src/stan/io/json/json_data_handler.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/stan/io/json/json_data_handler.hpp b/src/stan/io/json/json_data_handler.hpp index 3e0adeb279d..226ffdde074 100644 --- a/src/stan/io/json/json_data_handler.hpp +++ b/src/stan/io/json/json_data_handler.hpp @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -16,7 +16,6 @@ #include #include #include -#include namespace stan { @@ -172,8 +171,13 @@ class json_data_handler : public stan::json::json_handler { * and contain only letters, numbers, or an underscore. */ bool valid_varname(const std::string& name) { - static const boost::regex re("[a-zA-Z][a-zA-Z0-9_]*"); - return boost::regex_match(name, re); + static const std::locale locale; + if (name.empty() || !std::isalpha(name[0], locale)) { + return false; + } + return std::all_of(name.cbegin() + 1, name.cend(), [](const char c) { + return std::isalnum(c, locale) || c == '_'; + }); } bool is_array_tuples(const std::vector& keys) { From f6b7ec087a77d711b25bd933218b9e1ea4a16e51 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 24 Aug 2026 21:55:48 +0800 Subject: [PATCH 2/3] Default to C locale for varname val --- src/stan/io/json/json_data_handler.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stan/io/json/json_data_handler.hpp b/src/stan/io/json/json_data_handler.hpp index 226ffdde074..0dcc4d813b5 100644 --- a/src/stan/io/json/json_data_handler.hpp +++ b/src/stan/io/json/json_data_handler.hpp @@ -171,7 +171,7 @@ class json_data_handler : public stan::json::json_handler { * and contain only letters, numbers, or an underscore. */ bool valid_varname(const std::string& name) { - static const std::locale locale; + static const std::locale locale = std::locale::classic(); if (name.empty() || !std::isalpha(name[0], locale)) { return false; } From f6b5fbf7629435347dfc5a145c61c69389961da0 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 24 Aug 2026 22:16:37 +0800 Subject: [PATCH 3/3] Update src/stan/io/json/json_data_handler.hpp Co-authored-by: Brian Ward --- src/stan/io/json/json_data_handler.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stan/io/json/json_data_handler.hpp b/src/stan/io/json/json_data_handler.hpp index 0dcc4d813b5..b2b3faba655 100644 --- a/src/stan/io/json/json_data_handler.hpp +++ b/src/stan/io/json/json_data_handler.hpp @@ -171,7 +171,7 @@ class json_data_handler : public stan::json::json_handler { * and contain only letters, numbers, or an underscore. */ bool valid_varname(const std::string& name) { - static const std::locale locale = std::locale::classic(); + static const std::locale& locale = std::locale::classic(); if (name.empty() || !std::isalpha(name[0], locale)) { return false; }