mirror of
https://github.com/boostorg/nowide.git
synced 2026-02-22 03:22:32 +00:00
Disallow converting locales
No conversion is done in current implementation so avoid unexpected behavior
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <boost/nowide/stackstring.hpp>
|
||||
#include <cstdio>
|
||||
#include <iosfwd>
|
||||
#include <stdexcept>
|
||||
#include <streambuf>
|
||||
#else
|
||||
#include <fstream>
|
||||
@@ -83,6 +84,7 @@ namespace nowide {
|
||||
{
|
||||
if(is_open())
|
||||
return NULL;
|
||||
validate_cvt(this->getloc());
|
||||
bool ate = bool(mode & std::ios_base::ate);
|
||||
if(ate)
|
||||
mode = mode ^ std::ios_base::ate;
|
||||
@@ -138,6 +140,11 @@ namespace nowide {
|
||||
own_ = true;
|
||||
}
|
||||
}
|
||||
void validate_cvt(const std::locale &loc)
|
||||
{
|
||||
if(!std::use_facet<std::codecvt<char, char, std::mbstate_t> >(loc).always_noconv())
|
||||
throw std::runtime_error("Converting codecvts are not supported");
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual std::streambuf *setbuf(char *s, std::streamsize n)
|
||||
@@ -243,6 +250,10 @@ namespace nowide {
|
||||
{
|
||||
return seekoff(std::streamoff(off), std::ios_base::beg, m);
|
||||
}
|
||||
virtual void imbue(const std::locale &loc)
|
||||
{
|
||||
validate_cvt(loc);
|
||||
}
|
||||
|
||||
private:
|
||||
int fixg()
|
||||
|
||||
Reference in New Issue
Block a user