/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// boolean functions void xforms_booleanFromStringFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
xmlChar *pString = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE);
OUString aString(reinterpret_cast<char*>(pString), strlen(reinterpret_cast<char*>(pString)), RTL_TEXTENCODING_UTF8); if (aString.equalsIgnoreAsciiCase("true") ||
aString.equalsIgnoreAsciiCase("1"))
xmlXPathReturnTrue(ctxt); elseif (aString.equalsIgnoreAsciiCase("false") ||
aString.equalsIgnoreAsciiCase("0"))
xmlXPathReturnFalse(ctxt); else
XP_ERROR(XPATH_NUMBER_ERROR);
}
void xforms_ifFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ if (nargs != 3) XP_ERROR(XPATH_INVALID_ARITY);
xmlChar *s2 = xmlXPathPopString(ctxt);
if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE);
xmlChar *s1 = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE); bool aBool = xmlXPathPopBoolean(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE);
if (aBool)
xmlXPathReturnString(ctxt, s1); else
xmlXPathReturnString(ctxt, s2);
}
// Number Functions void xforms_avgFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ // use sum(), div() and count() if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
// save nodeset
xmlXPathObjectPtr pObject = valuePop(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE); //push back a copy
valuePush(ctxt, xmlXPathObjectCopy(pObject)); // get the Sum
xmlXPathSumFunction(ctxt, 1); double nSum = xmlXPathPopNumber(ctxt); // push a copy once more
valuePush(ctxt, xmlXPathObjectCopy(pObject));
xmlXPathCountFunction(ctxt, 1); double nCount = xmlXPathPopNumber(ctxt); // push args for div()
xmlXPathReturnNumber(ctxt, nSum);
xmlXPathReturnNumber(ctxt, nCount);
xmlXPathDivValues(ctxt); // the result is now on the ctxt stack
xmlXPathFreeObject(pObject);
}
void xforms_minFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
xmlNodeSetPtr pNodeSet = xmlXPathPopNodeSet(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE); double nMinimum = 0; for (int i = 0; i < xmlXPathNodeSetGetLength(pNodeSet); i++)
{ double nNumber = xmlXPathCastNodeToNumber(xmlXPathNodeSetItem(pNodeSet, i)); if (xmlXPathIsNaN(nNumber))
{
xmlXPathReturnNumber(ctxt, xmlXPathNAN); return;
} if (i == 0)
nMinimum = nNumber; elseif (nNumber < nMinimum)
nMinimum = nNumber;
}
xmlXPathReturnNumber(ctxt, nMinimum);
}
void xforms_maxFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
xmlNodeSetPtr pNodeSet = xmlXPathPopNodeSet(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE); double nMaximum = 0; for (int i = 0; i < xmlXPathNodeSetGetLength(pNodeSet); i++)
{ double nNumber = xmlXPathCastNodeToNumber(xmlXPathNodeSetItem(pNodeSet, i)); if (xmlXPathIsNaN(nNumber))
{
xmlXPathReturnNumber(ctxt, xmlXPathNAN); return;
} if (i == 0)
nMaximum = nNumber; elseif (nNumber > nMaximum)
nMaximum = nNumber;
}
xmlXPathReturnNumber(ctxt, nMaximum);
} void xforms_countNonEmptyFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
xmlNodeSetPtr pNodeSet = xmlXPathPopNodeSet(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE);
sal_Int32 nNotEmpty = 0; for (int i = 0; i < xmlXPathNodeSetGetLength(pNodeSet); i++)
{ const xmlChar *aString = xmlXPathCastNodeToString(xmlXPathNodeSetItem(pNodeSet, i)); if (*aString != 0) nNotEmpty++;
}
xmlXPathReturnNumber(ctxt, nNotEmpty);
} void xforms_indexFunction(xmlXPathParserContextPtr /*ctxt*/, int /*nargs*/)
{ // function index takes a string argument that is the IDREF of a // 'repeat' and returns the current 1-based position of the repeat // index of the identified repeat -- see xforms/9.3.1
// doc.getElementByID // (...)
}
// String Functions void xforms_propertyFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
xmlChar* pString = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE);
OUString aString(reinterpret_cast<char*>(pString), strlen(reinterpret_cast<char*>(pString)), RTL_TEXTENCODING_UTF8); if (aString.equalsIgnoreAsciiCase("version"))
xmlXPathReturnString(ctxt, reinterpret_cast<xmlChar *>(const_cast<char *>("1.0"))); elseif (aString.equalsIgnoreAsciiCase("conformance-level"))
xmlXPathReturnString(ctxt, reinterpret_cast<xmlChar *>(const_cast<char *>("conformance"))); else
xmlXPathReturnEmptyString(ctxt);
}
// Date and Time Functions
static OString makeDateTimeString (const DateTime& aDateTime)
{
OStringBuffer aDateTimeString;
aDateTimeString.append(static_cast<sal_Int32>(aDateTime.GetYear()));
aDateTimeString.append('-'); if (aDateTime.GetMonth()<10) aDateTimeString.append('0');
aDateTimeString.append(static_cast<sal_Int32>(aDateTime.GetMonth()));
aDateTimeString.append('-'); if (aDateTime.GetDay()<10) aDateTimeString.append('0');
aDateTimeString.append(static_cast<sal_Int32>(aDateTime.GetDay()));
aDateTimeString.append('T'); if (aDateTime.GetHour()<10) aDateTimeString.append('0');
aDateTimeString.append(static_cast<sal_Int32>(aDateTime.GetHour()));
aDateTimeString.append(':'); if (aDateTime.GetMin()<10) aDateTimeString.append('0');
aDateTimeString.append(static_cast<sal_Int32>(aDateTime.GetMin()));
aDateTimeString.append(':'); if (aDateTime.GetSec()<10) aDateTimeString.append('0');
aDateTimeString.append(static_cast<sal_Int32>(aDateTime.GetSec()));
aDateTimeString.append('Z');
return aDateTimeString.makeStringAndClear();
}
// returns current system date and time in canonical xsd:dateTime // format void xforms_nowFunction(xmlXPathParserContextPtr ctxt, int/*nargs*/)
{ /* A single lexical representation, which is a subset of the lexical representations allowed by [ISO 8601], is allowed for dateTime. This lexical representation is the [ISO 8601] extended format CCYY-MM-DDThh:mm:ss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day, preceded by an optional leading "-" sign to indicate a negative number. If the sign is omitted, "+" is assumed. The letter "T" is the date/time separator and "hh", "mm", "ss" represent hour, minute and second respectively.
*/
/* 3.2.7.2 Canonical representation The canonical representation for dateTime is defined by prohibiting certain options from the Lexical representation (par.3.2.7.1). Specifically, either the time zone must be omitted or, if present, the time zone must be Coordinated Universal tools::Time (UTC) indicated by a "Z".
*/
OString aDateTimeString; if (std::getenv("STABLE_FIELDS_HACK"))
aDateTimeString = makeDateTimeString(DateTime(DateTime::EMPTY)); else
aDateTimeString = makeDateTimeString(DateTime(DateTime::SYSTEM));
xmlChar *pString = static_cast<xmlChar*>(xmlMalloc(aDateTimeString.getLength()+1));
strncpy(reinterpret_cast<char*>(pString), aDateTimeString.getStr(), aDateTimeString.getLength());
pString[aDateTimeString.getLength()] = 0;
xmlXPathReturnString(ctxt, pString);
}
staticbool parseDateTime(std::u16string_view aString, DateTime& aDateTime)
{ // take apart a canonical literal xsd:dateTime string //CCYY-MM-DDThh:mm:ss(Z)
void xforms_secondsFromDateTimeFunction(xmlXPathParserContextPtr ctxt, int nargs)
{ // number of seconds from 1970-01-01T00:00:00Z to supplied xsd:date(Time)
if (nargs != 1) XP_ERROR(XPATH_INVALID_ARITY);
xmlChar* pString = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt)) XP_ERROR(XPATH_INVALID_TYPE);
OUString aString(reinterpret_cast<char*>(pString), strlen(reinterpret_cast<char*>(pString)), RTL_TEXTENCODING_UTF8);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.