?? xmldatetime.cpp
字號:
tmpDate.fTimeZone[hh] = 14; tmpDate.fTimeZone[mm] = 0; tmpDate.fValue[utc] = utc_type; tmpDate.normalize(); return (set2Left? XMLDateTime::compareOrder(&tmpDate, pDate2) : XMLDateTime::compareOrder(pDate1, &tmpDate));}int XMLDateTime::compareOrder(const XMLDateTime* const lValue , const XMLDateTime* const rValue) //, MemoryManager* const memMgr){ // // If any of the them is not normalized() yet, // we need to do something here. // XMLDateTime lTemp = *lValue; XMLDateTime rTemp = *rValue; lTemp.normalize(); rTemp.normalize(); for ( int i = 0 ; i < TOTAL_SIZE; i++ ) { if ( lTemp.fValue[i] < rTemp.fValue[i] ) { return LESS_THAN; } else if ( lTemp.fValue[i] > rTemp.fValue[i] ) { return GREATER_THAN; } } if ( lTemp.fHasTime) { if ( lTemp.fMiliSecond < rTemp.fMiliSecond ) { return LESS_THAN; } else if ( lTemp.fMiliSecond > rTemp.fMiliSecond ) { return GREATER_THAN; } } return EQUAL;}// ---------------------------------------------------------------------------// ctor and dtor// ---------------------------------------------------------------------------XMLDateTime::~XMLDateTime(){ if (fBuffer) fMemoryManager->deallocate(fBuffer);//delete[] fBuffer; }XMLDateTime::XMLDateTime(MemoryManager* const manager): fStart(0), fEnd(0), fBufferMaxLen(0), fBuffer(0), fMiliSecond(0), fHasTime(false), fMemoryManager(manager){ reset();}XMLDateTime::XMLDateTime(const XMLCh* const aString, MemoryManager* const manager): fStart(0), fEnd(0), fBufferMaxLen(0), fBuffer(0), fMiliSecond(0), fHasTime(false), fMemoryManager(manager){ setBuffer(aString);}// -----------------------------------------------------------------------// Copy ctor and Assignment operators// -----------------------------------------------------------------------XMLDateTime::XMLDateTime(const XMLDateTime &toCopy): fBufferMaxLen(0), fBuffer(0), fMemoryManager(toCopy.fMemoryManager){ copy(toCopy);}XMLDateTime& XMLDateTime::operator=(const XMLDateTime& rhs){ if (this == &rhs) return *this; copy(rhs); return *this;}// -----------------------------------------------------------------------// Implementation of Abstract Interface// -----------------------------------------------------------------------//// We may simply return the handle to fBuffer, but// for the sake of consistency, we return a duplicated copy// and the caller is responsible for the release of the buffer// just like any other things in the XMLNumber family.//XMLCh* XMLDateTime::toString() const{ assertBuffer(); // Return data using global operator new XMLCh* retBuf = XMLString::replicate(fBuffer); return retBuf;}//// We may simply return the handle to fBuffer//XMLCh* XMLDateTime::getRawData() const{ assertBuffer(); return fBuffer;}const XMLCh* XMLDateTime::getFormattedString() const{ return getRawData();}int XMLDateTime::getSign() const{ return 0;}// ---------------------------------------------------------------------------// Parsers// ---------------------------------------------------------------------------//// [-]{CCYY-MM-DD}'T'{HH:MM:SS.MS}[TimeZone]//void XMLDateTime::parseDateTime(){ initParser(); getDate(); //fStart is supposed to point to 'T' if (fBuffer[fStart++] != DATETIME_SEPARATOR) ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_dt_missingT , fBuffer , fMemoryManager); getTime(); validateDateTime(); normalize(); fHasTime = true;}//// [-]{CCYY-MM-DD}[TimeZone]//void XMLDateTime::parseDate(){ initParser(); getDate(); parseTimeZone(); validateDateTime(); normalize();}void XMLDateTime::parseTime(){ initParser(); // time initialize to default values fValue[CentYear]= YEAR_DEFAULT; fValue[Month] = MONTH_DEFAULT; fValue[Day] = DAY_DEFAULT; getTime(); validateDateTime(); normalize(); fHasTime = true;}//// {---DD}[TimeZone]// 01234//void XMLDateTime::parseDay(){ initParser(); if (fBuffer[0] != DATE_SEPARATOR || fBuffer[1] != DATE_SEPARATOR || fBuffer[2] != DATE_SEPARATOR ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_gDay_invalid , fBuffer , fMemoryManager); } //initialize values fValue[CentYear] = YEAR_DEFAULT; fValue[Month] = MONTH_DEFAULT; fValue[Day] = parseInt(fStart+3, fStart+5); if ( DAY_SIZE < fEnd ) { int sign = findUTCSign(DAY_SIZE); if ( sign < 0 ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_gDay_invalid , fBuffer , fMemoryManager); } else { getTimeZone(sign); } } validateDateTime(); normalize();}//// {--MM--}[TimeZone]// {--MM}[TimeZone]// 012345//void XMLDateTime::parseMonth(){ initParser(); if (fBuffer[0] != DATE_SEPARATOR || fBuffer[1] != DATE_SEPARATOR ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_gMth_invalid , fBuffer , fMemoryManager); } //set constants fValue[CentYear] = YEAR_DEFAULT; fValue[Day] = DAY_DEFAULT; fValue[Month] = parseInt(2, 4); // REVISIT: allow both --MM and --MM-- now. // need to remove the following lines to disallow --MM-- // when the errata is officially in the rec. fStart = 4; if ( fEnd >= fStart+2 && fBuffer[fStart] == DATE_SEPARATOR && fBuffer[fStart+1] == DATE_SEPARATOR ) { fStart += 2; } // // parse TimeZone if any // if ( fStart < fEnd ) { int sign = findUTCSign(fStart); if ( sign < 0 ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_gMth_invalid , fBuffer , fMemoryManager); } else { getTimeZone(sign); } } validateDateTime(); normalize();}////[-]{CCYY}[TimeZone]// 0 1234//void XMLDateTime::parseYear(){ initParser(); // skip the first '-' and search for timezone // int sign = findUTCSign((fBuffer[0] == chDash) ? 1 : 0); if (sign == NOT_FOUND) { fValue[CentYear] = parseIntYear(fEnd); } else { fValue[CentYear] = parseIntYear(sign); getTimeZone(sign); } //initialize values fValue[Month] = MONTH_DEFAULT; fValue[Day] = DAY_DEFAULT; //java is 1 validateDateTime(); normalize();}////{--MM-DD}[TimeZone]// 0123456//void XMLDateTime::parseMonthDay(){ initParser(); if (fBuffer[0] != DATE_SEPARATOR || fBuffer[1] != DATE_SEPARATOR || fBuffer[4] != DATE_SEPARATOR ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_gMthDay_invalid , fBuffer , fMemoryManager); } //initialize fValue[CentYear] = YEAR_DEFAULT; fValue[Month] = parseInt(2, 4); fValue[Day] = parseInt(5, 7); if ( MONTHDAY_SIZE < fEnd ) { int sign = findUTCSign(MONTHDAY_SIZE); if ( sign<0 ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_gMthDay_invalid , fBuffer , fMemoryManager); } else { getTimeZone(sign); } } validateDateTime(); normalize();}void XMLDateTime::parseYearMonth(){ initParser(); // get date getYearMonth(); fValue[Day] = DAY_DEFAULT; parseTimeZone(); validateDateTime(); normalize();}////PnYn MnDTnH nMnS: -P1Y2M3DT10H30M//// [-]{'P'{[n'Y'][n'M'][n'D']['T'][n'H'][n'M'][n'S']}}//// Note: the n above shall be >= 0// if no time element found, 'T' shall be absent//void XMLDateTime::parseDuration(){ initParser(); // must start with '-' or 'P' // XMLCh c = fBuffer[fStart++]; if ( (c != DURATION_STARTER) && (c != chDash) ) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_dur_Start_dashP , fBuffer , fMemoryManager); } // 'P' must ALWAYS be present in either case if ( (c == chDash) && (fBuffer[fStart++]!= DURATION_STARTER )) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_dur_noP , fBuffer , fMemoryManager); } // java code //date[utc]=(c=='-')?'-':0; //fValue[utc] = UTC_STD; fValue[utc] = (fBuffer[0] == chDash? UTC_NEG : UTC_STD); int negate = ( fBuffer[0] == chDash ? -1 : 1); // // No negative value is allowed after 'P' // // eg P-1234, invalid // if (indexOf(fStart, fEnd, chDash) != NOT_FOUND) { ThrowXMLwithMemMgr1(SchemaDateTimeException , XMLExcepts::DateTime_dur_DashNotFirst , fBuffer , fMemoryManager); } //at least one number and designator must be seen after P bool designator = false; int endDate = indexOf(fStart, fEnd, DATETIME_SEPARATOR); if ( endDate == NOT_FOUND ) { endDate = fEnd; // 'T' absent }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -