mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Compare commits
4 Commits
62b9504d43
...
f192767853
Author | SHA1 | Date | |
---|---|---|---|
|
f192767853 | ||
|
a58b9fe267 | ||
|
4a8a7172d4 | ||
|
cae745378d |
@ -85,6 +85,7 @@ add_library(SqModule MODULE SqBase.hpp Main.cpp
|
||||
Library/System/Dir.cpp Library/System/Dir.hpp
|
||||
Library/System/Env.cpp Library/System/Env.hpp
|
||||
Library/System/Path.cpp Library/System/Path.hpp
|
||||
Library/UTF8.cpp Library/UTF8.hpp
|
||||
Library/Utils.cpp Library/Utils.hpp
|
||||
Library/Utils/Announce.cpp Library/Utils/Announce.hpp
|
||||
Library/Utils/String.cpp Library/Utils/String.hpp
|
||||
@ -131,7 +132,7 @@ if(WIN32 OR MINGW)
|
||||
target_link_libraries(SqModule wsock32 ws2_32 shlwapi)
|
||||
endif()
|
||||
# Link to base libraries
|
||||
target_link_libraries(SqModule Squirrel fmt::fmt SimpleINI TinyDir xxHash ConcurrentQueue SAJSON CPR PUGIXML CivetWeb maxminddb libzmq-static)
|
||||
target_link_libraries(SqModule Squirrel fmt::fmt SimpleINI TinyDir xxHash ConcurrentQueue SAJSON CPR UTF8Lib PUGIXML CivetWeb maxminddb libzmq-static)
|
||||
# Enable built-in Discord support
|
||||
if(ENABLE_DISCORD)
|
||||
target_link_libraries(SqModule DPP)
|
||||
|
@ -79,6 +79,10 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.FmtFunc(_SC("SetDisabled"), &DpComponent::SetDisabled)
|
||||
.FmtFunc(_SC("SetAnimated"), &DpComponent::SetAnimated)
|
||||
.FmtFunc(_SC("SetEmojiName"), &DpComponent::ApplyEmojiName)
|
||||
.FmtFunc(_SC("GetComponents"), &DpComponent::GetComponents)
|
||||
.FmtFunc(_SC("GetOptions"), &DpComponent::GetOptions)
|
||||
.FmtFunc(_SC("AddComponent"), &DpComponent::AddComponent)
|
||||
.FmtFunc(_SC("AddOption"), &DpComponent::AddSelectOption)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_DPP_VectorProxy< dpp::component, DpComponent, SqDppComponent >(vm, ns, _SC("Components"));
|
||||
@ -89,6 +93,13 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedFooter::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedFooter::IsValid)
|
||||
.Prop(_SC("Text"), &DpEmbedFooter::GetText, &DpEmbedFooter::SetText)
|
||||
.Prop(_SC("Icon"), &DpEmbedFooter::GetIconURL, &DpEmbedFooter::SetIconURL)
|
||||
.Prop(_SC("Proxy"), &DpEmbedFooter::GetProxyURL, &DpEmbedFooter::SetProxyURL)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetText"), &DpEmbedFooter::ApplyText)
|
||||
.FmtFunc(_SC("SetIcon"), &DpEmbedFooter::ApplyIconURL)
|
||||
.FmtFunc(_SC("SetProxy"), &DpEmbedFooter::ApplyProxyURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedImage"),
|
||||
@ -97,6 +108,15 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedImage::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedImage::IsValid)
|
||||
.Prop(_SC("URL"), &DpEmbedImage::GetURL, &DpEmbedImage::SetURL)
|
||||
.Prop(_SC("Proxy"), &DpEmbedImage::GetProxyURL, &DpEmbedImage::SetProxyURL)
|
||||
.Prop(_SC("Height"), &DpEmbedImage::GetHeight, &DpEmbedImage::SetHeight)
|
||||
.Prop(_SC("Width"), &DpEmbedImage::GetWidth, &DpEmbedImage::SetWidth)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbedImage::ApplyURL)
|
||||
.FmtFunc(_SC("SetProxy"), &DpEmbedImage::ApplyProxyURL)
|
||||
.FmtFunc(_SC("SetHeight"), &DpEmbedImage::ApplyHeight)
|
||||
.FmtFunc(_SC("SetWidth"), &DpEmbedImage::ApplyWidth)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedProvider"),
|
||||
@ -105,6 +125,11 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedProvider::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedProvider::IsValid)
|
||||
.Prop(_SC("Name"), &DpEmbedProvider::GetName, &DpEmbedProvider::SetName)
|
||||
.Prop(_SC("URL"), &DpEmbedProvider::GetURL, &DpEmbedProvider::SetURL)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetName"), &DpEmbedProvider::ApplyName)
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbedProvider::ApplyURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedAuthor"),
|
||||
@ -113,6 +138,15 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedAuthor::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedAuthor::IsValid)
|
||||
.Prop(_SC("Name"), &DpEmbedAuthor::GetName, &DpEmbedAuthor::SetName)
|
||||
.Prop(_SC("URL"), &DpEmbedAuthor::GetURL, &DpEmbedAuthor::SetURL)
|
||||
.Prop(_SC("Icon"), &DpEmbedAuthor::GetIconURL, &DpEmbedAuthor::SetIconURL)
|
||||
.Prop(_SC("ProxyIcon"), &DpEmbedAuthor::GetProxyIconURL, &DpEmbedAuthor::SetProxyIconURL)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetName"), &DpEmbedAuthor::ApplyName)
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbedAuthor::ApplyURL)
|
||||
.FmtFunc(_SC("SetIcon"), &DpEmbedAuthor::ApplyIconURL)
|
||||
.FmtFunc(_SC("SetProxyIcon"), &DpEmbedAuthor::ApplyProxyIconURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedField"),
|
||||
@ -121,6 +155,13 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedField::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedField::IsValid)
|
||||
.Prop(_SC("Name"), &DpEmbedField::GetName, &DpEmbedField::SetName)
|
||||
.Prop(_SC("Value"), &DpEmbedField::GetValue, &DpEmbedField::SetValue)
|
||||
.Prop(_SC("Inline"), &DpEmbedField::IsInline, &DpEmbedField::SetInline)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetName"), &DpEmbedField::ApplyName)
|
||||
.FmtFunc(_SC("SetValue"), &DpEmbedField::ApplyValue)
|
||||
.FmtFunc(_SC("SetInline"), &DpEmbedField::SetInline)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Embed"),
|
||||
|
@ -471,6 +471,41 @@ struct DpComponent
|
||||
// Return the associated script object
|
||||
return mSqOptions;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Add a sub-component, only valid for action rows.
|
||||
* Adding subcomponents to a component will automatically set this component's type to SqDiscordComponentType.ActionRow.
|
||||
*/
|
||||
DpComponent & AddComponent(DpComponent & comp)
|
||||
{
|
||||
Valid().add_component(comp.Valid());
|
||||
// Do we have to sync a script wrapper?
|
||||
if (!mSqComponents.IsNull())
|
||||
{
|
||||
mSqComponents.CastI< Components >()->mVec.emplace_back();
|
||||
}
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Add a select-option. Limited to 25 options.
|
||||
*/
|
||||
DpComponent & AddSelectOption(DpSelectOption & opt)
|
||||
{
|
||||
// Make sure we are within bounds
|
||||
if (Valid().options.size() >= 25)
|
||||
{
|
||||
STHROWF("Maximum of 25 select options was reached");
|
||||
}
|
||||
// Perform the request
|
||||
mPtr->add_select_option(opt.Valid());
|
||||
// Do we have to sync a script wrapper?
|
||||
if (!mSqOptions.IsNull())
|
||||
{
|
||||
mSqOptions.CastI< Options >()->mVec.emplace_back();
|
||||
}
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -561,7 +596,42 @@ struct DpEmbedFooter
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated footer's text.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetText() const { return Valid().text; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated footer's text.
|
||||
*/
|
||||
void SetText(StackStrF & text) const { Valid().set_text(text.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated footer's text.
|
||||
*/
|
||||
DpEmbedFooter & ApplyText(StackStrF & text) { SetText(text); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated footer's icon url.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetIconURL() const { return Valid().icon_url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated footer's icon url.
|
||||
*/
|
||||
void SetIconURL(StackStrF & icon_url) const { Valid().set_icon(icon_url.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated footer's icon url.
|
||||
*/
|
||||
DpEmbedFooter & ApplyIconURL(StackStrF & icon_url) { SetIconURL(icon_url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated footer's proxied icon url.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetProxyURL() const { return Valid().proxy_url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated footer's proxied icon url.
|
||||
*/
|
||||
void SetProxyURL(StackStrF & proxy_url) const { Valid().set_proxy(proxy_url.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated footer's proxied icon url.
|
||||
*/
|
||||
DpEmbedFooter & ApplyProxyURL(StackStrF & proxy_url) { SetProxyURL(proxy_url); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -652,7 +722,94 @@ struct DpEmbedImage
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated URL to image or video.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetURL() const { return Valid().url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated URL to image or video.
|
||||
*/
|
||||
void SetURL(StackStrF & url) const
|
||||
{
|
||||
if (url.mLen > 0)
|
||||
{
|
||||
Valid().url.assign(url.mPtr, static_cast< size_t >(url.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().url.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated URL to image or video.
|
||||
*/
|
||||
DpEmbedImage & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated proxied image url.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetProxyURL() const { return Valid().proxy_url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated proxied image url.
|
||||
*/
|
||||
void SetProxyURL(StackStrF & proxy_url) const
|
||||
{
|
||||
if (proxy_url.mLen > 0)
|
||||
{
|
||||
Valid().proxy_url.assign(proxy_url.mPtr, static_cast< size_t >(proxy_url.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().proxy_url.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated proxied image url.
|
||||
*/
|
||||
DpEmbedImage & ApplyProxyURL(StackStrF & proxy_url) { SetProxyURL(proxy_url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated height (calculated by discord).
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetHeight() const { return Valid().height; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated height (calculated by discord).
|
||||
*/
|
||||
void SetHeight(StackStrF & height) const
|
||||
{
|
||||
if (height.mLen > 0)
|
||||
{
|
||||
Valid().height.assign(height.mPtr, static_cast< size_t >(height.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().height.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated height (calculated by discord).
|
||||
*/
|
||||
DpEmbedImage & ApplyHeight(StackStrF & height) { SetHeight(height); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated width (calculated by discord).
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetWidth() const { return Valid().width; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated width (calculated by discord).
|
||||
*/
|
||||
void SetWidth(StackStrF & width) const
|
||||
{
|
||||
if (width.mLen > 0)
|
||||
{
|
||||
Valid().width.assign(width.mPtr, static_cast< size_t >(width.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().width.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated width (calculated by discord).
|
||||
*/
|
||||
DpEmbedImage & ApplyWidth(StackStrF & width) { SetWidth(width); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -743,7 +900,50 @@ struct DpEmbedProvider
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated provider name.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated provider name.
|
||||
*/
|
||||
void SetName(StackStrF & name) const
|
||||
{
|
||||
if (name.mLen > 0)
|
||||
{
|
||||
Valid().name.assign(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().name.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated provider name.
|
||||
*/
|
||||
DpEmbedProvider & ApplyName(StackStrF & name) { SetName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated provider URL.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetURL() const { return Valid().url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated provider URL.
|
||||
*/
|
||||
void SetURL(StackStrF & url) const
|
||||
{
|
||||
if (url.mLen > 0)
|
||||
{
|
||||
Valid().url.assign(url.mPtr, static_cast< size_t >(url.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().url.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated provider URL.
|
||||
*/
|
||||
DpEmbedProvider & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -834,7 +1034,94 @@ struct DpEmbedAuthor
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated author name.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated author name.
|
||||
*/
|
||||
void SetName(StackStrF & name) const
|
||||
{
|
||||
if (name.mLen > 0)
|
||||
{
|
||||
Valid().name.assign(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().name.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated author name.
|
||||
*/
|
||||
DpEmbedAuthor & ApplyName(StackStrF & name) { SetName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated author URL.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetURL() const { return Valid().url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated author URL.
|
||||
*/
|
||||
void SetURL(StackStrF & url) const
|
||||
{
|
||||
if (url.mLen > 0)
|
||||
{
|
||||
Valid().url.assign(url.mPtr, static_cast< size_t >(url.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().url.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated author URL.
|
||||
*/
|
||||
DpEmbedAuthor & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated author icon URL.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetIconURL() const { return Valid().icon_url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated author icon URL.
|
||||
*/
|
||||
void SetIconURL(StackStrF & icon_url) const
|
||||
{
|
||||
if (icon_url.mLen > 0)
|
||||
{
|
||||
Valid().icon_url.assign(icon_url.mPtr, static_cast< size_t >(icon_url.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().icon_url.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated author icon URL.
|
||||
*/
|
||||
DpEmbedAuthor & ApplyIconURL(StackStrF & icon_url) { SetIconURL(icon_url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated proxied icon URL.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetProxyIconURL() const { return Valid().proxy_icon_url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated proxied icon URL.
|
||||
*/
|
||||
void SetProxyIconURL(StackStrF & proxy_icon_url) const
|
||||
{
|
||||
if (proxy_icon_url.mLen > 0)
|
||||
{
|
||||
Valid().proxy_icon_url.assign(proxy_icon_url.mPtr, static_cast< size_t >(proxy_icon_url.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().proxy_icon_url.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated proxied icon URL.
|
||||
*/
|
||||
DpEmbedAuthor & ApplyProxyIconURL(StackStrF & proxy_icon_url) { SetProxyIconURL(proxy_icon_url); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -925,7 +1212,66 @@ struct DpEmbedField
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated field name.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated field name.
|
||||
*/
|
||||
void SetName(StackStrF & name) const
|
||||
{
|
||||
if (name.mLen > 0)
|
||||
{
|
||||
Valid().name.assign(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().name.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated field name.
|
||||
*/
|
||||
DpEmbedField & ApplyName(StackStrF & name) { SetName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated field value (max length 1000).
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetValue() const { return Valid().value; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated field value (max length 1000).
|
||||
*/
|
||||
void SetValue(StackStrF & value) const
|
||||
{
|
||||
if (value.mLen > 0)
|
||||
{
|
||||
auto str = value.ToStr();
|
||||
auto len = dpp::utility::utf8len(str);
|
||||
// Make sure we are within bounds
|
||||
if (len > 1000)
|
||||
{
|
||||
STHROWF("Field value exceeds the 1000 character limit");
|
||||
}
|
||||
// Assign the specified string
|
||||
Valid().value = std::move(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().value.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated field value (max length 1000).
|
||||
*/
|
||||
DpEmbedField & ApplyValue(StackStrF & value) { SetValue(value); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the field is to be displayed inline.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsInline() const { return Valid().is_inline; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify whether the field is to be displayed inline.
|
||||
*/
|
||||
DpEmbedField & SetInline(bool toggle) { Valid().is_inline = toggle; return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
|
@ -169,7 +169,21 @@ template < class T, class W > struct DpVectorProxy
|
||||
// Return the object from the cache
|
||||
return mVec[static_cast< size_t >(i)].first;
|
||||
}
|
||||
SQMOD_NODISCARD LightObj & Get(SQInteger i) { ValidIdx_(i); return Get_(i); }
|
||||
SQMOD_NODISCARD LightObj & Get(SQInteger i)
|
||||
{
|
||||
// Was the referenced vector modified?
|
||||
if (mVec.size() < Valid().size())
|
||||
{
|
||||
// Synchronize the size
|
||||
mVec.resize(mPtr->size());
|
||||
// Synchronize the cache
|
||||
CacheSync();
|
||||
}
|
||||
// Validate index
|
||||
ValidIdx_(i);
|
||||
// Perform the request
|
||||
return Get_(i);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify a value from the container.
|
||||
*/
|
||||
|
135
module/Library/UTF8.cpp
Normal file
135
module/Library/UTF8.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/UTF8.hpp"
|
||||
#include "Core/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger SqStrLenUTF8(StackStrF & str)
|
||||
{
|
||||
// Is the string empty or invalid?
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return str.mLen; // Return same value
|
||||
}
|
||||
// Perform the request and return the result
|
||||
return static_cast< SQInteger >(utf8len(str.mPtr));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger SqStrNLenUTF8(SQInteger len, StackStrF & str)
|
||||
{
|
||||
// Is the string empty or invalid?
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return str.mLen; // Return same value
|
||||
}
|
||||
// Is the specified length within bounds?
|
||||
else if (std::abs(len) > str.mLen)
|
||||
{
|
||||
STHROWF("Specified range {} is out of bounds {}", len, str.mLen);
|
||||
}
|
||||
// Should we compute the length backwards?
|
||||
else if (len < 0)
|
||||
{
|
||||
len = str.mLen - std::abs(len); // Subtract from actual length
|
||||
}
|
||||
// Did we trim all of it?
|
||||
else if (len == 0)
|
||||
{
|
||||
return 0; // Nothing to search for
|
||||
}
|
||||
// Perform the request and return the result
|
||||
return static_cast< SQInteger >(utf8nlen(str.mPtr, static_cast< size_t >(len)));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger SqStrChrUTF8(SQInteger chr, StackStrF & str)
|
||||
{
|
||||
// Is the string empty or invalid?
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return -1; // Let the user know that we could not search for this
|
||||
}
|
||||
// Look for the specified character in the string
|
||||
auto * p = reinterpret_cast< const SQChar * >(utf8chr(str.mPtr, static_cast< utf8_int32_t >(chr)));
|
||||
// Return the distance in bytes where the character was found
|
||||
return static_cast< SQInteger >(p - str.mPtr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger SqCaseCmpUTF8(StackStrF & a, StackStrF & b)
|
||||
{
|
||||
// Is the left string invalid?
|
||||
if (a.mLen < 0)
|
||||
{
|
||||
STHROWF("Invalid string on the left {}", a.mLen);
|
||||
}
|
||||
// Is the right string invalid?
|
||||
else if (b.mLen < 0)
|
||||
{
|
||||
STHROWF("Invalid string on the right {}", b.mLen);
|
||||
}
|
||||
// Perform the request and return the result
|
||||
return utf8casecmp(a.mPtr, b.mPtr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger SqNCaseCmpUTF8(StackStrF & a, StackStrF & b)
|
||||
{
|
||||
// Is the left string invalid?
|
||||
if (a.mLen < 0)
|
||||
{
|
||||
STHROWF("Invalid string on the left {}", a.mLen);
|
||||
}
|
||||
// Is the right string invalid?
|
||||
else if (b.mLen < 0)
|
||||
{
|
||||
STHROWF("Invalid string on the right {}", b.mLen);
|
||||
}
|
||||
// See if we can decide this based on length differences
|
||||
else if (a.mLen < b.mLen)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (a.mLen > b.mLen)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
// Perform the request and return the result
|
||||
return utf8ncasecmp(a.mPtr, b.mPtr, static_cast< size_t >(a.mLen));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger SqCaseStrUTF8(StackStrF & hs, StackStrF & nd)
|
||||
{
|
||||
// Is the haystack or needle string empty or invalid?
|
||||
if (hs.mLen <= 0 || nd.mLen <= 0)
|
||||
{
|
||||
return -1; // Let the user know that we could not search for this
|
||||
}
|
||||
// Look for the specified needle string in the haystack string
|
||||
auto * p = reinterpret_cast< const SQChar * >(utf8casestr(hs.mPtr, nd.mPtr));
|
||||
// Return the distance in bytes where the string was found
|
||||
return static_cast< SQInteger >(p - hs.mPtr);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_UTF8(HSQUIRRELVM vm)
|
||||
{
|
||||
Table ns(vm);
|
||||
|
||||
ns
|
||||
.FmtFunc(_SC("StrLen"), &SqStrLenUTF8)
|
||||
.FmtFunc(_SC("StrNLen"), &SqStrNLenUTF8)
|
||||
.FmtFunc(_SC("StrChr"), &SqStrChrUTF8)
|
||||
.FmtFunc(_SC("CaseCmp"), &SqCaseCmpUTF8)
|
||||
.FmtFunc(_SC("NCaseCmp"), &SqNCaseCmpUTF8)
|
||||
.FmtFunc(_SC("CaseStr"), &SqCaseStrUTF8)
|
||||
;
|
||||
|
||||
RootTable(vm).Bind(_SC("SqUTF8"), ns);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
14
module/Library/UTF8.hpp
Normal file
14
module/Library/UTF8.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <utf8.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
@ -41,6 +41,7 @@ extern void Register_Net(HSQUIRRELVM vm);
|
||||
extern void Register_Numeric(HSQUIRRELVM vm);
|
||||
extern void Register_String(HSQUIRRELVM vm);
|
||||
extern void Register_System(HSQUIRRELVM vm);
|
||||
extern void Register_UTF8(HSQUIRRELVM vm);
|
||||
extern void Register_Utils(HSQUIRRELVM vm);
|
||||
extern void Register_XML(HSQUIRRELVM vm);
|
||||
extern void Register_ZMQ(HSQUIRRELVM vm);
|
||||
@ -110,6 +111,7 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
||||
Register_Numeric(vm);
|
||||
Register_String(vm);
|
||||
Register_System(vm);
|
||||
Register_UTF8(vm);
|
||||
Register_Utils(vm);
|
||||
Register_XML(vm);
|
||||
Register_ZMQ(vm);
|
||||
|
1
vendor/CMakeLists.txt
vendored
1
vendor/CMakeLists.txt
vendored
@ -6,6 +6,7 @@ add_subdirectory(SimpleIni)
|
||||
add_subdirectory(TinyDir)
|
||||
add_subdirectory(SAJSON)
|
||||
add_subdirectory(CPR)
|
||||
add_subdirectory(UTF8)
|
||||
add_subdirectory(PUGIXML)
|
||||
add_subdirectory(CivetWeb)
|
||||
set(BUILD_TESTING OFF CACHE INTERNAL "" FORCE)
|
||||
|
13
vendor/UTF8/CMakeLists.txt
vendored
Normal file
13
vendor/UTF8/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Create the UTF8Lib library
|
||||
add_library(UTF8Lib STATIC
|
||||
utf8.h
|
||||
utf8.c
|
||||
)
|
||||
# Set speciffic options
|
||||
target_compile_options(UTF8Lib PRIVATE -fvisibility=hidden)
|
||||
# Includes
|
||||
target_include_directories(UTF8Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
# Private library defines
|
||||
#target_compile_definitions(UTF8Lib PRIVATE )
|
||||
# Public library defines
|
||||
# target_compile_definitions(UTF8Lib PUBLIC )
|
24
vendor/UTF8/LICENSE
vendored
Normal file
24
vendor/UTF8/LICENSE
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
1
vendor/UTF8/utf8.c
vendored
Normal file
1
vendor/UTF8/utf8.c
vendored
Normal file
@ -0,0 +1 @@
|
||||
#include "utf8.h"
|
1662
vendor/UTF8/utf8.h
vendored
Normal file
1662
vendor/UTF8/utf8.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user