Ejemplo n.º 1
0
static void
cal(const int m, const int y, char *p, const int w)
{
	int d, i;
	char *s;

	s = (char *)p;
	d = jan1(y);
	mon[2] = 29;
	mon[9] = 30;

	switch ((jan1(y+1)+7-d)%7) {

	/*
	 *	non-leap year
	 */
	case 1:
		mon[2] = 28;
		break;

	/*
	 *	1752
	 */
	default:
		mon[9] = 19;
		break;

	/*
	 *	leap year
	 */
	case 2:
		;
	}
	for (i = 1; i < m; i++)
		d += mon[i];
	d %= 7;
	s += 3*d;
	for (i = 1; i <= mon[m]; i++) {
		if (i == 3 && mon[m] == 19) {
			i += 11;
			mon[m] += 11;
		}
		if (i > 9)
			*s = i/10+'0';
		s++;
		*s++ = i%10+'0';
		s++;
		if (++d == 7) {
			d = 0;
			s = p+w;
			p = s;
		}
	}
}
Ejemplo n.º 2
0
unsigned char DateTime::get_week() const
{
	throw_if_null();
	int day_of_week = 1 + ((get_day_of_week()+6)%7);
	DateTime dt = *this;
	DateTime nearest_thursday = dt.add_days(4 - day_of_week);
	DateTime jan1(nearest_thursday.year, 1, 1);
	int days = jan1.get_difference_in_days(nearest_thursday);
	int week = 1 + days / 7; // Count of Thursdays 
	return week;
}
Ejemplo n.º 3
0
  bool YearDescription_Impl::isLeapYear() const {

    boost::optional<int> calendarYear = this->calendarYear();
    if (calendarYear){
      openstudio::Date jan1(MonthOfYear::Jan, 1, *calendarYear);
      bool result = jan1.isLeapYear();
      return result;
    }

    boost::optional<std::string> value = getString(OS_YearDescriptionFields::IsLeapYear,true);
    OS_ASSERT(value);
    return openstudio::istringEqual(value.get(), "Yes");
  }
Ejemplo n.º 4
0
  std::string YearDescription_Impl::dayofWeekforStartDay() const {

    boost::optional<int> calendarYear = this->calendarYear();
    if (calendarYear){
      openstudio::Date jan1(MonthOfYear::Jan, 1, *calendarYear);
      std::string result = jan1.dayOfWeek().valueName();
      return result;
    }

    boost::optional<std::string> value = getString(OS_YearDescriptionFields::DayofWeekforStartDay,true);
    OS_ASSERT(value);
    return value.get();
  }
