Add c'tor overload to TagValue to prevent conversion to string
This commit is contained in:
parent
8756c8b267
commit
60c757dcf6
16
tagvalue.h
16
tagvalue.h
|
@ -7,6 +7,7 @@
|
||||||
#include <c++utilities/chrono/timespan.h>
|
#include <c++utilities/chrono/timespan.h>
|
||||||
#include <c++utilities/conversion/binaryconversion.h>
|
#include <c++utilities/conversion/binaryconversion.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -66,6 +67,7 @@ public:
|
||||||
TagValue();
|
TagValue();
|
||||||
TagValue(const char *text, std::size_t textSize, TagTextEncoding textEncoding = TagTextEncoding::Latin1,
|
TagValue(const char *text, std::size_t textSize, TagTextEncoding textEncoding = TagTextEncoding::Latin1,
|
||||||
TagTextEncoding convertTo = TagTextEncoding::Unspecified);
|
TagTextEncoding convertTo = TagTextEncoding::Unspecified);
|
||||||
|
TagValue(const char *text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
|
||||||
TagValue(
|
TagValue(
|
||||||
const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
|
const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
|
||||||
TagValue(int value);
|
TagValue(int value);
|
||||||
|
@ -179,6 +181,20 @@ inline TagValue::TagValue(const char *text, std::size_t textSize, TagTextEncodin
|
||||||
assignText(text, textSize, textEncoding, convertTo);
|
assignText(text, textSize, textEncoding, convertTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a new TagValue holding a copy of the given \a text.
|
||||||
|
* \param text Specifies the text to be assigned. This string must be null-terminated.
|
||||||
|
* \param textEncoding Specifies the encoding of the given \a text.
|
||||||
|
* \param convertTo Specifies the encoding to convert \a text to; set to TagTextEncoding::Unspecified to
|
||||||
|
* use \a textEncoding without any character set conversions.
|
||||||
|
* \throws Throws a ConversionException if the conversion the specified character set fails.
|
||||||
|
* \remarks Strips the BOM of the specified \a text.
|
||||||
|
*/
|
||||||
|
inline TagValue::TagValue(const char *text, TagTextEncoding textEncoding, TagTextEncoding convertTo)
|
||||||
|
{
|
||||||
|
assignText(text, std::strlen(text), textEncoding, convertTo);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs a new TagValue holding a copy of the given \a text.
|
* \brief Constructs a new TagValue holding a copy of the given \a text.
|
||||||
* \param text Specifies the text to be assigned.
|
* \param text Specifies the text to be assigned.
|
||||||
|
|
|
@ -146,6 +146,7 @@ void TagValueTests::testDateTime()
|
||||||
void TagValueTests::testString()
|
void TagValueTests::testString()
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL("15\xe4"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Latin1));
|
CPPUNIT_ASSERT_EQUAL("15\xe4"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Latin1));
|
||||||
|
CPPUNIT_ASSERT_EQUAL("15\xe4"s, TagValue("15ä", TagTextEncoding::Utf8, TagTextEncoding::Latin1).toString());
|
||||||
CPPUNIT_ASSERT_EQUAL("15ä"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Utf8));
|
CPPUNIT_ASSERT_EQUAL("15ä"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Utf8));
|
||||||
CPPUNIT_ASSERT_EQUAL("\x31\0\x35\0"s, TagValue(15).toString(TagTextEncoding::Utf16LittleEndian));
|
CPPUNIT_ASSERT_EQUAL("\x31\0\x35\0"s, TagValue(15).toString(TagTextEncoding::Utf16LittleEndian));
|
||||||
CPPUNIT_ASSERT_EQUAL("\0\x31\0\x35"s, TagValue(15).toString(TagTextEncoding::Utf16BigEndian));
|
CPPUNIT_ASSERT_EQUAL("\0\x31\0\x35"s, TagValue(15).toString(TagTextEncoding::Utf16BigEndian));
|
||||||
|
|
Loading…
Reference in New Issue