1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Enable wstring support in poco data.

This commit is contained in:
Sandu Liviu Catalin 2021-02-12 14:21:50 +02:00
parent a526cc7597
commit df61b4eb55
2 changed files with 75 additions and 0 deletions

View File

@ -1654,6 +1654,7 @@ protected:
case Poco::Data::MetaColumn::FDT_STRING:
return LightObj(SqInPlace{}, SqVM(), v.convert< std::string >());
case Poco::Data::MetaColumn::FDT_WSTRING:
return LightObj(SqInPlace{}, SqVM(), v.convert< std::wstring >());
case Poco::Data::MetaColumn::FDT_BLOB:
case Poco::Data::MetaColumn::FDT_CLOB:
case Poco::Data::MetaColumn::FDT_DATE:

View File

@ -792,6 +792,80 @@ struct Var<const string&> {
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push wide strings to and from the stack (wide string is usually std::wstring)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<std::wstring> {
std::wstring value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a wide string
///
/// \param vm Target VM
/// \param idx Index trying to be read
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret;
SQInteger len;
sq_tostring(vm, idx);
sq_getstringandsize(vm, -1, &ret, &len);
value.assign(ret, ret + static_cast< size_t >(len));
sq_pop(vm,1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put a wide string on the stack
///
/// \param vm Target VM
/// \param value Value to push on to the VM's stack
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const std::wstring& value) {
std::string s(value.begin(), value.end());
sq_pushstring(vm, s.c_str(), s.size());
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push const wide string references to and from the stack as copies (wide strings are always copied)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<const std::wstring&> {
std::wstring value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a wide string
///
/// \param vm Target VM
/// \param idx Index trying to be read
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret;
SQInteger len;
sq_tostring(vm, idx);
sq_getstringandsize(vm, -1, &ret, &len);
value.assign(ret, ret + static_cast< size_t >(len));
sq_pop(vm,1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put a wide string on the stack
///
/// \param vm Target VM
/// \param value Value to push on to the VM's stack
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const std::wstring& value) {
std::string s(value.begin(), value.end());
sq_pushstring(vm, s.c_str(), s.size());
}
};
#ifdef SQUNICODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push std::string to and from the stack when SQChar is not char (must define SQUNICODE)