Ejemplo n.º 5
0
void NOTATIONDatatypeValidator::checkValueSpace(const XMLCh* const content
                                                , MemoryManager* const manager)
{
    //
    //  NOTATATION: <URI>:<localPart>
    //  where URI is optional
    //        ':' and localPart must be present
    //
    int contentLength = XMLString::stringLen(content);
    int colonPosition = XMLString::lastIndexOf(content, chColon);

    if ((colonPosition == -1)                ||  // no ':'
        (colonPosition == contentLength - 1)  )  // <URI>':'
        ThrowXMLwithMemMgr1(InvalidDatatypeValueException
                , XMLExcepts::VALUE_NOTATION_Invalid
                , content
                , manager);

    if (colonPosition > 0)
    {
        // Extract URI
        XMLCh* uriPart = (XMLCh*) manager->allocate
        (
            (colonPosition + 1) * sizeof(XMLCh)
        );//new XMLCh[colonPosition + 1];
        ArrayJanitor<XMLCh> jan1(uriPart, manager);
        XMLString::subString(uriPart, content, 0, colonPosition, manager);

        try
        {
            // no relative uri support here
            XMLUri  newURI(uriPart, manager);
        }
        catch(const OutOfMemoryException&)
        {
            throw;
        }
        catch (...)
        {
            ThrowXMLwithMemMgr1(InvalidDatatypeValueException
                    , XMLExcepts::VALUE_NOTATION_Invalid
                    , content
                    , manager);
        }
    }

    // Extract localpart
    XMLCh* localPart = (XMLCh*) manager->allocate
    (
        (contentLength - colonPosition) * sizeof(XMLCh)
    );//new XMLCh[contentLength - colonPosition];
    ArrayJanitor<XMLCh> jan2(localPart, manager);
    XMLString::subString(localPart, content, colonPosition + 1, contentLength, manager);

    if ( !XMLString::isValidNCName(localPart))
    {
        ThrowXMLwithMemMgr1(InvalidDatatypeValueException
                , XMLExcepts::VALUE_NOTATION_Invalid
                , content
                , manager);
    }

}
Ejemplo n.º 6
0
// ---------------------------------------------------------------------------
//  Public Constructors and Destructor
// ---------------------------------------------------------------------------
ICUMsgLoader::ICUMsgLoader(const XMLCh* const  msgDomain)
:fLocaleBundle(0)
,fDomainBundle(0)
{
    /***
	    Validate msgDomain
    ***/
    if (!XMLString::equals(msgDomain, XMLUni::fgXMLErrDomain)    &&
        !XMLString::equals(msgDomain, XMLUni::fgExceptDomain)    &&
        !XMLString::equals(msgDomain, XMLUni::fgXMLDOMMsgDomain) &&
        !XMLString::equals(msgDomain, XMLUni::fgValidityDomain)   )
    {
        XMLPlatformUtils::panic(PanicHandler::Panic_UnknownMsgDomain);
    }

    /***
	Resolve domainName
    ***/
    int     index = XMLString::lastIndexOf(msgDomain, chForwardSlash);
    char*   domainName = XMLString::transcode(&(msgDomain[index + 1]), XMLPlatformUtils::fgMemoryManager);
    ArrayJanitor<char> jan1(domainName, XMLPlatformUtils::fgMemoryManager);

    /***
        Location resolution priority

         1. XMLMsgLoader::getNLSHome(), set by user through
            XMLPlatformUtils::Initialize(), which provides user-specified
            location where the message loader shall retrieve error messages.

         2. environment var: XERCESC_NLS_HOME

         3. path $XERCESCROOT/msg
    ***/

    char locationBuf[1024];
    memset(locationBuf, 0, sizeof locationBuf);
    const char *nlsHome = XMLMsgLoader::getNLSHome();

    if (nlsHome)
    {
    	strcpy(locationBuf, nlsHome);
        strcat(locationBuf, U_FILE_SEP_STRING);
    }
    else
    {
        nlsHome = getenv("XERCESC_NLS_HOME");
        if (nlsHome)
        {
            strcpy(locationBuf, nlsHome);
            strcat(locationBuf, U_FILE_SEP_STRING);
        }
        else
        {
            nlsHome = getenv("XERCESCROOT");
            if (nlsHome)
            {
                strcpy(locationBuf, nlsHome);
                strcat(locationBuf, U_FILE_SEP_STRING);
                strcat(locationBuf, "msg");
                strcat(locationBuf, U_FILE_SEP_STRING);
            }
            else
            {
                /***
                 leave it to ICU to decide where to search
                 for the error message.
                 ***/
                 setAppData();
            }
        }
    }

    /***
	Open the locale-specific resource bundle
    ***/
    strcat(locationBuf, BUNDLE_NAME);
    UErrorCode err = U_ZERO_ERROR;
    uloc_setDefault("root", &err);   // in case user-specified locale unavailable
    err = U_ZERO_ERROR;
    fLocaleBundle = ures_open(locationBuf, XMLMsgLoader::getLocale(), &err);
    if (!U_SUCCESS(err) || fLocaleBundle == NULL)
    {
    	/***
    	   in case user specified location does not work
    	   try the dll
        ***/

        if (strcmp(locationBuf, BUNDLE_NAME) !=0 )
        {
            setAppData();
            err = U_ZERO_ERROR;
            fLocaleBundle = ures_open(BUNDLE_NAME, XMLMsgLoader::getLocale(), &err);
            if (!U_SUCCESS(err) || fLocaleBundle == NULL)
            {
                 XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
            }
        }
        else
        {
            XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
        }
    }

    /***
	Open the domain specific resource bundle within
	the locale-specific resource bundle
    ***/
    err = U_ZERO_ERROR;
    fDomainBundle = ures_getByKey(fLocaleBundle, domainName, NULL, &err);
    if (!U_SUCCESS(err) || fDomainBundle == NULL)
    {
        XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
    }

}