Core/PacketIO: Add a validating string helper class for use in packet classes
(cherry picked from commit f2f47f774f3d9c5da1a38b5f20cbfe59c2ff66af)
This commit is contained in:
@@ -16,9 +16,48 @@
|
||||
*/
|
||||
|
||||
#include "PacketUtilities.h"
|
||||
#include "Hyperlinks.h"
|
||||
#include "Errors.h"
|
||||
#include <utf8.h>
|
||||
#include <sstream>
|
||||
|
||||
WorldPackets::InvalidStringValueException::InvalidStringValueException(std::string const& value) : ByteBufferInvalidValueException("string", value.c_str())
|
||||
{
|
||||
}
|
||||
|
||||
WorldPackets::InvalidUtf8ValueException::InvalidUtf8ValueException(std::string const& value) : InvalidStringValueException(value)
|
||||
{
|
||||
}
|
||||
|
||||
WorldPackets::InvalidHyperlinkException::InvalidHyperlinkException(std::string const& value) : InvalidStringValueException(value)
|
||||
{
|
||||
}
|
||||
|
||||
WorldPackets::IllegalHyperlinkException::IllegalHyperlinkException(std::string const& value) : InvalidStringValueException(value)
|
||||
{
|
||||
}
|
||||
|
||||
bool WorldPackets::Strings::Utf8::Validate(std::string const& value)
|
||||
{
|
||||
if (!utf8::is_valid(value.begin(), value.end()))
|
||||
throw InvalidUtf8ValueException(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WorldPackets::Strings::Hyperlinks::Validate(std::string const& value)
|
||||
{
|
||||
if (!Trinity::Hyperlinks::CheckAllLinks(value))
|
||||
throw InvalidHyperlinkException(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WorldPackets::Strings::NoHyperlinks::Validate(std::string const& value)
|
||||
{
|
||||
if (value.find('|') != std::string::npos)
|
||||
throw IllegalHyperlinkException(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
WorldPackets::PacketArrayMaxCapacityException::PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit)
|
||||
{
|
||||
std::ostringstream builder;
|
||||
|
||||
Reference in New Issue
Block a user