forked from boostorg/regex
Apply patches for building regex on WinCE see: http://lists.boost.org/Archives/boost/2007/11/130839.php
[SVN r41327]
This commit is contained in:
@ -143,7 +143,7 @@ int main(int argc, char**argv)
|
||||
boost::match_results<std::deque<char>::iterator> dm;
|
||||
std::string s1, s2, ts;
|
||||
std::deque<char> ds;
|
||||
boost::regex_t r;
|
||||
boost::regex_tA r;
|
||||
boost::scoped_array<boost::regmatch_t> matches;
|
||||
std::size_t nsubs;
|
||||
boost::timer t;
|
||||
@ -175,12 +175,12 @@ int main(int argc, char**argv)
|
||||
cout << "Error in expression: \"" << e.what() << "\"" << endl;
|
||||
continue;
|
||||
}
|
||||
int code = regcomp(&r, s1.c_str(), boost::REG_PERL);
|
||||
int code = regcompA(&r, s1.c_str(), boost::REG_PERL);
|
||||
if(code != 0)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(code, &r, buf, 256);
|
||||
cout << "regcomp error: \"" << buf << "\"" << endl;
|
||||
regerrorA(code, &r, buf, 256);
|
||||
cout << "regcompA error: \"" << buf << "\"" << endl;
|
||||
continue;
|
||||
}
|
||||
nsubs = r.re_nsub + 1;
|
||||
@ -324,17 +324,17 @@ int main(int argc, char**argv)
|
||||
iters = 10;
|
||||
tim = 1.1;
|
||||
// cache load:
|
||||
regexec(&r, s2.c_str(), nsubs, matches.get(), 0);
|
||||
regex_tA(&r, s2.c_str(), nsubs, matches.get(), 0);
|
||||
do{
|
||||
iters *= (tim > 0.001) ? (1.1/tim) : 100;
|
||||
t.restart();
|
||||
for(i = 0; i < iters; ++i)
|
||||
{
|
||||
result = regexec(&r, s2.c_str(), nsubs, matches.get(), 0);
|
||||
result = regex_tA(&r, s2.c_str(), nsubs, matches.get(), 0);
|
||||
}
|
||||
tim = t.elapsed();
|
||||
}while(tim < wait_time);
|
||||
cout << "POSIX regexec time: " << (tim * 1000000 / iters) << "us" << endl;
|
||||
cout << "POSIX regex_tA time: " << (tim * 1000000 / iters) << "us" << endl;
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
@ -360,7 +360,7 @@ int main(int argc, char**argv)
|
||||
cout << "\" (matched=" << (matches[0].rm_eo != s2.size()) << ")" << endl << endl;
|
||||
}
|
||||
}
|
||||
regfree(&r);
|
||||
regfreeA(&r);
|
||||
}
|
||||
|
||||
if(pbuf)
|
||||
@ -372,7 +372,7 @@ int main(int argc, char**argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(BOOST_REGEX_USE_WIN32_LOCALE)
|
||||
#if defined(_WIN32) && defined(BOOST_REGEX_USE_WIN32_LOCALE) && !defined(UNDER_CE)
|
||||
#pragma comment(lib, "user32.lib")
|
||||
#endif
|
||||
|
||||
|
@ -51,7 +51,11 @@
|
||||
namespace boost{
|
||||
namespace re_detail{
|
||||
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
typedef WIN32_FIND_DATAA _fi_find_data;
|
||||
#else
|
||||
typedef WIN32_FIND_DATAW _fi_find_data;
|
||||
#endif
|
||||
typedef HANDLE _fi_find_handle;
|
||||
|
||||
} // namespace re_detail
|
||||
|
@ -354,7 +354,7 @@ void BuildFileList(std::list<std::string>* pl, const char* files, bool recurse)
|
||||
|
||||
while(dstart != dend)
|
||||
{
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
(::sprintf_s)(buf, sizeof(buf), "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
|
||||
#else
|
||||
(std::sprintf)(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
|
||||
|
@ -86,7 +86,14 @@ const char* _fi_sep_alt = _fi_sep;
|
||||
|
||||
void mapfile::open(const char* file)
|
||||
{
|
||||
#if defined(__CYGWIN__)||defined(__CYGWIN32__)
|
||||
#if defined(BOOST_NO_ANSI_APIS)
|
||||
int filename_size = strlen(file);
|
||||
LPWSTR wide_file = (LPWSTR)_alloca( (filename_size + 1) * sizeof(WCHAR) );
|
||||
if(::MultiByteToWideChar(CP_ACP, 0, file, filename_size, wide_file, filename_size + 1) == 0)
|
||||
hfile = INVALID_HANDLE_VALUE;
|
||||
else
|
||||
hfile = CreateFileW(wide_file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#elif defined(__CYGWIN__)||defined(__CYGWIN32__)
|
||||
char win32file[ MAX_PATH ];
|
||||
cygwin_conv_to_win32_path( file, win32file );
|
||||
hfile = CreateFileA(win32file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
@ -350,6 +357,48 @@ void mapfile::close()
|
||||
|
||||
#endif
|
||||
|
||||
inline _fi_find_handle find_first_file(const char* wild, _fi_find_data& data)
|
||||
{
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
std::size_t wild_size = std::strlen(wild);
|
||||
LPWSTR wide_wild = (LPWSTR)_alloca( (wild_size + 1) * sizeof(WCHAR) );
|
||||
if (::MultiByteToWideChar(CP_ACP, 0, wild, wild_size, wide_wild, wild_size + 1) == 0)
|
||||
return _fi_invalid_handle;
|
||||
|
||||
return FindFirstFileW(wide_wild, &data);
|
||||
#else
|
||||
return FindFirstFileA(wild, &data);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool find_next_file(_fi_find_handle hf, _fi_find_data& data)
|
||||
{
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
return FindNextFileW(hf, &data);
|
||||
#else
|
||||
return FindNextFileA(hf, &data);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void copy_find_file_result_with_overflow_check(const _fi_find_data& data, char* path, size_t max_size)
|
||||
{
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
if (::WideCharToMultiByte(CP_ACP, 0, data.cFileName, -1, path, max_size, NULL, NULL) == 0)
|
||||
re_detail::overflow_error_if_not_zero(1);
|
||||
#else
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(path, max_size, data.cFileName));
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool is_not_current_or_parent_path_string(const _fi_find_data& data)
|
||||
{
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
return (std::wcscmp(data.cFileName, L".") && std::wcscmp(data.cFileName, L".."));
|
||||
#else
|
||||
return (std::strcmp(data.cFileName, ".") && std::strcmp(data.cFileName, ".."));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
file_iterator::file_iterator()
|
||||
{
|
||||
@ -413,7 +462,7 @@ file_iterator::file_iterator(const char* wild)
|
||||
|
||||
ref = new file_iterator_ref();
|
||||
BOOST_REGEX_NOEH_ASSERT(ref)
|
||||
ref->hf = FindFirstFileA(wild, &(ref->_data));
|
||||
ref->hf = find_first_file(wild, ref->_data);
|
||||
ref->count = 1;
|
||||
|
||||
if(ref->hf == _fi_invalid_handle)
|
||||
@ -423,7 +472,7 @@ file_iterator::file_iterator(const char* wild)
|
||||
}
|
||||
else
|
||||
{
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, (MAX_PATH - (ptr - _path)), ref->_data.cFileName));
|
||||
copy_find_file_result_with_overflow_check(ref->_data, ptr, (MAX_PATH - (ptr - _path)));
|
||||
if(ref->_data.dwFileAttributes & _fi_dir)
|
||||
next();
|
||||
}
|
||||
@ -510,7 +559,7 @@ void file_iterator::next()
|
||||
bool cont = true;
|
||||
while(cont)
|
||||
{
|
||||
cont = FindNextFileA(ref->hf, &(ref->_data));
|
||||
cont = find_next_file(ref->hf, ref->_data);
|
||||
if(cont && ((ref->_data.dwFileAttributes & _fi_dir) == 0))
|
||||
break;
|
||||
}
|
||||
@ -523,7 +572,7 @@ void file_iterator::next()
|
||||
ptr = _path;
|
||||
}
|
||||
else
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, MAX_PATH - (ptr - _path), ref->_data.cFileName));
|
||||
copy_find_file_result_with_overflow_check(ref->_data, ptr, MAX_PATH - (ptr - _path));
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,7 +642,7 @@ directory_iterator::directory_iterator(const char* wild)
|
||||
ref = new file_iterator_ref();
|
||||
BOOST_REGEX_NOEH_ASSERT(ref)
|
||||
ref->count = 1;
|
||||
ref->hf = FindFirstFileA(wild, &(ref->_data));
|
||||
ref->hf = find_first_file(wild, ref->_data);
|
||||
if(ref->hf == _fi_invalid_handle)
|
||||
{
|
||||
*_path = 0;
|
||||
@ -601,8 +650,8 @@ directory_iterator::directory_iterator(const char* wild)
|
||||
}
|
||||
else
|
||||
{
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, MAX_PATH - (ptr - _path), ref->_data.cFileName));
|
||||
if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ref->_data.cFileName, ".") == 0) || (std::strcmp(ref->_data.cFileName, "..") == 0))
|
||||
copy_find_file_result_with_overflow_check(ref->_data, ptr, MAX_PATH - (ptr - _path));
|
||||
if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ptr, ".") == 0) || (std::strcmp(ptr, "..") == 0))
|
||||
next();
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
@ -686,10 +735,10 @@ void directory_iterator::next()
|
||||
bool cont = true;
|
||||
while(cont)
|
||||
{
|
||||
cont = FindNextFileA(ref->hf, &(ref->_data));
|
||||
cont = find_next_file(ref->hf, ref->_data);
|
||||
if(cont && (ref->_data.dwFileAttributes & _fi_dir))
|
||||
{
|
||||
if(std::strcmp(ref->_data.cFileName, ".") && std::strcmp(ref->_data.cFileName, ".."))
|
||||
if(is_not_current_or_parent_path_string(ref->_data))
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -702,7 +751,7 @@ void directory_iterator::next()
|
||||
ptr = _path;
|
||||
}
|
||||
else
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, MAX_PATH - (ptr - _path), ref->_data.cFileName));
|
||||
copy_find_file_result_with_overflow_check(ref->_data, ptr, MAX_PATH - (ptr - _path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA*
|
||||
{
|
||||
if(std::strcmp(e->re_endp, names[i]) == 0)
|
||||
{
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
(::sprintf_s)(localbuf, 5, "%d", i);
|
||||
#else
|
||||
(std::sprintf)(localbuf, "%d", i);
|
||||
@ -174,7 +174,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA*
|
||||
return std::strlen(localbuf) + 1;
|
||||
}
|
||||
}
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
(::sprintf_s)(localbuf, 5, "%d", 0);
|
||||
#else
|
||||
(std::sprintf)(localbuf, "%d", 0);
|
||||
|
@ -30,7 +30,7 @@
|
||||
#define NOGDI
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
|
||||
#if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
#pragma comment(lib, "user32.lib")
|
||||
#endif
|
||||
|
||||
@ -42,6 +42,18 @@ namespace std{
|
||||
|
||||
namespace boost{ namespace re_detail{
|
||||
|
||||
#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
|
||||
|
||||
|
||||
void w32_regex_traits_char_layer<char>::init()
|
||||
{
|
||||
// we need to start by initialising our syntax map so we know which
|
||||
@ -106,8 +118,24 @@ void w32_regex_traits_char_layer<char>::init()
|
||||
char char_map[1 << CHAR_BIT];
|
||||
for(int ii = 0; ii < (1 << CHAR_BIT); ++ii)
|
||||
char_map[ii] = static_cast<char>(ii);
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
int r = ::LCMapStringA(this->m_locale, LCMAP_LOWERCASE, char_map, 1 << CHAR_BIT, this->m_lower_map, 1 << CHAR_BIT);
|
||||
BOOST_ASSERT(r != 0);
|
||||
#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
|
||||
if(r < (1 << CHAR_BIT))
|
||||
{
|
||||
// if we have multibyte characters then not all may have been given
|
||||
@ -115,7 +143,12 @@ void w32_regex_traits_char_layer<char>::init()
|
||||
for(int jj = r; jj < (1 << CHAR_BIT); ++jj)
|
||||
this->m_lower_map[jj] = static_cast<char>(jj);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
r = ::GetStringTypeExA(this->m_locale, CT_CTYPE1, char_map, 1 << CHAR_BIT, this->m_type_map);
|
||||
#else
|
||||
r = ::GetStringTypeExW(this->m_locale, CT_CTYPE1, wide_char_map, 1 << CHAR_BIT, this->m_type_map);
|
||||
#endif
|
||||
BOOST_ASSERT(0 != r);
|
||||
}
|
||||
|
||||
@ -126,18 +159,48 @@ BOOST_REGEX_DECL lcid_type BOOST_REGEX_CALL w32_get_default_locale()
|
||||
|
||||
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(char c, lcid_type id)
|
||||
{
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
WORD mask;
|
||||
if(::GetStringTypeExA(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER))
|
||||
return true;
|
||||
return false;
|
||||
#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
|
||||
}
|
||||
|
||||
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(wchar_t c, lcid_type id)
|
||||
{
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
WORD mask;
|
||||
if(::GetStringTypeExW(id, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER))
|
||||
return true;
|
||||
return false;
|
||||
#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
|
||||
}
|
||||
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
||||
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(unsigned short ca, lcid_type id)
|
||||
@ -183,12 +246,21 @@ void free_module(void* mod)
|
||||
|
||||
BOOST_REGEX_DECL cat_type BOOST_REGEX_CALL w32_cat_open(const std::string& name)
|
||||
{
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
cat_type result(::LoadLibraryA(name.c_str()), &free_module);
|
||||
return result;
|
||||
#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);
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::string& def)
|
||||
{
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
char buf[256];
|
||||
if(0 == ::LoadStringA(
|
||||
static_cast<HMODULE>(cat.get()),
|
||||
@ -199,6 +271,21 @@ BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, l
|
||||
{
|
||||
return def;
|
||||
}
|
||||
#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
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
@ -236,6 +323,7 @@ BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_cat_get(
|
||||
#endif
|
||||
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type id, const char* p1, const char* p2)
|
||||
{
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
int bytes = ::LCMapStringA(
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
@ -255,6 +343,36 @@ BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type id, const
|
||||
&*result.begin(), // destination buffer
|
||||
bytes // size of destination buffer
|
||||
);
|
||||
#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
|
||||
if(bytes > static_cast<int>(result.size()))
|
||||
return std::string(p1, p2);
|
||||
while(result.size() && result[result.size()-1] == '\0')
|
||||
@ -335,6 +453,7 @@ BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_transfor
|
||||
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type id)
|
||||
{
|
||||
char result[2];
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
int b = ::LCMapStringA(
|
||||
id, // locale identifier
|
||||
LCMAP_LOWERCASE, // mapping transformation type
|
||||
@ -344,6 +463,29 @@ BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type id)
|
||||
1); // size of destination buffer
|
||||
if(b == 0)
|
||||
return c;
|
||||
#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
|
||||
return result[0];
|
||||
}
|
||||
|
||||
@ -382,6 +524,7 @@ BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_tolower(unsigned short c, l
|
||||
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type id)
|
||||
{
|
||||
char result[2];
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
int b = ::LCMapStringA(
|
||||
id, // locale identifier
|
||||
LCMAP_UPPERCASE, // mapping transformation type
|
||||
@ -391,6 +534,29 @@ BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type id)
|
||||
1); // size of destination buffer
|
||||
if(b == 0)
|
||||
return c;
|
||||
#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
|
||||
return result[0];
|
||||
}
|
||||
|
||||
@ -429,8 +595,21 @@ BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_toupper(unsigned short c, l
|
||||
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type id, boost::uint32_t m, char c)
|
||||
{
|
||||
WORD mask;
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
if(::GetStringTypeExA(id, CT_CTYPE1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation<char>::mask_base))
|
||||
return true;
|
||||
#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
|
||||
if((m & w32_regex_traits_implementation<char>::mask_word) && (c == '_'))
|
||||
return true;
|
||||
return false;
|
||||
|
@ -157,7 +157,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
|
||||
{
|
||||
result = std::wcslen(wnames[code]) + 1;
|
||||
if(buf_size >= result)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
::wcscpy_s(buf, buf_size, wnames[code]);
|
||||
#else
|
||||
std::wcscpy(buf, wnames[code]);
|
||||
@ -176,13 +176,13 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
|
||||
{
|
||||
if(std::wcscmp(e->re_endp, wnames[i]) == 0)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
#if defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
(std::swprintf)(localbuf, L"%d", i);
|
||||
#else
|
||||
(std::swprintf)(localbuf, 5, L"%d", i);
|
||||
#endif
|
||||
if(std::wcslen(localbuf) < buf_size)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
::wcscpy_s(buf, buf_size, localbuf);
|
||||
#else
|
||||
std::wcscpy(buf, localbuf);
|
||||
@ -190,13 +190,13 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
|
||||
return std::wcslen(localbuf) + 1;
|
||||
}
|
||||
}
|
||||
#if defined(_WIN32_WCE)
|
||||
#if defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
(std::swprintf)(localbuf, L"%d", 0);
|
||||
#else
|
||||
(std::swprintf)(localbuf, 5, L"%d", 0);
|
||||
#endif
|
||||
if(std::wcslen(localbuf) < buf_size)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
|
||||
::wcscpy_s(buf, buf_size, localbuf);
|
||||
#else
|
||||
std::wcscpy(buf, localbuf);
|
||||
|
@ -32,30 +32,30 @@ int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB |
|
||||
|
||||
int main()
|
||||
{
|
||||
regex_t re;
|
||||
regex_tA re;
|
||||
int result;
|
||||
result = regcomp(&re, expression, REG_AWK);
|
||||
result = regcompA(&re, expression, REG_AWK);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
regerrorA(result, &re, buf, sizeof(buf));
|
||||
printf(buf);
|
||||
return result;
|
||||
}
|
||||
assert(re.re_nsub == 0);
|
||||
matches[0].rm_so = 0;
|
||||
matches[0].rm_eo = strlen(text);
|
||||
result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
|
||||
result = regexecA(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
regerrorA(result, &re, buf, sizeof(buf));
|
||||
printf(buf);
|
||||
regfree(&re);
|
||||
regfreeA(&re);
|
||||
return result;
|
||||
}
|
||||
assert(matches[0].rm_so == matches[0].rm_eo == 1);
|
||||
regfree(&re);
|
||||
regfreeA(&re);
|
||||
printf("no errors found\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,30 +33,30 @@ int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB |
|
||||
|
||||
int main()
|
||||
{
|
||||
regex_t re;
|
||||
regex_tA re;
|
||||
int result;
|
||||
result = regcomp(&re, expression, REG_AWK);
|
||||
result = regcompA(&re, expression, REG_AWK);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
regerrorA(result, &re, buf, sizeof(buf));
|
||||
printf(buf);
|
||||
return result;
|
||||
}
|
||||
BOOST_TEST(re.re_nsub == 0);
|
||||
matches[0].rm_so = 0;
|
||||
matches[0].rm_eo = strlen(text);
|
||||
result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
|
||||
result = regexecA(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
regerrorA(result, &re, buf, sizeof(buf));
|
||||
printf(buf);
|
||||
regfree(&re);
|
||||
regfreeA(&re);
|
||||
return result;
|
||||
}
|
||||
BOOST_TEST(matches[0].rm_so == matches[0].rm_eo == 1);
|
||||
regfree(&re);
|
||||
regfreeA(&re);
|
||||
printf("no errors found\n");
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ namespace std{ using ::setlocale; }
|
||||
|
||||
test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
|
||||
{
|
||||
#ifndef UNDER_CE
|
||||
// store the name:
|
||||
m_old_name = m_name;
|
||||
m_name = c_name;
|
||||
@ -43,6 +44,9 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
|
||||
s_c_locale = no_test;
|
||||
std::cout << "The global C locale: " << c_name << " is not available and will not be tested." << std::endl;
|
||||
}
|
||||
#else
|
||||
s_c_locale = no_test;
|
||||
#endif
|
||||
#ifndef BOOST_NO_STD_LOCALE
|
||||
// back up the C++ locale and create the new one:
|
||||
m_old_cpp_locale = s_cpp_locale_inst;
|
||||
@ -69,6 +73,7 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
|
||||
// Start by geting the printable name of the locale.
|
||||
// We use this for debugging purposes only:
|
||||
//
|
||||
#ifndef BOOST_NO_ANSI_APIS
|
||||
boost::scoped_array<char> p;
|
||||
int r = ::GetLocaleInfoA(
|
||||
lcid, // locale identifier
|
||||
@ -83,6 +88,43 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
|
||||
p.get(), // information buffer
|
||||
r+1 // size of buffer
|
||||
);
|
||||
#else
|
||||
WCHAR code_page_string[7];
|
||||
int r = ::GetLocaleInfoW(
|
||||
lcid,
|
||||
LOCALE_IDEFAULTANSICODEPAGE,
|
||||
code_page_string,
|
||||
7);
|
||||
BOOST_ASSERT(r != 0);
|
||||
|
||||
UINT code_page = static_cast<UINT>(_wtol(code_page_string));
|
||||
|
||||
boost::scoped_array<wchar_t> wp;
|
||||
r = ::GetLocaleInfoW(
|
||||
lcid, // locale identifier
|
||||
LOCALE_SCOUNTRY, // information type
|
||||
0, // information buffer
|
||||
0 // size of buffer
|
||||
);
|
||||
wp.reset(new wchar_t[r+1]);
|
||||
r = ::GetLocaleInfoW(
|
||||
lcid, // locale identifier
|
||||
LOCALE_SCOUNTRY, // information type
|
||||
wp.get(), // information buffer
|
||||
r+1 // size of buffer
|
||||
);
|
||||
|
||||
int name_size = (r+1) * 2;
|
||||
boost::scoped_array<char> p(new char[name_size]);
|
||||
int conv_r = ::WideCharToMultiByte(
|
||||
code_page,
|
||||
0,
|
||||
wp.get(), r,
|
||||
p.get(), name_size,
|
||||
NULL, NULL
|
||||
);
|
||||
BOOST_ASSERT(conv_r != 0);
|
||||
#endif
|
||||
//
|
||||
// now see if locale is installed and behave accordingly:
|
||||
//
|
||||
@ -104,8 +146,10 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
|
||||
test_locale::~test_locale()
|
||||
{
|
||||
// restore to previous state:
|
||||
#ifndef UNDER_CE
|
||||
std::setlocale(LC_ALL, m_old_c_locale.c_str());
|
||||
s_c_locale = m_old_c_state;
|
||||
#endif
|
||||
#ifndef BOOST_NO_STD_LOCALE
|
||||
s_cpp_locale_inst = m_old_cpp_locale;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user