diff options
Diffstat (limited to 'configmgr/source/valueparser.cxx')
-rw-r--r-- | configmgr/source/valueparser.cxx | 105 |
1 files changed, 61 insertions, 44 deletions
diff --git a/configmgr/source/valueparser.cxx b/configmgr/source/valueparser.cxx index 6245cb11b654..83ddd245dc06 100644 --- a/configmgr/source/valueparser.cxx +++ b/configmgr/source/valueparser.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/uno/RuntimeException.hpp> #include <com/sun/star/uno/Sequence.hxx> #include <comphelper/sequence.hxx> +#include <o3tl/string_view.hxx> #include <rtl/math.h> #include <rtl/string.h> #include <rtl/string.hxx> @@ -33,6 +34,7 @@ #include <xmlreader/span.hxx> #include <xmlreader/xmlreader.hxx> +#include "data.hxx" #include "localizedvaluenode.hxx" #include "node.hxx" #include "nodemap.hxx" @@ -78,16 +80,21 @@ bool parseValue(xmlreader::Span const & text, sal_Bool * value) { bool parseValue(xmlreader::Span const & text, sal_Int16 * value) { assert(text.is() && value != nullptr); // For backwards compatibility, support hexadecimal values: - sal_Int32 n = + bool bStartWithHexPrefix = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( text.begin, text.length, RTL_CONSTASCII_STRINGPARAM("0X"), - RTL_CONSTASCII_LENGTH("0X")) == 0 ? - static_cast< sal_Int32 >( - OString( + RTL_CONSTASCII_LENGTH("0X")) == 0; + sal_Int32 n; + if (bStartWithHexPrefix) + { + std::string_view sView( text.begin + RTL_CONSTASCII_LENGTH("0X"), - text.length - RTL_CONSTASCII_LENGTH("0X")).toUInt32(16)) : - OString(text.begin, text.length).toInt32(); - //TODO: check valid lexical representation + text.length - RTL_CONSTASCII_LENGTH("0X")); + n = o3tl::toUInt32(sView, 16); + } + else + n = o3tl::toInt32(std::string_view(text.begin, text.length)); + //TODO: check valid lexical representation if (n >= SAL_MIN_INT16 && n <= SAL_MAX_INT16) { *value = static_cast< sal_Int16 >(n); return true; @@ -98,32 +105,41 @@ bool parseValue(xmlreader::Span const & text, sal_Int16 * value) { bool parseValue(xmlreader::Span const & text, sal_Int32 * value) { assert(text.is() && value != nullptr); // For backwards compatibility, support hexadecimal values: - *value = - rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( + bool bStartWithHexPrefix = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( text.begin, text.length, RTL_CONSTASCII_STRINGPARAM("0X"), - RTL_CONSTASCII_LENGTH("0X")) == 0 ? - static_cast< sal_Int32 >( - OString( - text.begin + RTL_CONSTASCII_LENGTH("0X"), - text.length - RTL_CONSTASCII_LENGTH("0X")).toUInt32(16)) : - OString(text.begin, text.length).toInt32(); - //TODO: check valid lexical representation + RTL_CONSTASCII_LENGTH("0X")) == 0; + + if (bStartWithHexPrefix) + { + std::string_view sView(text.begin + RTL_CONSTASCII_LENGTH("0X"), + text.length - RTL_CONSTASCII_LENGTH("0X")); + *value = static_cast< sal_Int32 >(o3tl::toUInt32(sView, 16)); + } + else + { + std::string_view sView(text.begin, text.length); + *value = o3tl::toInt32(sView); + } + //TODO: check valid lexical representation return true; } bool parseValue(xmlreader::Span const & text, sal_Int64 * value) { assert(text.is() && value != nullptr); // For backwards compatibility, support hexadecimal values: - *value = + bool bStartWithHexPrefix = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( text.begin, text.length, RTL_CONSTASCII_STRINGPARAM("0X"), - RTL_CONSTASCII_LENGTH("0X")) == 0 ? - static_cast< sal_Int64 >( - OString( + RTL_CONSTASCII_LENGTH("0X")) == 0; + if (bStartWithHexPrefix) + { + OString sSuffix( text.begin + RTL_CONSTASCII_LENGTH("0X"), - text.length - RTL_CONSTASCII_LENGTH("0X")).toUInt64(16)) : - OString(text.begin, text.length).toInt64(); - //TODO: check valid lexical representation + text.length - RTL_CONSTASCII_LENGTH("0X")); + *value = static_cast< sal_Int64 >(sSuffix.toUInt64(16)); + } + else *value = o3tl::toInt64(std::string_view(text.begin, text.length)); + //TODO: check valid lexical representation return true; } @@ -252,22 +268,23 @@ ValueParser::ValueParser(int layer): type_(TYPE_ERROR), layer_(layer), state_() ValueParser::~ValueParser() {} xmlreader::XmlReader::Text ValueParser::getTextMode() const { - if (node_.is()) { - switch (state_) { - case State::Text: - if (!items_.empty()) { - break; - } - [[fallthrough]]; - case State::IT: - return - (type_ == TYPE_STRING || type_ == TYPE_STRING_LIST || - !separator_.isEmpty()) - ? xmlreader::XmlReader::Text::Raw - : xmlreader::XmlReader::Text::Normalized; - default: + if (!node_) + return xmlreader::XmlReader::Text::NONE; + + switch (state_) { + case State::Text: + if (!items_.empty()) { break; } + [[fallthrough]]; + case State::IT: + return + (type_ == TYPE_STRING || type_ == TYPE_STRING_LIST || + !separator_.isEmpty()) + ? xmlreader::XmlReader::Text::Raw + : xmlreader::XmlReader::Text::Normalized; + default: + break; } return xmlreader::XmlReader::Text::NONE; } @@ -346,21 +363,20 @@ bool ValueParser::endElement() { switch (node_->kind()) { case Node::KIND_PROPERTY: - pValue = static_cast< PropertyNode * >(node_.get())->getValuePtr(layer_); + pValue = static_cast< PropertyNode * >(node_.get())->getValuePtr(layer_, layer_ == Data::NO_LAYER); break; case Node::KIND_LOCALIZED_PROPERTY: { NodeMap & members = node_->getMembers(); - NodeMap::iterator i(members.find(localizedName_)); + auto [i, bInserted] = members.insert(NodeMap::value_type(localizedName_, nullptr)); LocalizedValueNode *pLVNode; - if (i == members.end()) { + if (bInserted) { pLVNode = new LocalizedValueNode(layer_); - members.insert( - NodeMap::value_type(localizedName_, pLVNode )); + i->second = pLVNode; } else { pLVNode = static_cast< LocalizedValueNode * >(i->second.get()); } - pValue = pLVNode->getValuePtr(layer_); + pValue = pLVNode->getValuePtr(layer_, layer_ == Data::NO_LAYER); } break; default: @@ -439,8 +455,9 @@ void ValueParser::start( template< typename T > css::uno::Any ValueParser::convertItems() { css::uno::Sequence< T > seq(items_.size()); + auto seqRange = asNonConstRange(seq); for (sal_Int32 i = 0; i < seq.getLength(); ++i) { - bool ok = (items_[i] >>= seq[i]); + bool ok = (items_[i] >>= seqRange[i]); assert(ok); (void) ok; // avoid warnings } |