24#include <com/sun/star/uno/Any.hxx>
25#include <com/sun/star/uno/RuntimeException.hpp>
26#include <com/sun/star/uno/Sequence.hxx>
29#include <rtl/string.h>
30#include <rtl/string.hxx>
31#include <rtl/ustring.hxx>
48bool parseHexDigit(
char c,
int * value) {
49 assert(value !=
nullptr);
50 if (c >=
'0' && c <=
'9') {
54 if (c >=
'A' && c <=
'F') {
55 *
value = c -
'A' + 10;
58 if (c >=
'a' && c <=
'f') {
59 *
value = c -
'a' + 10;
66 assert(
text.is() && value !=
nullptr);
67 if (text ==
"true" || text ==
"1") {
71 if (text ==
"false" || text ==
"0") {
79 assert(
text.is() && value !=
nullptr);
82 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
83 text.begin,
text.length, RTL_CONSTASCII_STRINGPARAM(
"0X"),
84 RTL_CONSTASCII_LENGTH(
"0X")) == 0 ?
85 static_cast< sal_Int32
>(
87 text.begin + RTL_CONSTASCII_LENGTH(
"0X"),
88 text.length - RTL_CONSTASCII_LENGTH(
"0X")).toUInt32(16)) :
89 OString(
text.begin,
text.length).toInt32();
91 if (n >= SAL_MIN_INT16 && n <= SAL_MAX_INT16) {
92 *
value =
static_cast< sal_Int16
>(
n);
99 assert(
text.is() && value !=
nullptr);
102 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
103 text.begin,
text.length, RTL_CONSTASCII_STRINGPARAM(
"0X"),
104 RTL_CONSTASCII_LENGTH(
"0X")) == 0 ?
105 static_cast< sal_Int32
>(
107 text.begin + RTL_CONSTASCII_LENGTH(
"0X"),
108 text.length - RTL_CONSTASCII_LENGTH(
"0X")).toUInt32(16)) :
109 OString(
text.begin,
text.length).toInt32();
115 assert(
text.is() && value !=
nullptr);
118 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
119 text.begin,
text.length, RTL_CONSTASCII_STRINGPARAM(
"0X"),
120 RTL_CONSTASCII_LENGTH(
"0X")) == 0 ?
121 static_cast< sal_Int64
>(
123 text.begin + RTL_CONSTASCII_LENGTH(
"0X"),
124 text.length - RTL_CONSTASCII_LENGTH(
"0X")).toUInt64(16)) :
125 OString(
text.begin,
text.length).toInt64();
131 assert(
text.is() && value !=
nullptr);
132 *
value = rtl_math_stringToDouble(
133 text.begin,
text.begin +
text.length,
'.', 0,
nullptr,
nullptr);
139 assert(
text.is() && value !=
nullptr);
147 assert(
text.is() && value !=
nullptr);
148 if ((
text.length & 1) != 0) {
151 std::vector< sal_Int8 > seq;
152 for (sal_Int32 i = 0;
i !=
text.length;) {
155 if (!parseHexDigit(
text.begin[i++], &n1) ||
156 !parseHexDigit(
text.begin[i++], &n2))
160 seq.push_back(
static_cast< sal_Int8 >((n1 << 4) | n2));
166template<
typename T > css::uno::Any parseSingleValue(
170 if (!parseValue(text, &val)) {
171 throw css::uno::RuntimeException(
"invalid value");
173 return css::uno::Any(val);
176template<
typename T > css::uno::Any parseListValue(
179 std::vector< T > seq;
186 if (
text.length != 0) {
188 sal_Int32
i = rtl_str_indexOfStr_WithLength(
194 throw css::uno::RuntimeException(
"invalid value");
207css::uno::Any parseValue(
212 throw css::uno::RuntimeException(
"invalid value of type any");
214 return parseSingleValue< sal_Bool >(text);
216 return parseSingleValue< sal_Int16 >(text);
218 return parseSingleValue< sal_Int32 >(text);
220 return parseSingleValue< sal_Int64 >(text);
222 return parseSingleValue< double >(text);
224 return parseSingleValue< OUString >(text);
226 return parseSingleValue< css::uno::Sequence< sal_Int8 > >(
text);
228 return parseListValue< sal_Bool >(separator, text);
230 return parseListValue< sal_Int16 >(separator, text);
232 return parseListValue< sal_Int32 >(separator, text);
234 return parseListValue< sal_Int64 >(separator, text);
236 return parseListValue< double >(separator, text);
238 return parseListValue< OUString >(separator, text);
240 return parseListValue< css::uno::Sequence< sal_Int8 > >(
244 throw css::uno::RuntimeException(
"this cannot happen");
256 return xmlreader::XmlReader::Text::NONE;
268 ? xmlreader::XmlReader::Text::Raw
269 : xmlreader::XmlReader::Text::Normalized;
273 return xmlreader::XmlReader::Text::NONE;
299 sal_Int32 scalar = -1;
315 if (scalar >= 0 && scalar < 0x20 && scalar != 0x09 &&
316 scalar != 0x0A && scalar != 0x0D)
318 char c =
static_cast< char >(scalar);
320 }
else if (scalar == 0xFFFE) {
321 pad_.
add(RTL_CONSTASCII_STRINGPARAM(
"\xEF\xBF\xBE"));
322 }
else if (scalar == 0xFFFF) {
323 pad_.
add(RTL_CONSTASCII_STRINGPARAM(
"\xEF\xBF\xBF"));
325 throw css::uno::RuntimeException(
326 "bad unicode scalar attribute in " + reader.
getUrl());
335 throw css::uno::RuntimeException(
336 "bad member <" +
name.convertFromUtf8() +
"> in " + reader.
getUrl());
346 css::uno::Any *pValue =
nullptr;
348 switch (
node_->kind()) {
377 *pValue = convertItems< sal_Bool >();
380 *pValue = convertItems< sal_Int16 >();
383 *pValue = convertItems< sal_Int32 >();
386 *pValue = convertItems< sal_Int64 >();
389 *pValue = convertItems< double >();
392 *pValue = convertItems< OUString >();
395 *pValue = convertItems< css::uno::Sequence< sal_Int8 > >();
433 assert(node.is() && !
node_.is());
441 css::uno::Sequence< T > seq(
items_.size());
442 auto seqRange = asNonConstRange(seq);
443 for (sal_Int32
i = 0;
i < seq.getLength(); ++
i) {
444 bool ok = (
items_[
i] >>= seqRange[
i]);
448 return css::uno::Any(seq);
css::uno::Any * getValuePtr(int layer)
NodeMapImpl::value_type value_type
@ KIND_LOCALIZED_PROPERTY
css::uno::Any convertItems()
void characters(xmlreader::Span const &text)
rtl::Reference< Node > node_
bool startElement(xmlreader::XmlReader &reader, int nsId, xmlreader::Span const &name)
xmlreader::XmlReader::Text getTextMode() const
void start(rtl::Reference< Node > const &property, OUString const &localizedName=OUString())
std::vector< css::uno::Any > items_
void add(char const *begin, sal_Int32 length)
const OUString & getUrl() const
bool nextAttribute(int *nsId, Span *localName)
Span getAttributeValue(bool fullyNormalize)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool isListType(Type type)
Type elementType(Type type)
PyObject_HEAD PyUNO_callable_Internals * members