mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
Surround date in toString with quotes. Fix #1062
This commit is contained in:
parent
cf02d38986
commit
0f7729cbb5
@ -27,6 +27,7 @@
|
|||||||
#include "Poco/Nullable.h"
|
#include "Poco/Nullable.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
#include "Poco/DateTimeFormatter.h"
|
#include "Poco/DateTimeFormatter.h"
|
||||||
|
#include "Poco/UTF8String.h"
|
||||||
#include "Poco/MongoDB/MongoDB.h"
|
#include "Poco/MongoDB/MongoDB.h"
|
||||||
#include "Poco/MongoDB/BSONReader.h"
|
#include "Poco/MongoDB/BSONReader.h"
|
||||||
#include "Poco/MongoDB/BSONWriter.h"
|
#include "Poco/MongoDB/BSONWriter.h"
|
||||||
@ -79,7 +80,7 @@ inline std::string Element::name() const
|
|||||||
typedef std::list<Element::Ptr> ElementSet;
|
typedef std::list<Element::Ptr> ElementSet;
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ElementTraits
|
struct ElementTraits
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
@ -109,51 +110,11 @@ struct ElementTraits<std::string>
|
|||||||
|
|
||||||
static std::string toString(const std::string& value, int indent = 0)
|
static std::string toString(const std::string& value, int indent = 0)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::string result;
|
||||||
|
result.append(1, '"');
|
||||||
oss << '"';
|
result.append(UTF8::escape(value));
|
||||||
|
result.append(1, '"');
|
||||||
for(std::string::const_iterator it = value.begin(); it != value.end(); ++it)
|
return result;
|
||||||
{
|
|
||||||
switch (*it)
|
|
||||||
{
|
|
||||||
case '"':
|
|
||||||
oss << "\\\"";
|
|
||||||
break;
|
|
||||||
case '\\':
|
|
||||||
oss << "\\\\";
|
|
||||||
break;
|
|
||||||
case '\b':
|
|
||||||
oss << "\\b";
|
|
||||||
break;
|
|
||||||
case '\f':
|
|
||||||
oss << "\\f";
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
oss << "\\n";
|
|
||||||
break;
|
|
||||||
case '\r':
|
|
||||||
oss << "\\r";
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
oss << "\\t";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if ( *it > 0 && *it <= 0x1F )
|
|
||||||
{
|
|
||||||
oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*it);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
oss << *it;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
oss << '"';
|
|
||||||
return oss.str();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -231,7 +192,11 @@ struct ElementTraits<Timestamp>
|
|||||||
|
|
||||||
static std::string toString(const Timestamp& value, int indent = 0)
|
static std::string toString(const Timestamp& value, int indent = 0)
|
||||||
{
|
{
|
||||||
return DateTimeFormatter::format(value, "%Y-%m-%dT%H:%M:%s%z");
|
std::string result;
|
||||||
|
result.append(1, '"');
|
||||||
|
result.append(DateTimeFormatter::format(value, "%Y-%m-%dT%H:%M:%s%z"));
|
||||||
|
result.append(1, '"');
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -308,7 +273,7 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
T value() const
|
T value() const
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
@ -320,7 +285,7 @@ public:
|
|||||||
return ElementTraits<T>::toString(_value, indent);
|
return ElementTraits<T>::toString(_value, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int type() const
|
int type() const
|
||||||
{
|
{
|
||||||
return ElementTraits<T>::TypeId;
|
return ElementTraits<T>::TypeId;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user