OSDN Git Service

fix #38565
authorSHIRAKATA Kentaro <argrath@ub32.org>
Tue, 4 Sep 2018 18:16:17 +0000 (03:16 +0900)
committerSHIRAKATA Kentaro <argrath@ub32.org>
Tue, 4 Sep 2018 18:16:17 +0000 (03:16 +0900)
ChangeLog.j
sys/share/cppregex.cpp

index 12642f1..7726312 100644 (file)
@@ -1,6 +1,7 @@
        * \8e\9f\82Ì\96â\91è\82ð\8fC\90³
          * #wizwhere\83R\83}\83\93\83h\82Å\83N\83\89\83b\83V\83\85\82·\82é (#38569)
          * 2\83o\83C\83g\95\8e\9a\95\\8e¦\8e\9e\82É\91®\90«\95Ï\8dX\82ª\8ds\82í\82ê\82È\82¢ (#38566)
+         * \90³\8bK\95\\8c»\82ª\90³\82µ\82­\93®\8dì\82µ\82È\82¢ (#38565)
        * \96|\96ó\92Ç\89Á\8fC\90³
 
 Thu Jun 21 2018  Kentaro Shirakata  <argrath@ub32.org>
index cba44b8..89abaad 100644 (file)
@@ -5,16 +5,37 @@
 
 #include <regex>
 #include <memory>
+#include <windows.h>
 
 /* nhregex interface documented in sys/share/posixregex.c */
 
+#if 1 /*JP*/
+static std::wstring s2w(const char *s) {
+  std::string src = std::string(s);
+  auto const dest_size = ::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, nullptr, 0U);
+  std::vector<wchar_t> dest(dest_size, L'\0');
+  if (::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, dest.data(), dest.size()) == 0) {
+    return std::wstring(L"");
+  }
+  dest.resize(std::char_traits<wchar_t>::length(dest.data()));
+  dest.shrink_to_fit();
+  return std::wstring(dest.begin(), dest.end());
+  }
+#endif
+
 extern "C" {
+#if 0 /*JP*/
   #include <hack.h>
+#endif
 
   extern const char regex_id[] = "cppregex";
 
   struct nhregex {
+#if 0 /*JP*/
     std::unique_ptr<std::regex> re;
+#else
+    std::unique_ptr<std::wregex> re;
+#endif
     std::unique_ptr<std::regex_error> err;
   };
 
@@ -26,9 +47,15 @@ extern "C" {
     if (!re)
       return FALSE;
     try {
+#if 0 /*JP*/
       re->re.reset(new std::regex(s, (std::regex::extended
                                     | std::regex::nosubs
                                     | std::regex::optimize)));
+#else
+      re->re.reset(new std::wregex(s2w(s), (std::regex::extended
+                                     | std::regex::nosubs
+                                     | std::regex::optimize)));
+#endif
       re->err.reset(nullptr);
       return TRUE;
     } catch (const std::regex_error& err) {
@@ -49,7 +76,11 @@ extern "C" {
     if (!re->re)
       return false;
     try {
+#if 0 /*JP*/
       return regex_search(s, *re->re, std::regex_constants::match_any);
+#else
+      return regex_search(s2w(s), *re->re, std::regex_constants::match_any);
+#endif
     } catch (const std::regex_error& err) {
       return false;
     }