2016-02-27 10:57:10 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Text.hpp"
|
|
|
|
#include "Node.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-04-02 10:04:28 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
2016-02-27 10:57:10 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-28 16:39:26 +01:00
|
|
|
SQInteger Text::Typename(HSQUIRRELVM vm)
|
2016-02-27 10:57:10 +01:00
|
|
|
{
|
2016-05-22 21:34:27 +02:00
|
|
|
static const SQChar name[] = _SC("SqXmlText");
|
2016-02-28 16:39:26 +01:00
|
|
|
sq_pushstring(vm, name, sizeof(name));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-27 10:57:10 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 Text::Cmp(const Text & o)
|
|
|
|
{
|
|
|
|
if (strcmp(m_Text.get(), o.m_Text.get()) == 0)
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-02-27 10:57:10 +01:00
|
|
|
return 0;
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
else if (strlen(m_Text.get()) > strlen(o.m_Text.get()))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-02-27 10:57:10 +01:00
|
|
|
return 1;
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
else
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-02-27 10:57:10 +01:00
|
|
|
return -1;
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::AsLong(Object & def) const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object >::push(DefaultVM::Get(), def);
|
2016-02-27 10:57:10 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
SqMod_PushSLongObject(DefaultVM::Get(), m_Text.as_llong(longint));
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
2016-07-17 02:24:07 +02:00
|
|
|
return Var< Object >(DefaultVM::Get(), -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::AsUlong(Object & def) const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object >::push(DefaultVM::Get(), def);
|
2016-02-27 10:57:10 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
SqMod_PushULongObject(DefaultVM::Get(), m_Text.as_ullong(longint));
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
2016-07-17 02:24:07 +02:00
|
|
|
return Var< Object >(DefaultVM::Get(), -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Text::ApplyLong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object & >::push(DefaultVM::Get(), value);
|
2016-02-27 10:57:10 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-28 16:39:26 +01:00
|
|
|
// Assign the obtained value and return the result
|
|
|
|
return m_Text.set(longint);
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Text::ApplyUlong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object & >::push(DefaultVM::Get(), value);
|
2016-02-27 10:57:10 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-28 16:39:26 +01:00
|
|
|
// Assign the obtained value and return the result
|
|
|
|
return m_Text.set(longint);
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::GetLong() const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
SqMod_PushSLongObject(DefaultVM::Get(), m_Text.as_llong());
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
2016-07-17 02:24:07 +02:00
|
|
|
return Var< Object >(DefaultVM::Get(), -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Text::SetLong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object & >::push(DefaultVM::Get(), value);
|
2016-02-27 10:57:10 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Assign the obtained value
|
2016-02-28 16:39:26 +01:00
|
|
|
m_Text = longint;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::GetUlong() const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
SqMod_PushULongObject(DefaultVM::Get(), m_Text.as_ullong());
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
2016-07-17 02:24:07 +02:00
|
|
|
return Var< Object >(DefaultVM::Get(), -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Text::SetUlong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object & >::push(DefaultVM::Get(), value);
|
2016-02-27 10:57:10 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Assign the obtained value
|
2016-02-28 16:39:26 +01:00
|
|
|
m_Text = longint;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Node Text::GetData() const
|
|
|
|
{
|
|
|
|
return Node(m_Doc, m_Text.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|