2002-05-24 12:53:12 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-03-05 18:22:35 +00:00
|
|
|
* Copyright (c) 2004
|
|
|
|
* John Maddock
|
2002-05-24 12:53:12 +00:00
|
|
|
*
|
2004-02-05 09:14:22 +00:00
|
|
|
* Use, modification and distribution are subject to the
|
|
|
|
* Boost Software License, Version 1.0. (See accompanying file
|
|
|
|
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
2002-05-24 12:53:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LOCATION: see http://www.boost.org for most recent version.
|
2006-03-05 18:22:35 +00:00
|
|
|
* FILE w32_regex_traits.cpp
|
|
|
|
* VERSION see <boost/version.hpp>
|
|
|
|
* DESCRIPTION: Implements w32_regex_traits<char> (and associated helper classes).
|
2002-05-24 12:53:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define BOOST_REGEX_SOURCE
|
2006-03-05 18:22:35 +00:00
|
|
|
#include <boost/regex/config.hpp>
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2003-03-03 15:53:48 +00:00
|
|
|
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
|
2006-03-05 18:22:35 +00:00
|
|
|
#include <boost/regex/regex_traits.hpp>
|
|
|
|
#include <boost/regex/pattern_except.hpp>
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2006-09-05 07:18:36 +00:00
|
|
|
#ifndef NOMINMAX
|
|
|
|
# define NOMINMAX
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
#define NOGDI
|
|
|
|
#include <windows.h>
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2008-09-30 18:01:03 +00:00
|
|
|
#if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
2002-05-24 12:53:12 +00:00
|
|
|
#pragma comment(lib, "user32.lib")
|
|
|
|
#endif
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
|
|
|
namespace std{
|
|
|
|
using ::memset;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
namespace boost{ namespace re_detail{
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifdef BOOST_NO_ANSI_APIS
|
|
|
|
UINT get_code_page_for_locale_id(lcid_type id)
|
|
|
|
{
|
|
|
|
WCHAR code_page_string[7];
|
|
|
|
if (::GetLocaleInfoW(id, LOCALE_IDEFAULTANSICODEPAGE, code_page_string, 7) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return static_cast<UINT>(_wtol(code_page_string));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
void w32_regex_traits_char_layer<char>::init()
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
// we need to start by initialising our syntax map so we know which
|
|
|
|
// character is used for which purpose:
|
|
|
|
std::memset(m_char_map, 0, sizeof(m_char_map));
|
|
|
|
cat_type cat;
|
|
|
|
std::string cat_name(w32_regex_traits<char>::get_catalog_name());
|
|
|
|
if(cat_name.size())
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
cat = ::boost::re_detail::w32_cat_open(cat_name);
|
|
|
|
if(!cat)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
std::string m("Unable to open message catalog: ");
|
|
|
|
std::runtime_error err(m + cat_name);
|
|
|
|
::boost::re_detail::raise_runtime_error(err);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
//
|
|
|
|
// if we have a valid catalog then load our messages:
|
|
|
|
//
|
|
|
|
if(cat)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
string_type mss = ::boost::re_detail::w32_cat_get(cat, this->m_locale, i, get_default_syntax(i));
|
|
|
|
for(string_type::size_type j = 0; j < mss.size(); ++j)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
m_char_map[static_cast<unsigned char>(mss[j])] = i;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
const char* ptr = get_default_syntax(i);
|
|
|
|
while(ptr && *ptr)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
m_char_map[static_cast<unsigned char>(*ptr)] = i;
|
|
|
|
++ptr;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// finish off by calculating our escape types:
|
|
|
|
//
|
|
|
|
unsigned char i = 'A';
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(m_char_map[i] == 0)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
if(::boost::re_detail::w32_is(this->m_locale, 0x0002u, (char)i))
|
|
|
|
m_char_map[i] = regex_constants::escape_type_class;
|
|
|
|
else if(::boost::re_detail::w32_is(this->m_locale, 0x0001u, (char)i))
|
|
|
|
m_char_map[i] = regex_constants::escape_type_not_class;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
}while(0xFF != i++);
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
//
|
|
|
|
// fill in lower case map:
|
|
|
|
//
|
|
|
|
char char_map[1 << CHAR_BIT];
|
|
|
|
for(int ii = 0; ii < (1 << CHAR_BIT); ++ii)
|
|
|
|
char_map[ii] = static_cast<char>(ii);
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
int r = ::LCMapStringA(this->m_locale, LCMAP_LOWERCASE, char_map, 1 << CHAR_BIT, this->m_lower_map, 1 << CHAR_BIT);
|
|
|
|
BOOST_ASSERT(r != 0);
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(this->m_locale);
|
|
|
|
BOOST_ASSERT(code_page != 0);
|
|
|
|
|
|
|
|
WCHAR wide_char_map[1 << CHAR_BIT];
|
|
|
|
int conv_r = ::MultiByteToWideChar(code_page, 0, char_map, 1 << CHAR_BIT, wide_char_map, 1 << CHAR_BIT);
|
|
|
|
BOOST_ASSERT(conv_r != 0);
|
|
|
|
|
|
|
|
WCHAR wide_lower_map[1 << CHAR_BIT];
|
|
|
|
int r = ::LCMapStringW(this->m_locale, LCMAP_LOWERCASE, wide_char_map, 1 << CHAR_BIT, wide_lower_map, 1 << CHAR_BIT);
|
|
|
|
BOOST_ASSERT(r != 0);
|
|
|
|
|
|
|
|
conv_r = ::WideCharToMultiByte(code_page, 0, wide_lower_map, r, this->m_lower_map, 1 << CHAR_BIT, NULL, NULL);
|
|
|
|
BOOST_ASSERT(conv_r != 0);
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
if(r < (1 << CHAR_BIT))
|
|
|
|
{
|
|
|
|
// if we have multibyte characters then not all may have been given
|
|
|
|
// a lower case mapping:
|
|
|
|
for(int jj = r; jj < (1 << CHAR_BIT); ++jj)
|
|
|
|
this->m_lower_map[jj] = static_cast<char>(jj);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2008-09-30 18:01:03 +00:00
|
|
|
|
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
r = ::GetStringTypeExA(this->m_locale, CT_CTYPE1, char_map, 1 << CHAR_BIT, this->m_type_map);
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
r = ::GetStringTypeExW(this->m_locale, CT_CTYPE1, wide_char_map, 1 << CHAR_BIT, this->m_type_map);
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_ASSERT(0 != r);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL lcid_type BOOST_REGEX_CALL w32_get_default_locale()
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
return ::GetUserDefaultLCID();
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(char c, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExA(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER))
|
|
|
|
return true;
|
|
|
|
return false;
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(id);
|
|
|
|
if (code_page == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WCHAR wide_c;
|
|
|
|
if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &wide_c, 1, &mask) && (mask & C1_LOWER))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(wchar_t c, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER))
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(unsigned short ca, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
wchar_t c = ca;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER))
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(char c, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExA(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_UPPER))
|
|
|
|
return true;
|
|
|
|
return false;
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(id);
|
|
|
|
if (code_page == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WCHAR wide_c;
|
|
|
|
if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &wide_c, 1, &mask) && (mask & C1_UPPER))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(wchar_t c, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_UPPER))
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(unsigned short ca, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
wchar_t c = ca;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_UPPER))
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
void free_module(void* mod)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
::FreeLibrary(static_cast<HMODULE>(mod));
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL cat_type BOOST_REGEX_CALL w32_cat_open(const std::string& name)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
cat_type result(::LoadLibraryA(name.c_str()), &free_module);
|
|
|
|
return result;
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
LPWSTR wide_name = (LPWSTR)_alloca( (name.size() + 1) * sizeof(WCHAR) );
|
|
|
|
if (::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.size(), wide_name, name.size() + 1) == 0)
|
|
|
|
return cat_type();
|
|
|
|
|
|
|
|
cat_type result(::LoadLibraryW(wide_name), &free_module);
|
|
|
|
return result;
|
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::string& def)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
char buf[256];
|
|
|
|
if(0 == ::LoadStringA(
|
|
|
|
static_cast<HMODULE>(cat.get()),
|
|
|
|
i,
|
|
|
|
buf,
|
|
|
|
256
|
|
|
|
))
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
return def;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
WCHAR wbuf[256];
|
|
|
|
int r = ::LoadStringW(
|
|
|
|
static_cast<HMODULE>(cat.get()),
|
|
|
|
i,
|
|
|
|
wbuf,
|
|
|
|
256
|
|
|
|
);
|
|
|
|
if (r == 0)
|
|
|
|
return def;
|
|
|
|
|
|
|
|
LPSTR buf = (LPSTR)_alloca( (r + 1) * 2 );
|
|
|
|
if (::WideCharToMultiByte(CP_ACP, 0, wbuf, r, buf, (r + 1) * 2, NULL, NULL) == 0)
|
|
|
|
return def;
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
return std::string(buf);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifndef BOOST_NO_WREGEX
|
|
|
|
BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::wstring& def)
|
|
|
|
{
|
|
|
|
wchar_t buf[256];
|
|
|
|
if(0 == ::LoadStringW(
|
|
|
|
static_cast<HMODULE>(cat.get()),
|
|
|
|
i,
|
|
|
|
buf,
|
|
|
|
256
|
|
|
|
))
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
return def;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
return std::wstring(buf);
|
|
|
|
}
|
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::basic_string<unsigned short>& def)
|
|
|
|
{
|
|
|
|
unsigned short buf[256];
|
|
|
|
if(0 == ::LoadStringW(
|
|
|
|
static_cast<HMODULE>(cat.get()),
|
|
|
|
i,
|
|
|
|
(LPWSTR)buf,
|
|
|
|
256
|
|
|
|
))
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
return def;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
return std::basic_string<unsigned short>(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type id, const char* p1, const char* p2)
|
|
|
|
{
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
int bytes = ::LCMapStringA(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
p1, // source string
|
|
|
|
static_cast<int>(p2 - p1), // number of characters in source string
|
|
|
|
0, // destination buffer
|
|
|
|
0 // size of destination buffer
|
|
|
|
);
|
|
|
|
if(!bytes)
|
|
|
|
return std::string(p1, p2);
|
|
|
|
std::string result(++bytes, '\0');
|
|
|
|
bytes = ::LCMapStringA(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
p1, // source string
|
|
|
|
static_cast<int>(p2 - p1), // number of characters in source string
|
|
|
|
&*result.begin(), // destination buffer
|
|
|
|
bytes // size of destination buffer
|
|
|
|
);
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(id);
|
|
|
|
if(code_page == 0)
|
|
|
|
return std::string(p1, p2);
|
|
|
|
|
|
|
|
int src_len = static_cast<int>(p2 - p1);
|
|
|
|
LPWSTR wide_p1 = (LPWSTR)_alloca( (src_len + 1) * 2 );
|
|
|
|
if(::MultiByteToWideChar(code_page, 0, p1, src_len, wide_p1, src_len + 1) == 0)
|
|
|
|
return std::string(p1, p2);
|
|
|
|
|
|
|
|
int bytes = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
wide_p1, // source string
|
|
|
|
src_len, // number of characters in source string
|
|
|
|
0, // destination buffer
|
|
|
|
0 // size of destination buffer
|
|
|
|
);
|
|
|
|
if(!bytes)
|
|
|
|
return std::string(p1, p2);
|
|
|
|
std::string result(++bytes, '\0');
|
|
|
|
bytes = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
wide_p1, // source string
|
|
|
|
src_len, // number of characters in source string
|
|
|
|
(LPWSTR)&*result.begin(), // destination buffer
|
|
|
|
bytes // size of destination buffer
|
|
|
|
);
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
if(bytes > static_cast<int>(result.size()))
|
|
|
|
return std::string(p1, p2);
|
|
|
|
while(result.size() && result[result.size()-1] == '\0')
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
result.erase(result.size()-1);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef BOOST_NO_WREGEX
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_transform(lcid_type id, const wchar_t* p1, const wchar_t* p2)
|
|
|
|
{
|
|
|
|
int bytes = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
p1, // source string
|
|
|
|
static_cast<int>(p2 - p1), // number of characters in source string
|
|
|
|
0, // destination buffer
|
|
|
|
0 // size of destination buffer
|
|
|
|
);
|
|
|
|
if(!bytes)
|
|
|
|
return std::wstring(p1, p2);
|
|
|
|
std::string result(++bytes, '\0');
|
|
|
|
bytes = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
p1, // source string
|
|
|
|
static_cast<int>(p2 - p1), // number of characters in source string
|
|
|
|
reinterpret_cast<wchar_t*>(&*result.begin()), // destination buffer *of bytes*
|
|
|
|
bytes // size of destination buffer
|
|
|
|
);
|
|
|
|
if(bytes > static_cast<int>(result.size()))
|
|
|
|
return std::wstring(p1, p2);
|
|
|
|
while(result.size() && result[result.size()-1] == L'\0')
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
result.erase(result.size()-1);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
std::wstring r2;
|
|
|
|
for(std::string::size_type i = 0; i < result.size(); ++i)
|
|
|
|
r2.append(1, static_cast<wchar_t>(static_cast<unsigned char>(result[i])));
|
|
|
|
return r2;
|
|
|
|
}
|
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_transform(lcid_type id, const unsigned short* p1, const unsigned short* p2)
|
|
|
|
{
|
|
|
|
int bytes = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
(LPCWSTR)p1, // source string
|
|
|
|
static_cast<int>(p2 - p1), // number of characters in source string
|
|
|
|
0, // destination buffer
|
|
|
|
0 // size of destination buffer
|
|
|
|
);
|
|
|
|
if(!bytes)
|
|
|
|
return std::basic_string<unsigned short>(p1, p2);
|
|
|
|
std::string result(++bytes, '\0');
|
|
|
|
bytes = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_SORTKEY, // mapping transformation type
|
|
|
|
(LPCWSTR)p1, // source string
|
|
|
|
static_cast<int>(p2 - p1), // number of characters in source string
|
|
|
|
reinterpret_cast<wchar_t*>(&*result.begin()), // destination buffer *of bytes*
|
|
|
|
bytes // size of destination buffer
|
|
|
|
);
|
|
|
|
if(bytes > static_cast<int>(result.size()))
|
|
|
|
return std::basic_string<unsigned short>(p1, p2);
|
|
|
|
while(result.size() && result[result.size()-1] == L'\0')
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
result.erase(result.size()-1);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
std::basic_string<unsigned short> r2;
|
|
|
|
for(std::string::size_type i = 0; i < result.size(); ++i)
|
|
|
|
r2.append(1, static_cast<unsigned short>(static_cast<unsigned char>(result[i])));
|
|
|
|
return r2;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type id)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
char result[2];
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
int b = ::LCMapStringA(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_LOWERCASE, // mapping transformation type
|
|
|
|
&c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(id);
|
|
|
|
if (code_page == 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
WCHAR wide_c;
|
|
|
|
if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
WCHAR wide_result;
|
|
|
|
int b = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_LOWERCASE, // mapping transformation type
|
|
|
|
&wide_c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
&wide_result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
if (::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0)
|
|
|
|
return c;
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
return result[0];
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifndef BOOST_NO_WREGEX
|
|
|
|
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_tolower(wchar_t c, lcid_type id)
|
|
|
|
{
|
|
|
|
wchar_t result[2];
|
|
|
|
int b = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_LOWERCASE, // mapping transformation type
|
|
|
|
&c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
|
|
|
return result[0];
|
|
|
|
}
|
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_tolower(unsigned short c, lcid_type id)
|
|
|
|
{
|
|
|
|
wchar_t result[2];
|
|
|
|
int b = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_LOWERCASE, // mapping transformation type
|
|
|
|
(wchar_t const*)&c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
|
|
|
return result[0];
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
|
|
|
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type id)
|
|
|
|
{
|
|
|
|
char result[2];
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
int b = ::LCMapStringA(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_UPPERCASE, // mapping transformation type
|
|
|
|
&c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(id);
|
|
|
|
if(code_page == 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
WCHAR wide_c;
|
|
|
|
if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
WCHAR wide_result;
|
|
|
|
int b = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_UPPERCASE, // mapping transformation type
|
|
|
|
&wide_c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
&wide_result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
if (::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0)
|
|
|
|
return c;
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
return result[0];
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifndef BOOST_NO_WREGEX
|
|
|
|
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_toupper(wchar_t c, lcid_type id)
|
|
|
|
{
|
|
|
|
wchar_t result[2];
|
|
|
|
int b = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_UPPERCASE, // mapping transformation type
|
|
|
|
&c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
|
|
|
return result[0];
|
|
|
|
}
|
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_toupper(unsigned short c, lcid_type id)
|
|
|
|
{
|
|
|
|
wchar_t result[2];
|
|
|
|
int b = ::LCMapStringW(
|
|
|
|
id, // locale identifier
|
|
|
|
LCMAP_UPPERCASE, // mapping transformation type
|
|
|
|
(wchar_t const*)&c, // source string
|
|
|
|
1, // number of characters in source string
|
|
|
|
result, // destination buffer
|
|
|
|
1); // size of destination buffer
|
|
|
|
if(b == 0)
|
|
|
|
return c;
|
|
|
|
return result[0];
|
|
|
|
}
|
2002-05-24 12:53:12 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type id, boost::uint32_t m, char c)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
|
|
|
WORD mask;
|
2008-09-30 18:01:03 +00:00
|
|
|
#ifndef BOOST_NO_ANSI_APIS
|
2006-03-05 18:22:35 +00:00
|
|
|
if(::GetStringTypeExA(id, CT_CTYPE1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation<char>::mask_base))
|
|
|
|
return true;
|
2008-09-30 18:01:03 +00:00
|
|
|
#else
|
|
|
|
UINT code_page = get_code_page_for_locale_id(id);
|
|
|
|
if(code_page == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WCHAR wide_c;
|
|
|
|
if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &wide_c, 1, &mask) && (mask & m & w32_regex_traits_implementation<char>::mask_base))
|
|
|
|
return true;
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
if((m & w32_regex_traits_implementation<char>::mask_word) && (c == '_'))
|
2002-05-24 12:53:12 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifndef BOOST_NO_WREGEX
|
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type id, boost::uint32_t m, wchar_t c)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation<wchar_t>::mask_base))
|
|
|
|
return true;
|
|
|
|
if((m & w32_regex_traits_implementation<wchar_t>::mask_word) && (c == '_'))
|
|
|
|
return true;
|
|
|
|
if((m & w32_regex_traits_implementation<wchar_t>::mask_unicode) && (c > 0xff))
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
|
|
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type id, boost::uint32_t m, unsigned short c)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
WORD mask;
|
|
|
|
if(::GetStringTypeExW(id, CT_CTYPE1, (wchar_t const*)&c, 1, &mask) && (mask & m & w32_regex_traits_implementation<wchar_t>::mask_base))
|
|
|
|
return true;
|
|
|
|
if((m & w32_regex_traits_implementation<wchar_t>::mask_word) && (c == '_'))
|
|
|
|
return true;
|
|
|
|
if((m & w32_regex_traits_implementation<wchar_t>::mask_unicode) && (c > 0xff))
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
} // re_detail
|
|
|
|
} // boost
|
2004-02-05 09:14:22 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
2004-02-05 09:14:22 +00:00
|
|
|
|