12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429 |
- {
- Parser functions to parser xml xsd types
- See: http://books.xmlschemata.org/relaxng/relax-CHP-19.html
- Copyright (C) 2011 by Ivo Steinmann
- }
- unit xmlxsdparser;
- {$mode objfpc}
- {$H+}
- interface
- uses
- {$IFDEF MSWINDOWS}windows,{$ENDIF}
- {$IFDEF UNIX}unixutil,{$ENDIF}
- sysutils,
- dateutils,
- math,
- Classes;
- resourcestring
- SXsdParserError = 'parsing "%s" as "%s" failed';
- type
- {$IFDEF MSWINDOWS}
- PBoolean = System.PBoolean;
- // PBoolean is redefined by windows unit, so redefine it here again!
- {$ENDIF}
- TXsdTimezoneType = (
- tzUnknown,
- tzLocal,
- tzUtc
- );
- PXsdTimezone = ^TXsdTimezone;
- TXsdTimezone = record
- Kind : TXsdTimezoneType;
- Hour : Longint; // +/- [00..23]
- Minute : Longword; // [00..59]
- end;
- const
- TIMEZONE_UTC: TXsdTimezone = (Kind:tzUTC;Hour:0;Minute:0);
- { Format functions }
- function xsdFormatBase64(Value: TStream): AnsiString;
- function xsdFormatBoolean(Value: Boolean; UseWords: Boolean = False): AnsiString;
- function xsdFormatDate(Year, Month, Day: Longword; BC: Boolean; Timezone: PXsdTimezone = nil): AnsiString;
- function xsdFormatDate(Value: TDateTime; Timezone: PXsdTimezone = nil): AnsiString;
- function xsdFormatTime(Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil): AnsiString;
- function xsdFormatTime(Value: TDateTime; Timezone: PXsdTimezone = nil): AnsiString;
- function xsdFormatDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; BC: Boolean; Timezone: PXsdTimezone = nil): AnsiString;
- function xsdFormatDateTime(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
- function xsdFormatDecimal(Value: Extended; Precision: Integer = 4; Digits: Integer = 1): AnsiString;
- function xsdFormatDouble(Value: Double): AnsiString;
- function xsdFormatFloat(Value: Single): AnsiString;
- function xsdFormatByte(Value: Shortint): AnsiString;
- function xsdFormatShort(Value: Smallint): AnsiString;
- function xsdFormatInt(Value: Longint): AnsiString;
- function xsdFormatLong(Value: Int64): AnsiString;
- function xsdFormatUnsignedByte(Value: Byte): AnsiString;
- function xsdFormatUnsignedShort(Value: Word): AnsiString;
- function xsdFormatUnsignedInt(Value: Longword): AnsiString;
- function xsdFormatUnsignedLong(Value: QWord): AnsiString;
- function xsdFormatEnum(enum: array of AnsiString; Value: Integer): AnsiString;
- { DateTime functions }
- function xsdNowUTC: TDateTime;
- function xsdGetLocalTimezone: TXsdTimezone;
- function xsdTimezoneUtcOffsetMinutes(const Timezone: TXsdTimezone): Longint;
- function xsdDateTimeToUTC(const DateTime: TDateTime; const Current: TXsdTimezone): TDateTime;
- function xsdDateTimeConvert(const DateTime: TDateTime; const Current, Target: TXsdTimezone): TDateTime;
- { Parse functions }
- function xsdTryParseBase64(Chars: PChar; Len: Integer; const Value: TStream): Boolean;
- function xsdTryParseString(Chars: PChar; Len: Integer; out Value: AnsiString): Boolean;
- function xsdTryParseStringLower(Chars: PChar; Len: Integer; out Value: AnsiString): Boolean;
- function xsdTryParseBoolean(Chars: PChar; Len: Integer; out Value: Boolean): Boolean;
- function xsdTryParseDate(Chars: PChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
- function xsdTryParseDate(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseTime(Chars: PChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseDateTime(Chars: PChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
- function xsdTryParseDateTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseDecimal(Chars: PChar; Len: Integer; out Value: Extended): Boolean;
- function xsdTryParseDouble(Chars: PChar; Len: Integer; out Value: Double): Boolean;
- function xsdTryParseFloat(Chars: PChar; Len: Integer; out Value: Single): Boolean;
- function xsdTryParseInteger(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- function xsdTryParseNonNegativeInteger(Chars: PChar; Len: Integer; out Value: QWord): Boolean;
- function xsdTryParseNonPositiveInteger(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- function xsdTryParseNegativeInteger(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- function xsdTryParsePositiveInteger(Chars: PChar; Len: Integer; out Value: QWord): Boolean;
- function xsdTryParseByte(Chars: PChar; Len: Integer; out Value: Shortint): Boolean;
- function xsdTryParseShort(Chars: PChar; Len: Integer; out Value: Smallint): Boolean;
- function xsdTryParseInt(Chars: PChar; Len: Integer; out Value: Longint): Boolean;
- function xsdTryParseLong(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- function xsdTryParseUnsignedByte(Chars: PChar; Len: Integer; out Value: Byte): Boolean;
- function xsdTryParseUnsignedShort(Chars: PChar; Len: Integer; out Value: Word): Boolean;
- function xsdTryParseUnsignedInt(Chars: PChar; Len: Integer; out Value: Longword): Boolean;
- function xsdTryParseUnsignedLong(Chars: PChar; Len: Integer; out Value: QWord): Boolean;
- function xsdTryParseEnum(Chars: PChar; Len: Integer; enum: array of AnsiString; out Value: Integer): Boolean;
- function xsdParseStringDef(Chars: PChar; Len: Integer; Default: AnsiString): AnsiString;
- function xsdParseStringLowerDef(Chars: PChar; Len: Integer; Default: AnsiString): AnsiString;
- function xsdParseBooleanDef(Chars: PChar; Len: Integer; Default: Boolean): Boolean;
- function xsdParseDateDef(Chars: PChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseTimeDef(Chars: PChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDateTimeDef(Chars: PChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDecimalDef(Chars: PChar; Len: Integer; Default: Extended): Extended;
- function xsdParseDoubleDef(Chars: PChar; Len: Integer; Default: Double): Double;
- function xsdParseFloatDef(Chars: PChar; Len: Integer; Default: Single): Single;
- function xsdParseIntegerDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- function xsdParseNonNegativeIntegerDef(Chars: PChar; Len: Integer; Default: QWord): QWord;
- function xsdParseNonPositiveIntegerDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- function xsdParseNegativeIntegerDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- function xsdParsePositiveIntegerDef(Chars: PChar; Len: Integer; Default: QWord): QWord;
- function xsdParseByteDef(Chars: PChar; Len: Integer; Default: Shortint): Shortint;
- function xsdParseShortDef(Chars: PChar; Len: Integer; Default: Smallint): Smallint;
- function xsdParseIntDef(Chars: PChar; Len: Integer; Default: Longint): Longint;
- function xsdParseLongDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- function xsdParseUnsignedByteDef(Chars: PChar; Len: Integer; Default: Byte): Byte;
- function xsdParseUnsignedShortDef(Chars: PChar; Len: Integer; Default: Word): Word;
- function xsdParseUnsignedIntDef(Chars: PChar; Len: Integer; Default: Longword): Longword;
- function xsdParseUnsignedLongDef(Chars: PChar; Len: Integer; Default: QWord): QWord;
- function xsdParseEnumDef(Chars: PChar; Len: Integer; enum: array of AnsiString; Default: Integer): Integer;
- procedure xsdParseBase64(Chars: PChar; Len: Integer; const Value: TStream);
- procedure xsdParseString(Chars: PChar; Len: Integer; out Value: AnsiString);
- procedure xsdParseStringLower(Chars: PChar; Len: Integer; out Value: AnsiString);
- procedure xsdParseBoolean(Chars: PChar; Len: Integer; out Value: Boolean);
- procedure xsdParseDate(Chars: PChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
- procedure xsdParseDate(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil);
- procedure xsdParseTime(Chars: PChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil);
- procedure xsdParseTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil);
- procedure xsdParseDateTime(Chars: PChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
- procedure xsdParseDateTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil);
- procedure xsdParseDecimal(Chars: PChar; Len: Integer; out Value: Extended);
- procedure xsdParseDouble(Chars: PChar; Len: Integer; out Value: Double);
- procedure xsdParseFloat(Chars: PChar; Len: Integer; out Value: Single);
- procedure xsdParseInteger(Chars: PChar; Len: Integer; out Value: Int64);
- procedure xsdParseNonNegativeInteger(Chars: PChar; Len: Integer; out Value: QWord);
- procedure xsdParseNonPositiveInteger(Chars: PChar; Len: Integer; out Value: Int64);
- procedure xsdParseNegativeInteger(Chars: PChar; Len: Integer; out Value: Int64);
- procedure xsdParsePositiveInteger(Chars: PChar; Len: Integer; out Value: QWord);
- procedure xsdParseByte(Chars: PChar; Len: Integer; out Value: Shortint);
- procedure xsdParseShort(Chars: PChar; Len: Integer; out Value: Smallint);
- procedure xsdParseInt(Chars: PChar; Len: Integer; out Value: Longint);
- procedure xsdParseLong(Chars: PChar; Len: Integer; out Value: Int64);
- procedure xsdParseUnsignedByte(Chars: PChar; Len: Integer; out Value: Byte);
- procedure xsdParseUnsignedShort(Chars: PChar; Len: Integer; out Value: Word);
- procedure xsdParseUnsignedInt(Chars: PChar; Len: Integer; out Value: Longword);
- procedure xsdParseUnsignedLong(Chars: PChar; Len: Integer; out Value: QWord);
- procedure xsdParseEnum(Chars: PChar; Len: Integer; enum: array of AnsiString; out Value: Integer);
- function xsdParseString(Chars: PChar; Len: Integer): AnsiString;
- function xsdParseStringLower(Chars: PChar; Len: Integer): AnsiString;
- function xsdParseBoolean(Chars: PChar; Len: Integer): Boolean;
- function xsdParseDate(Chars: PChar; Len: Integer; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseTime(Chars: PChar; Len: Integer; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDateTime(Chars: PChar; Len: Integer; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDecimal(Chars: PChar; Len: Integer): Extended;
- function xsdParseDouble(Chars: PChar; Len: Integer): Double;
- function xsdParseFloat(Chars: PChar; Len: Integer): Single;
- function xsdParseInteger(Chars: PChar; Len: Integer): Int64;
- function xsdParseNonNegativeInteger(Chars: PChar; Len: Integer): QWord;
- function xsdParseNonPositiveInteger(Chars: PChar; Len: Integer): Int64;
- function xsdParseNegativeInteger(Chars: PChar; Len: Integer): Int64;
- function xsdParsePositiveInteger(Chars: PChar; Len: Integer): QWord;
- function xsdParseByte(Chars: PChar; Len: Integer): Shortint;
- function xsdParseShort(Chars: PChar; Len: Integer): Smallint;
- function xsdParseInt(Chars: PChar; Len: Integer): Longint;
- function xsdParseLong(Chars: PChar; Len: Integer): Int64;
- function xsdParseUnsignedByte(Chars: PChar; Len: Integer): Byte;
- function xsdParseUnsignedShort(Chars: PChar; Len: Integer): Word;
- function xsdParseUnsignedInt(Chars: PChar; Len: Integer): Longword;
- function xsdParseUnsignedLong(Chars: PChar; Len: Integer): QWord;
- function xsdParseEnum(Chars: PChar; Len: Integer; enum: array of AnsiString): Integer;
- {
- function xsdTryParseBase64(const S: AnsiString; const Value: TStream): Boolean;
- function xsdTryParseString(const S: AnsiString; out Value: AnsiString): Boolean;
- function xsdTryParseStringLower(const S: AnsiString; out Value: AnsiString): Boolean;
- function xsdTryParseBoolean(const S: AnsiString; out Value: Boolean): Boolean;
- function xsdTryParseDate(const S: AnsiString; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
- function xsdTryParseDate(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseTime(const S: AnsiString; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseDateTime(const S: AnsiString; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
- function xsdTryParseDateTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
- function xsdTryParseDecimal(const S: AnsiString; out Value: Extended): Boolean;
- function xsdTryParseDouble(const S: AnsiString; out Value: Double): Boolean;
- function xsdTryParseFloat(const S: AnsiString; out Value: Single): Boolean;
- function xsdTryParseInteger(const S: AnsiString; out Value: Int64): Boolean;
- function xsdTryParseNonNegativeInteger(const S: AnsiString; out Value: QWord): Boolean;
- function xsdTryParseNonPositiveInteger(const S: AnsiString; out Value: Int64): Boolean;
- function xsdTryParseNegativeInteger(const S: AnsiString; out Value: Int64): Boolean;
- function xsdTryParsePositiveInteger(const S: AnsiString; out Value: QWord): Boolean;
- function xsdTryParseByte(const S: AnsiString; out Value: Shortint): Boolean;
- function xsdTryParseShort(const S: AnsiString; out Value: Smallint): Boolean;
- function xsdTryParseInt(const S: AnsiString; out Value: Longint): Boolean;
- function xsdTryParseLong(const S: AnsiString; out Value: Int64): Boolean;
- function xsdTryParseUnsignedByte(const S: AnsiString; out Value: Byte): Boolean;
- function xsdTryParseUnsignedShort(const S: AnsiString; out Value: Word): Boolean;
- function xsdTryParseUnsignedInt(const S: AnsiString; out Value: Longword): Boolean;
- function xsdTryParseUnsignedLong(const S: AnsiString; out Value: QWord): Boolean;
- function xsdTryParseEnum(const S: AnsiString; enum: array of AnsiString; out Value: Integer): Boolean;
- function xsdParseStringDef(const S: AnsiString; Default: AnsiString): AnsiString;
- function xsdParseStringLowerDef(const S: AnsiString; Default: AnsiString): AnsiString;
- function xsdParseBooleanDef(const S: AnsiString; Default: Boolean): Boolean;
- function xsdParseDateDef(const S: AnsiString; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseTimeDef(const S: AnsiString; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDateTimeDef(const S: AnsiString; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDecimalDef(const S: AnsiString; Default: Extended): Extended;
- function xsdParseDoubleDef(const S: AnsiString; Default: Double): Double;
- function xsdParseFloatDef(const S: AnsiString; Default: Single): Single;
- function xsdParseIntegerDef(const S: AnsiString; Default: Int64): Int64;
- function xsdParseNonNegativeIntegerDef(const S: AnsiString; Default: QWord): QWord;
- function xsdParseNonPositiveIntegerDef(const S: AnsiString; Default: Int64): Int64;
- function xsdParseNegativeIntegerDef(const S: AnsiString; Default: Int64): Int64;
- function xsdParsePositiveIntegerDef(const S: AnsiString; Default: QWord): QWord;
- function xsdParseByteDef(const S: AnsiString; Default: Shortint): Shortint;
- function xsdParseShortDef(const S: AnsiString; Default: Smallint): Smallint;
- function xsdParseIntDef(const S: AnsiString; Default: Longint): Longint;
- function xsdParseLongDef(const S: AnsiString; Default: Int64): Int64;
- function xsdParseUnsignedByteDef(const S: AnsiString; Default: Byte): Byte;
- function xsdParseUnsignedShortDef(const S: AnsiString; Default: Word): Word;
- function xsdParseUnsignedIntDef(const S: AnsiString; Default: Longword): Longword;
- function xsdParseUnsignedLongDef(const S: AnsiString; Default: QWord): QWord;
- function xsdParseEnumDef(const S: AnsiString; enum: array of AnsiString; Default: Integer): Integer;
- }
- procedure xsdParseBase64(const S: AnsiString; const Value: TStream);
- procedure xsdParseString(const S: AnsiString; out Value: AnsiString);
- procedure xsdParseStringLower(const S: AnsiString; out Value: AnsiString);
- procedure xsdParseBoolean(const S: AnsiString; out Value: Boolean);
- procedure xsdParseDate(const S: AnsiString; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
- procedure xsdParseDate(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil);
- procedure xsdParseTime(const S: AnsiString; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil);
- procedure xsdParseTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil);
- procedure xsdParseDateTime(const S: AnsiString; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
- procedure xsdParseDateTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil);
- procedure xsdParseDecimal(const S: AnsiString; out Value: Extended);
- procedure xsdParseDouble(const S: AnsiString; out Value: Double);
- procedure xsdParseFloat(const S: AnsiString; out Value: Single);
- procedure xsdParseInteger(const S: AnsiString; out Value: Int64);
- procedure xsdParseNonNegativeInteger(const S: AnsiString; out Value: QWord);
- procedure xsdParseNonPositiveInteger(const S: AnsiString; out Value: Int64);
- procedure xsdParseNegativeInteger(const S: AnsiString; out Value: Int64);
- procedure xsdParsePositiveInteger(const S: AnsiString; out Value: QWord);
- procedure xsdParseByte(const S: AnsiString; out Value: Shortint);
- procedure xsdParseShort(const S: AnsiString; out Value: Smallint);
- procedure xsdParseInt(const S: AnsiString; out Value: Longint);
- procedure xsdParseLong(const S: AnsiString; out Value: Int64);
- procedure xsdParseUnsignedByte(const S: AnsiString; out Value: Byte);
- procedure xsdParseUnsignedShort(const S: AnsiString; out Value: Word);
- procedure xsdParseUnsignedInt(const S: AnsiString; out Value: Longword);
- procedure xsdParseUnsignedLong(const S: AnsiString; out Value: QWord);
- procedure xsdParseEnum(const S: AnsiString; enum: array of AnsiString; out Value: Integer);
- function xsdParseString(const S: AnsiString): AnsiString;
- function xsdParseStringLower(const S: AnsiString): AnsiString;
- function xsdParseBoolean(const S: AnsiString): Boolean;
- function xsdParseDate(const S: AnsiString; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseTime(const S: AnsiString; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDateTime(const S: AnsiString; Timezone: PXsdTimezone = nil): TDateTime;
- function xsdParseDecimal(const S: AnsiString): Extended;
- function xsdParseDouble(const S: AnsiString): Double;
- function xsdParseFloat(const S: AnsiString): Single;
- function xsdParseInteger(const S: AnsiString): Int64;
- function xsdParseNonNegativeInteger(const S: AnsiString): QWord;
- function xsdParseNonPositiveInteger(const S: AnsiString): Int64;
- function xsdParseNegativeInteger(const S: AnsiString): Int64;
- function xsdParsePositiveInteger(const S: AnsiString): QWord;
- function xsdParseByte(const S: AnsiString): Shortint;
- function xsdParseShort(const S: AnsiString): Smallint;
- function xsdParseInt(const S: AnsiString): Longint;
- function xsdParseLong(const S: AnsiString): Int64;
- function xsdParseUnsignedByte(const S: AnsiString): Byte;
- function xsdParseUnsignedShort(const S: AnsiString): Word;
- function xsdParseUnsignedInt(const S: AnsiString): Longword;
- function xsdParseUnsignedLong(const S: AnsiString): QWord;
- function xsdParseEnum(const S: AnsiString; enum: array of AnsiString): Integer;
- { INTERNAL HELPERS!!! }
- const
- XSD_IGNORE_LAST = Pointer(-1); // maybe used as L parameter if the string is zero terminated
- function __parseNonNegativeInteger(var P: PChar; const L: PChar; out Value: QWord): Boolean;
- function __parseInteger(var P: PChar; const L: PChar; out Value: Int64): Boolean;
- function __parseFloat(var P: PChar; const L: PChar; out Value: Extended): Boolean;
- function __parseTimezone(var P: PChar; const L: PChar; out T: TXsdTimezone): Boolean;
- function __parseDate(var P: PChar; const L: PChar; out Year, Month, Day: Longword; BC: PBoolean): Boolean;
- function __parseTime(var P: PChar; const L: PChar; const AllowMoreThan24h: Boolean;
- out Hour, Minute, Second, Milliseconds: Longword): Boolean;
- function __strpas(Chars: PChar; Len: Integer): AnsiString;
- implementation
- function xsdFormatBase64(Value: TStream): AnsiString;
- const
- Base64: array[0..63] of char = (
- 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
- 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
- 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
- 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
- );
- BufferSize = 3*512; { buffer size must be a multiple of 3 }
- var
- Buffer: array[0..BufferSize-1] of Byte;
- Num, Ofs: Integer;
- b1, b2, b3: Byte;
- begin
- Result := '';
- while True do
- begin
- Num := Value.Read(Buffer, BufferSize);
- if Num = 0 then
- Exit;
- Ofs := 0;
- while Num >= 3 do
- begin
- b1 := Buffer[Ofs];
- b2 := Buffer[Ofs+1];
- b3 := Buffer[Ofs+2];
- Result := Result +
- Base64[b1 shr 2] +
- Base64[((b1 and $3) shl 4) or (b2 shr 4)] +
- Base64[((b2 and $F) shl 2) or (b3 shr 6)] +
- Base64[b3 and $3F];
- Num := Num - 3;
- Ofs := Ofs + 3;
- end;
- case Num of
- 1: begin
- b1 := Buffer[Ofs];
- Result := Result +
- Base64[b1 shr 2] +
- Base64[((b1 and $3) shl 4)] +
- '==';
- Exit;
- end;
- 2: begin
- b1 := Buffer[Ofs];
- b2 := Buffer[Ofs+1];
- Result := Result +
- Base64[b1 shr 2] +
- Base64[((b1 and $3) shl 4) or (b2 shr 4)] +
- Base64[((b2 and $F) shl 2)] +
- '=';
- Exit;
- end;
- end;
- end;
- end;
- function xsdFormatBoolean(Value: Boolean; UseWords: Boolean): AnsiString;
- begin
- if UseWords then
- if Value then
- Result := 'true'
- else
- Result := 'false'
- else
- if Value then
- Result := '1'
- else
- Result := '0';
- end;
- function xsdFormatDate(Year, Month, Day: Longword; BC: Boolean; Timezone: PXsdTimezone): AnsiString;
- begin
- Result := Format('%4.4d-%2.2u-%2.2u', [Year, Month, Day]);
- if BC then
- Result := '-' + Result;
- if Assigned(Timezone) then
- case Timezone^.Kind of
- tzUTC:
- Result := Result + 'Z';
- tzLOCAL:
- begin
- if Timezone^.Hour >= 0 then
- Result := Result + '+'
- else
- Result := Result + '-';
- Result := Result + Format('%2.2d:%2.2u', [Timezone^.Hour, Timezone^.Minute]);
- end;
- end;
- end;
- function xsdFormatDate(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
- var
- Year, Month, Day: Word;
- begin
- DecodeDate(Value, Year, Month, Day);
- Result := xsdFormatDate(Year, Month, Day, False, Timezone);
- end;
- function xsdFormatTime(Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone): AnsiString;
- begin
- Result := Format('%2.2u:%2.2u:%2.2u', [Hour, Minute, Second]);
- if Milliseconds > 0 then
- Result := Result + '.' + IntToStr(Milliseconds);
- if Assigned(Timezone) then
- case Timezone^.Kind of
- tzUTC:
- Result := Result + 'Z';
- tzLOCAL:
- begin
- if Timezone^.Hour >= 0 then
- Result := Result + '+'
- else
- Result := Result + '-';
- Result := Result + Format('%2.2d:%2.2u', [Timezone^.Hour, Timezone^.Minute]);
- end;
- end;
- end;
- function xsdFormatTime(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
- var
- Hour, Minute, Second, Milliseconds: Word;
- begin
- DecodeTime(Value, Hour, Minute, Second, Milliseconds);
- Result := xsdFormatTime(Hour, Minute, Second, Milliseconds, Timezone);
- end;
- function xsdFormatDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; BC: Boolean; Timezone: PXsdTimezone): AnsiString;
- begin
- Result := xsdFormatDate(Year, Month, Day, BC, nil) + 'T' + xsdFormatTime(Hour, Minute, Second, Milliseconds, Timezone);
- end;
- function xsdFormatDateTime(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
- var
- Year, Month, Day, Hour, Minute, Second, Milliseconds: Word;
- begin
- DecodeDateTime(Value, Year, Month, Day, Hour, Minute, Second, Milliseconds);
- Result := xsdFormatDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds, False, Timezone);
- end;
- function xsdFormatDecimal(Value: Extended; Precision: Integer; Digits: Integer): AnsiString;
- begin
- Result := FloatToStrF(Value, ffFixed, Precision, Digits);
- end;
- function xsdFormatDouble(Value: Double): AnsiString;
- begin
- Result := FloatToStr(Value);
- end;
- function xsdFormatFloat(Value: Single): AnsiString;
- begin
- Result := FloatToStr(Value);
- end;
- function xsdFormatByte(Value: Shortint): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatShort(Value: Smallint): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatInt(Value: Integer): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatLong(Value: Int64): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedByte(Value: Byte): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedShort(Value: Word): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedInt(Value: Longword): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedLong(Value: QWord): AnsiString;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatEnum(enum: array of AnsiString; Value: Integer): AnsiString;
- begin
- Result := enum[Value];
- end;
- function xsdNowUTC: TDateTime;
- begin
- Result := xsdDateTimeToUTC(Now, xsdGetLocalTimezone);
- end;
- function xsdGetLocalTimezone: TXsdTimezone;
- var
- Offset: Integer;
- {$IFDEF MSWINDOWS}
- TZInfo: TTimeZoneInformation;
- {$ENDIF}
- begin
- Result.Kind := tzLOCAL;
- {$IFDEF UNIX}
- Offset := Tzseconds div 60;
- {$ENDIF}
- {$IFDEF MSWINDOWS}
- case GetTimeZoneInformation(TZInfo) of
- 1: Offset := -TZInfo.Bias - TZInfo.StandardBias;
- 2: Offset := -TZInfo.Bias - TZInfo.DaylightBias;
- else Result.Kind := tzUnknown;
- end;
- {$ENDIF}
- Result.Hour := Offset div 60;
- Result.Minute := abs(Offset) mod 60;
- end;
- function xsdTimezoneUtcOffsetMinutes(const Timezone: TXsdTimezone): Longint;
- begin
- case Timezone.Kind of
- tzUTC: Result := 0;
- tzLOCAL : Result := 60*Timezone.Hour + Timezone.Minute;
- else raise Exception.Create('can''t get offset of unknown timezone');
- end;
- end;
- function xsdDateTimeToUTC(const DateTime: TDateTime; const Current: TXsdTimezone): TDateTime;
- begin
- Result := xsdDateTimeConvert(DateTime, Current, TIMEZONE_UTC);
- end;
- function xsdDateTimeConvert(const DateTime: TDateTime; const Current, Target: TXsdTimezone): TDateTime;
- begin
- Result := IncMinute(DateTime, xsdTimezoneUtcOffsetMinutes(Target) - xsdTimezoneUtcOffsetMinutes(Current));
- end;
- function __parseNonNegativeInteger(var P: PChar; const L: PChar; out Value: QWord): Boolean;
- begin
- { expect integer }
- Value := 0;
- while (P < L) and (P^ in ['0'..'9']) do
- begin
- Value := 10*Value + Ord(P^) - Ord('0');
- Inc(P);
- end;
- Result := True;
- end;
- function __parseInteger(var P: PChar; const L: PChar; out Value: Int64): Boolean;
- var
- N: Boolean;
- begin
- { allow '-' }
- N := (P < L) and (P^ = '-');
- if N then
- Inc(P);
- { expect integer }
- Value := 0;
- while (P < L) and (P^ in ['0'..'9']) do
- begin
- Value := 10*Value + Ord(P^) - Ord('0');
- Inc(P);
- end;
- if N then
- Value := -Value;
- Result := True;
- end;
- function __parseFloat(var P: PChar; const L: PChar; out Value: Extended): Boolean;
- var
- N: Boolean;
- Exp: Int64;
- Int: QWord;
- begin
- { allow 'Nan' }
- if (P+2 < L) and ((P^ = 'N') or (P^ = 'n')) then
- begin
- Inc(P);
- if (P^ <> 'A') and (P^ <> 'a') then Exit(False);
- Inc(P);
- if (P^ <> 'N') and (P^ <> 'n') then Exit(False);
- Inc(P);
- Value := Nan;
- Result := True;
- Exit;
- end;
- { allow '-' }
- N := (P < L) and (P^ = '-');
- if N then
- Inc(P);
- { allow 'Inf' }
- if (P+2 < L) and ((P^ = 'I') or (P^ = 'i')) then
- begin
- Inc(P);
- if (P^ <> 'N') and (P^ <> 'n') then Exit(False);
- Inc(P);
- if (P^ <> 'F') and (P^ <> 'f') then Exit(False);
- Inc(P);
- if N then
- Value := NegInfinity
- else
- Value := Infinity;
- Result := True;
- Exit;
- end;
- { expect integer }
- Int := 0;
- while (P < L) and (P^ in ['0'..'9']) do
- begin
- Int := 10*Int + Ord(P^) - Ord('0');
- Inc(P);
- end;
- Value := Int;
- { allow '.' }
- if (P < L) and (P^ = '.') then
- begin
- Inc(P);
- { expect integer }
- Exp := 1;
- Int := 0;
- while (P < L) and (P^ in ['0'..'9']) do
- begin
- Int := 10*Int + Ord(P^) - Ord('0');
- Exp := 10*Exp;
- Inc(P);
- end;
- Value := Value + Int / Exp;
- end;
- { allow 'E' or 'e' }
- if (P < L) and ((P^ = 'E') or (P^ = 'e')) then
- begin
- Inc(P);
- { expect integer }
- if not __parseInteger(P, L, Exp) then
- Exit(False);
- while Exp > 0 do
- begin
- Value := Value * 10;
- Dec(Exp);
- end;
- while Exp < 0 do
- begin
- Value := Value * 0.1;
- Inc(Exp);
- end;
- end;
- if N then
- Value := -Value;
- Result := True;
- end;
- function __parseTimezone(var P: PChar; const L: PChar; out T: TXsdTimezone): Boolean;
- var
- I: Integer;
- N: Boolean;
- begin
- { allow 'Z' }
- if (P < L) and (P^ = 'Z') then
- begin
- T.Kind := tzUTC;
- T.Hour := 0;
- T.Minute := 0;
- Inc(P);
- end else
- { allow '+' or '-' }
- if (P < L) and (P^ in ['+','-']) then
- begin
- T.Kind := tzLOCAL;
- N := P^ = '-';
- Inc(P);
- { expect 00..13 }
- T.Hour := 0; I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- T.Hour := 10*T.Hour + Ord(P^) - Ord('0');
- Dec(I); Inc(P);
- end;
- if T.Hour > 13 then
- Exit(False);
- if N then
- T.Hour := -T.Hour;
- { expect ':' }
- if (P >= L) or (P^ <> ':') then
- Exit(False);
- Inc(P);
- { expect 00..59 }
- T.Minute := 0; I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- T.Minute := 10*T.Minute + Ord(P^) - Ord('0');
- Dec(I); Inc(P);
- end;
- if T.Minute > 59 then
- Exit(False);
- end else
- { unknown }
- begin
- T.Kind := tzUNKNOWN;
- T.Hour := 0;
- T.Minute := 0;
- end;
- Result := True;
- end;
- function __parseDate(var P: PChar; const L: PChar; out Year, Month, Day: Longword; BC: PBoolean): Boolean;
- var
- I: Integer;
- begin
- { allow '-' }
- if (P < L) and (P^ = '-') then
- begin
- if Assigned(BC) then
- BC^ := True
- else
- Exit(False);
- Inc(P);
- end else
- if Assigned(BC) then
- BC^ := False;
- { expect Integer }
- Year := 0;
- while (P < L) and (P^ in ['0'..'9']) do
- begin
- Year := 10*Year + Ord(P^) - Ord('0');
- Inc(P);
- end;
- { expect '-' }
- if (P >= L) or (P^ <> '-') then
- Exit(False);
- Inc(P);
- { expect 01..12 }
- Month := 0; I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- Month := 10*Month + Ord(P^) - Ord('0');
- Dec(I); Inc(P);
- end;
- if (Month < 1) or (Month > 12) then
- Exit(False);
- { expect '-' }
- if (P >= L) or (P^ <> '-') then
- Exit(False);
- Inc(P);
- { expect 01..31 }
- Day := 0; I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- Day := 10*Day + Ord(P^) - Ord('0');
- Dec(I); Inc(P);
- end;
- if (Day < 1) or (Day > 31) then
- Exit(False);
- Result := True;
- end;
- function __parseTime(var P: PChar; const L: PChar; const AllowMoreThan24h: Boolean;
- out Hour, Minute, Second, Milliseconds: Longword): Boolean;
- var
- I: Integer;
- Ms: Longword;
- begin
- { expect 00..24 (except if AllowMoreThan24h) }
- Hour := 0;
- if AllowMoreThan24h then I := 9 { maximal 9 digits for hour } else I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- Hour := 10*Hour + Ord(P^) - Ord('0');
- Inc(P); Dec(I);
- end;
- if not AllowMoreThan24h and (Hour > 24) then
- Exit(False);
- { expect ':' }
- if (P >= L) or (P^ <> ':') then
- Exit(False);
- Inc(P);
- { expect 00..59 }
- Minute := 0; I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- Minute := 10*Minute + Ord(P^) - Ord('0');
- Dec(I); Inc(P);
- end;
- if (Minute > 59) or (not AllowMoreThan24h and (Hour = 24) and (Minute > 0)) then
- Exit(False);
- { expect ':' }
- if (P >= L) or (P^ <> ':') then
- Exit(False);
- Inc(P);
- { expect 00..59 }
- Second := 0; I := 2;
- while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
- begin
- Second := 10*Second + Ord(P^) - Ord('0');
- Dec(I); Inc(P);
- end;
- if (Second > 59) or (not AllowMoreThan24h and (Hour = 24) and (Second > 0)) then
- Exit(False);
- { allow '.' }
- if (P < L) and (P^ = '.') then
- begin
- Inc(P);
- { expect integer }
- Ms := 0; I := 1;
- while (P < L) and (P^ in ['0'..'9']) do
- begin
- Ms := 10*Ms + Ord(P^) - Ord('0');
- I := 10*I;
- Inc(P);
- end;
- Milliseconds := (1000*Ms) div I;
- if (Milliseconds >= 999) or (not AllowMoreThan24h and (Hour = 24) and (Milliseconds > 0)) then
- Exit(False);
- end else
- Milliseconds := 0;
- Result := True;
- end;
- function xsdTryParseBase64(Chars: PChar; Len: Integer; const Value: TStream): Boolean;
- const
- BufferSize = 3*512;
- var
- Buffer: array[0..BufferSize-1] of Byte;
- Ofs: Integer;
- P,L: PByte;
- p1,p2,p3,p4: Shortint;
- begin
- if Assigned(Chars) then
- begin
- Ofs := 0;
- P := PByte(Chars);
- if Len >= 0 then
- begin
- if Len mod 4 <> 0 then
- Exit(False);
- L := P + Len;
- while P < L do
- begin
- case Chr(P^) of
- 'A'..'Z': p1 := P^ - Ord('A');
- 'a'..'z': p1 := P^ - Ord('a') + 26;
- '0'..'9': p1 := P^ - Ord('0') + 52;
- '+' : p1 := 62;
- '/' : p1 := 63;
- else Exit(False);
- end;
- Inc(P);
- case Chr(P^) of
- 'A'..'Z': p2 := P^ - Ord('A');
- 'a'..'z': p2 := P^ - Ord('a') + 26;
- '0'..'9': p2 := P^ - Ord('0') + 52;
- '+' : p2 := 62;
- '/' : p2 := 63;
- else Exit(False);
- end;
- Inc(P);
- case Chr(P^) of
- 'A'..'Z': p3 := P^ - Ord('A');
- 'a'..'z': p3 := P^ - Ord('a') + 26;
- '0'..'9': p3 := P^ - Ord('0') + 52;
- '+' : p3 := 62;
- '/' : p3 := 63;
- '=' : p3 := -1;
- else Exit(False);
- end;
- Inc(P);
- if (p3 >= 0) then
- begin
- case Chr(P^) of
- 'A'..'Z': p4 := P^ - Ord('A');
- 'a'..'z': p4 := P^ - Ord('a') + 26;
- '0'..'9': p4 := P^ - Ord('0') + 52;
- '+' : p4 := 62;
- '/' : p4 := 63;
- '=' : p4 := -1;
- else Exit(False);
- end;
- end else begin
- if P^ <> Ord('=') then
- Exit(False);
- p4 := -1;
- end;
- Inc(P);
- Buffer[Ofs] := (p1 shl 2) or (p2 shr 4);
- Ofs := Ofs + 1;
- if p3 >= 0 then
- begin
- Buffer[Ofs] := ((p2 and $F) shl 4) or (p3 shr 2);
- Ofs := Ofs + 1;
- if p4 >= 0 then
- begin
- Buffer[Ofs] := ((p3 and $3) shl 6) or p4;
- Ofs := Ofs + 1;
- end;
- end;
- if Ofs >= BufferSize-2 then
- begin
- Value.Write(Buffer, Ofs);
- Ofs := 0;
- end;
- end;
- end else begin
- while P^ <> 0 do
- begin
- case Chr(P^) of
- 'A'..'Z': p1 := P^ - Ord('A');
- 'a'..'z': p1 := P^ - Ord('a') + 26;
- '0'..'9': p1 := P^ - Ord('0') + 52;
- '+' : p1 := 62;
- '/' : p1 := 63;
- else Exit(False);
- end;
- Inc(P);
- case Chr(P^) of
- 'A'..'Z': p2 := P^ - Ord('A');
- 'a'..'z': p2 := P^ - Ord('a') + 26;
- '0'..'9': p2 := P^ - Ord('0') + 52;
- '+' : p2 := 62;
- '/' : p2 := 63;
- else Exit(False);
- end;
- Inc(P);
- case Chr(P^) of
- 'A'..'Z': p3 := P^ - Ord('A');
- 'a'..'z': p3 := P^ - Ord('a') + 26;
- '0'..'9': p3 := P^ - Ord('0') + 52;
- '+' : p3 := 62;
- '/' : p3 := 63;
- '=' : p3 := -1;
- else Exit(False);
- end;
- Inc(P);
- if (p3 >= 0) then
- begin
- case Chr(P^) of
- 'A'..'Z': p4 := P^ - Ord('A');
- 'a'..'z': p4 := P^ - Ord('a') + 26;
- '0'..'9': p4 := P^ - Ord('0') + 52;
- '+' : p4 := 62;
- '/' : p4 := 63;
- '=' : p4 := -1;
- else Exit(False);
- end;
- end else begin
- if P^ <> Ord('=') then
- Exit(False);
- p4 := -1;
- end;
- Inc(P);
- Buffer[Ofs] := (p1 shl 2) or (p2 shr 4);
- Ofs := Ofs + 1;
- if p3 >= 0 then
- begin
- Buffer[Ofs] := ((p2 and $F) shl 4) or (p3 shr 2);
- Ofs := Ofs + 1;
- if p4 >= 0 then
- begin
- Buffer[Ofs] := ((p3 and $3) shl 6) or p4;
- Ofs := Ofs + 1;
- end;
- end;
- if Ofs >= BufferSize-2 then
- begin
- Value.Write(Buffer, Ofs);
- Ofs := 0;
- end;
- end;
- end;
- if Ofs > 0 then // flush
- Value.Write(Buffer, Ofs);
- Result := True;
- end else
- Result := False;
- end;
- function xsdTryParseString(Chars: PChar; Len: Integer; out Value: AnsiString): Boolean;
- const
- AllocChars = 256;
- var
- P,L,D: PByte;
- begin
- if Assigned(Chars) then
- begin
- P := PByte(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- SetLength(Value, Len);
- D := @Value[1];
- while P < L do
- begin
- D^ := P^;
- Inc(D);
- Inc(P);
- end;
- end else begin
- SetLength(Value, AllocChars);
- D := @Value[1];
- L := D + AllocChars;
- while P^ <> 0 do
- begin
- if D = L then
- begin
- Len := Length(Value);
- SetLength(Value, Len+AllocChars);
- D := @Value[Len+1];
- L := D + AllocChars;
- end;
- D^ := P^;
- Inc(D);
- Inc(P);
- end;
- SetLength(Value, P-PByte(Chars));
- end;
- Result := True;
- end else
- Result := False;
- end;
- {begin
- if Assigned(Chars) then
- begin
- if Len >= 0 then
- begin
- SetLength(Value, Len);
- Move(Chars^, Value[1], Len);
- end else
- Value := PChar(Chars);
- Result := True;
- end else
- Result := False;
- end;}
- function xsdTryParseStringLower(Chars: PChar; Len: Integer; out Value: AnsiString): Boolean;
- const
- AllocChars = 256;
- var
- P,L,D: PByte;
- C: Byte;
- begin
- if Assigned(Chars) then
- begin
- P := PByte(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- SetLength(Value, Len);
- D := @Value[1];
- while P < L do
- begin
- C := P^;
- if (C>=65) and (C<=90) then Inc(C, 32);
- D^ := C;
- Inc(D);
- Inc(P);
- end;
- end else begin
- SetLength(Value, AllocChars);
- D := @Value[1];
- L := D + AllocChars;
- while P^ <> 0 do
- begin
- C := P^;
- if (C>=65) and (C<=90) then Inc(C, 32);
- if D = L then
- begin
- Len := Length(Value);
- SetLength(Value, Len+AllocChars);
- D := @Value[Len+1];
- L := D + AllocChars;
- end;
- D^ := C;
- Inc(D);
- Inc(P);
- end;
- SetLength(Value, P-PByte(Chars));
- end;
- Result := True;
- end else
- Result := False;
- end;
- function __strpas(Chars: PChar; Len: Integer): AnsiString;
- begin
- if not xsdTryParseString(Chars, Len, Result) then
- Result := '';
- end;
- function xsdTryParseBoolean(Chars: PChar; Len: Integer; out Value: Boolean): Boolean;
- var
- P: PChar;
- Num: QWord;
- begin
- if not Assigned(Chars) then
- Exit(False);
- if Len < 0 then
- begin
- P := PChar(Chars);
- Len := 0;
- while (Len < 7) and (P^ <> #0) do
- begin
- Inc(Len);
- Inc(P);
- end;
- end;
- case Len of
- 1: Num := PByte(Chars)^;
- 4: Num := PLongword(Chars)^;
- 5: Num := PLongword(Chars)^ or (QWord(Chars[4]) shl 32);
- else Exit(False);
- end;
- case Num of
- $30,
- $65736C6166,$65736C6146,$65736C4166,$65736C4146,$65734C6166,$65734C6146,$65734C4166,$65734C4146,
- $65536C6166,$65536C6146,$65536C4166,$65536C4146,$65534C6166,$65534C6146,$65534C4166,$65534C4146,
- $45736C6166,$45736C6146,$45736C4166,$45736C4146,$45734C6166,$45734C6146,$45734C4166,$45734C4146,
- $45536C6166,$45536C6146,$45536C4166,$45536C4146,$45534C6166,$45534C6146,$45534C4166,$45534C4146:
- Value := False;
- $31,
- $65757274,$65757254,$65755274,$65755254,$65557274,$65557254,$65555274,$65555254,
- $45757274,$45757254,$45755274,$45755254,$45557274,$45557254,$45555274,$45555254:
- Value := True;
- else Exit(False);
- end;
- Result := True;
- end;
- function xsdTryParseDate(Chars: PChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone; BC: PBoolean): Boolean;
- var
- P: PChar;
- L: PChar;
- T: TXsdTimezone;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and
- __parseDate(P, L, Year, Month, Day, BC) and
- __parseTimezone(P, L, T) and (P = L)
- end else
- Result := Assigned(P) and
- __parseDate(P, XSD_IGNORE_LAST, Year, Month, Day, BC) and
- __parseTimezone(P, XSD_IGNORE_LAST, T) and (P^ = #0);
- { assign Timezone if requested }
- if Result and Assigned(Timezone) then
- Timezone^ := T;
- end;
- function xsdTryParseDate(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone): Boolean;
- var
- Year, Month, Day: Longword;
- begin
- if xsdTryParseDate(Chars, Len, Year, Month, Day, Timezone, nil) then
- Result := TryEncodeDate(Year, Month, Day, Value)
- else
- Result := False;
- end;
- function xsdTryParseTime(Chars: PChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone): Boolean;
- var
- P: PChar;
- L: PChar;
- T: TXsdTimezone;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and
- __parseTime(P, L, False, Hour, Minute, Second, Milliseconds) and
- __parseTimezone(P, L, T) and (P = L)
- end else
- Result := Assigned(P) and
- __parseTime(P, XSD_IGNORE_LAST, False, Hour, Minute, Second, Milliseconds) and
- __parseTimezone(P, XSD_IGNORE_LAST, T) and (P^ = #0);
- { assign Timezone if requested }
- if Result and Assigned(Timezone) then
- Timezone^ := T;
- end;
- function xsdTryParseTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone): Boolean;
- var
- Hour, Minute, Second, Milliseconds: Longword;
- begin
- if xsdTryParseTime(Chars, Len, Hour, Minute, Second, Milliseconds, Timezone) then
- Result := TryEncodeTime(Hour, Minute, Second, Milliseconds, Value)
- else
- Result := False;
- end;
- function xsdTryParseDateTime(Chars: PChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean): Boolean;
- function __parseT(var P: PChar; const L: PChar): Boolean;
- begin
- Result := (P < L) and (P^ = 'T');
- if Result then Inc(P);
- end;
- var
- P: PChar;
- L: PChar;
- T: TXsdTimezone;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and
- __parseDate(P, L, Year, Month, Day, BC) and
- __parseT(P, L) and
- __parseTime(P, L, False, Hour, Minute, Second, Milliseconds) and
- __parseTimezone(P, L, T) and (P = L)
- end else
- Result := Assigned(P) and
- __parseDate(P, XSD_IGNORE_LAST, Year, Month, Day, BC) and
- __parseT(P, XSD_IGNORE_LAST) and
- __parseTime(P, XSD_IGNORE_LAST, False, Hour, Minute, Second, Milliseconds) and
- __parseTimezone(P, XSD_IGNORE_LAST, T) and (P^ = #0);
- { assign Timezone if requested }
- if Result and Assigned(Timezone) then
- Timezone^ := T;
- end;
- function xsdTryParseDateTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone): Boolean;
- var
- Year, Month, Day: Longword;
- Hour, Minute, Second, Milliseconds: Longword;
- begin
- if xsdTryParseDateTime(Chars, Len, Year, Month, Day, Hour, Minute, Second, Milliseconds, Timezone) then
- Result := TryEncodeDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds, Value)
- else
- Result := False;
- end;
- function xsdTryParseDecimal(Chars: PChar; Len: Integer; out Value: Extended): Boolean;
- var
- P: PChar;
- L: PChar;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and __parseFloat(P, L, Value) and (P = L)
- end else
- Result := Assigned(P) and __parseFloat(P, XSD_IGNORE_LAST, Value) and (P^ = #0);
- end;
- function xsdTryParseDouble(Chars: PChar; Len: Integer; out Value: Double): Boolean;
- var
- P: PChar;
- L: PChar;
- Tmp: Extended;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and __parseFloat(P, L, Tmp) and (P = L)
- end else
- Result := Assigned(P) and __parseFloat(P, XSD_IGNORE_LAST, Tmp) and (P^ = #0);
- Value := Tmp;
- end;
- function xsdTryParseFloat(Chars: PChar; Len: Integer; out Value: Single): Boolean;
- var
- P: PChar;
- L: PChar;
- Tmp: Extended;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and __parseFloat(P, L, Tmp) and (P = L)
- end else
- Result := Assigned(P) and __parseFloat(P, XSD_IGNORE_LAST, Tmp) and (P^ = #0);
- Value := Tmp;
- end;
- function xsdTryParseInteger(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- var
- P: PChar;
- L: PChar;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and __parseInteger(P, L, Value) and (P = L)
- end else
- Result := Assigned(P) and __parseInteger(P, XSD_IGNORE_LAST, Value) and (P^ = #0);
- end;
- function xsdTryParseNonNegativeInteger(Chars: PChar; Len: Integer; out Value: QWord): Boolean;
- var
- P: PChar;
- L: PChar;
- begin
- P := PChar(Chars);
- if Len >= 0 then
- begin
- L := P + Len;
- Result := Assigned(P) and __parseNonNegativeInteger(P, L, Value) and (P = L)
- end else
- Result := Assigned(P) and __parseNonNegativeInteger(P, XSD_IGNORE_LAST, Value) and (P^ = #0);
- end;
- function xsdTryParseNonPositiveInteger(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- begin
- Result := xsdTryParseInteger(Chars, Len, Value) and (Value <= 0);
- end;
- function xsdTryParseNegativeInteger(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- begin
- Result := xsdTryParseInteger(Chars, Len, Value) and (Value <= -1);
- end;
- function xsdTryParsePositiveInteger(Chars: PChar; Len: Integer; out Value: QWord): Boolean;
- begin
- Result := xsdTryParseNonNegativeInteger(Chars, Len, Value) and (Value >= 1);
- end;
- function xsdTryParseByte(Chars: PChar; Len: Integer; out Value: Shortint): Boolean;
- var
- Tmp: Int64;
- begin
- Result := xsdTryParseInteger(Chars, Len, Tmp) and (Tmp <= 128) and (Tmp >= -127);
- Value := Tmp;
- end;
- function xsdTryParseShort(Chars: PChar; Len: Integer; out Value: Smallint): Boolean;
- var
- Tmp: Int64;
- begin
- Result := xsdTryParseInteger(Chars, Len, Tmp) and (Tmp <= 32767) and (Tmp >= -32768);
- Value := Tmp;
- end;
- function xsdTryParseInt(Chars: PChar; Len: Integer; out Value: Longint): Boolean;
- var
- Tmp: Int64;
- begin
- Result := xsdTryParseInteger(Chars, Len, Tmp) and (Tmp <= 2147483647) and (Tmp >= -2147483648);
- Value := Tmp;
- end;
- function xsdTryParseLong(Chars: PChar; Len: Integer; out Value: Int64): Boolean;
- begin
- Result := xsdTryParseInteger(Chars, Len, Value);
- end;
- function xsdTryParseUnsignedByte(Chars: PChar; Len: Integer; out Value: Byte): Boolean;
- var
- Tmp: QWord;
- begin
- Result := xsdTryParseNonNegativeInteger(Chars, Len, Tmp) and (Tmp <= 255);
- Value := Tmp;
- end;
- function xsdTryParseUnsignedShort(Chars: PChar; Len: Integer; out Value: Word): Boolean;
- var
- Tmp: QWord;
- begin
- Result := xsdTryParseNonNegativeInteger(Chars, Len, Tmp) and (Tmp <= 65535);
- Value := Tmp;
- end;
- function xsdTryParseUnsignedInt(Chars: PChar; Len: Integer; out Value: Longword): Boolean;
- var
- Tmp: QWord;
- begin
- Result := xsdTryParseNonNegativeInteger(Chars, Len, Tmp) and (Tmp <= 4294967295);
- Value := Tmp;
- end;
- function xsdTryParseUnsignedLong(Chars: PChar; Len: Integer; out Value: QWord): Boolean;
- begin
- Result := xsdTryParseNonNegativeInteger(Chars, Len, Value)
- end;
- function xsdTryParseEnum(Chars: PChar; Len: Integer; enum: array of AnsiString; out Value: Integer): Boolean;
- var
- Temp: AnsiString;
- I: Integer;
- begin
- Temp := '';
- Result := xsdTryParseString(Chars, Len, Temp);
- if Result then
- begin
- for I := 0 to High(enum) do
- if Temp = enum[I] then
- begin
- Value := I;
- Exit(True);
- end;
- Result := False;
- end;
- end;
- function xsdParseStringDef(Chars: PChar; Len: Integer; Default: AnsiString): AnsiString;
- begin
- if not xsdTryParseString(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseStringLowerDef(Chars: PChar; Len: Integer; Default: AnsiString): AnsiString;
- begin
- if not xsdTryParseStringLower(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseBooleanDef(Chars: PChar; Len: Integer; Default: Boolean): Boolean;
- begin
- if not xsdTryParseBoolean(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseDateDef(Chars: PChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone): TDateTime;
- begin
- if not xsdTryParseDate(Chars, Len, Result, Timezone) then
- Result := Default;
- end;
- function xsdParseTimeDef(Chars: PChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone): TDateTime;
- begin
- if not xsdTryParseTime(Chars, Len, Result, Timezone) then
- Result := Default;
- end;
- function xsdParseDateTimeDef(Chars: PChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone): TDateTime;
- begin
- if not xsdTryParseDateTime(Chars, Len, Result, Timezone) then
- Result := Default;
- end;
- function xsdParseDecimalDef(Chars: PChar; Len: Integer; Default: Extended): Extended;
- begin
- if not xsdTryParseDecimal(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseDoubleDef(Chars: PChar; Len: Integer; Default: Double): Double;
- begin
- if not xsdTryParseDouble(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseFloatDef(Chars: PChar; Len: Integer; Default: Single): Single;
- begin
- if not xsdTryParseFloat(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseIntegerDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- begin
- if not xsdTryParseInteger(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseNonNegativeIntegerDef(Chars: PChar; Len: Integer; Default: QWord): QWord;
- begin
- if not xsdTryParseNonNegativeInteger(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseNonPositiveIntegerDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- begin
- if not xsdTryParseNonPositiveInteger(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseNegativeIntegerDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- begin
- if not xsdTryParseNegativeInteger(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParsePositiveIntegerDef(Chars: PChar; Len: Integer; Default: QWord): QWord;
- begin
- if not xsdTryParsePositiveInteger(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseByteDef(Chars: PChar; Len: Integer; Default: Shortint): Shortint;
- begin
- if not xsdTryParseByte(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseShortDef(Chars: PChar; Len: Integer; Default: Smallint): Smallint;
- begin
- if not xsdTryParseShort(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseIntDef(Chars: PChar; Len: Integer; Default: Longint): Longint;
- begin
- if not xsdTryParseInt(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseLongDef(Chars: PChar; Len: Integer; Default: Int64): Int64;
- begin
- if not xsdTryParseLong(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseUnsignedByteDef(Chars: PChar; Len: Integer; Default: Byte): Byte;
- begin
- if not xsdTryParseUnsignedByte(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseUnsignedShortDef(Chars: PChar; Len: Integer; Default: Word): Word;
- begin
- if not xsdTryParseUnsignedShort(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseUnsignedIntDef(Chars: PChar; Len: Integer; Default: Longword): Longword;
- begin
- if not xsdTryParseUnsignedInt(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseUnsignedLongDef(Chars: PChar; Len: Integer; Default: QWord): QWord;
- begin
- if not xsdTryParseUnsignedLong(Chars, Len, Result) then
- Result := Default;
- end;
- function xsdParseEnumDef(Chars: PChar; Len: Integer; enum: array of AnsiString; Default: Integer): Integer;
- begin
- if not xsdTryParseEnum(Chars, Len, enum, Result) then
- Result := Default;
- end;
- procedure xsdParseBase64(Chars: PChar; Len: Integer; const Value: TStream);
- begin
- if not xsdTryParseBase64(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:base64Binary']);
- end;
- procedure xsdParseString(Chars: PChar; Len: Integer; out Value: AnsiString);
- begin
- if not xsdTryParseString(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:string']);
- end;
- procedure xsdParseStringLower(Chars: PChar; Len: Integer; out Value: AnsiString);
- begin
- if not xsdTryParseStringLower(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:string']);
- end;
- procedure xsdParseBoolean(Chars: PChar; Len: Integer; out Value: Boolean);
- begin
- if not xsdTryParseBoolean(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:boolean']);
- end;
- procedure xsdParseDate(Chars: PChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone; BC: PBoolean);
- begin
- if not xsdTryParseDate(Chars, Len, Year, Month, Day, Timezone, BC) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:date']);
- end;
- procedure xsdParseDate(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone);
- begin
- if not xsdTryParseDate(Chars, Len, Value, Timezone) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:date']);
- end;
- procedure xsdParseTime(Chars: PChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone);
- begin
- if not xsdTryParseTime(Chars, Len, Hour, Minute, Second, Milliseconds, Timezone) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:time']);
- end;
- procedure xsdParseTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone);
- begin
- if not xsdTryParseTime(Chars, Len, Value, Timezone) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:time']);
- end;
- procedure xsdParseDateTime(Chars: PChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean);
- begin
- if not xsdTryParseDateTime(Chars, Len, Year, Month, Day, Hour, Minute, Second, Milliseconds, Timezone, BC) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:dateTime']);
- end;
- procedure xsdParseDateTime(Chars: PChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone);
- begin
- if not xsdTryParseDateTime(Chars, Len, Value, Timezone) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:dateTime']);
- end;
- procedure xsdParseDecimal(Chars: PChar; Len: Integer; out Value: Extended);
- begin
- if not xsdTryParseDecimal(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:decimal']);
- end;
- procedure xsdParseDouble(Chars: PChar; Len: Integer; out Value: Double);
- begin
- if not xsdTryParseDouble(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:double']);
- end;
- procedure xsdParseFloat(Chars: PChar; Len: Integer; out Value: Single);
- begin
- if not xsdTryParseFloat(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:float']);
- end;
- procedure xsdParseInteger(Chars: PChar; Len: Integer; out Value: Int64);
- begin
- if not xsdTryParseInteger(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:integer']);
- end;
- procedure xsdParseNonNegativeInteger(Chars: PChar; Len: Integer; out Value: QWord);
- begin
- if not xsdTryParseNonNegativeInteger(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:nonNegativeInteger']);
- end;
- procedure xsdParseNonPositiveInteger(Chars: PChar; Len: Integer; out Value: Int64);
- begin
- if not xsdTryParseNonPositiveInteger(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:nonPositiveInteger']);
- end;
- procedure xsdParseNegativeInteger(Chars: PChar; Len: Integer; out Value: Int64);
- begin
- if not xsdTryParseNegativeInteger(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:negativeInteger']);
- end;
- procedure xsdParsePositiveInteger(Chars: PChar; Len: Integer; out Value: QWord);
- begin
- if not xsdTryParsePositiveInteger(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:positiveInteger']);
- end;
- procedure xsdParseByte(Chars: PChar; Len: Integer; out Value: Shortint);
- begin
- if not xsdTryParseByte(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:byte']);
- end;
- procedure xsdParseShort(Chars: PChar; Len: Integer; out Value: Smallint);
- begin
- if not xsdTryParseShort(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:short']);
- end;
- procedure xsdParseInt(Chars: PChar; Len: Integer; out Value: Longint);
- begin
- if not xsdTryParseInt(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:int']);
- end;
- procedure xsdParseLong(Chars: PChar; Len: Integer; out Value: Int64);
- begin
- if not xsdTryParseLong(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:long']);
- end;
- procedure xsdParseUnsignedByte(Chars: PChar; Len: Integer; out Value: Byte);
- begin
- if not xsdTryParseUnsignedByte(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedByte']);
- end;
- procedure xsdParseUnsignedShort(Chars: PChar; Len: Integer; out Value: Word);
- begin
- if not xsdTryParseUnsignedShort(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedShort']);
- end;
- procedure xsdParseUnsignedInt(Chars: PChar; Len: Integer; out Value: Longword);
- begin
- if not xsdTryParseUnsignedInt(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedInt']);
- end;
- procedure xsdParseUnsignedLong(Chars: PChar; Len: Integer; out Value: QWord);
- begin
- if not xsdTryParseUnsignedLong(Chars, Len, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedLong']);
- end;
- procedure xsdParseEnum(Chars: PChar; Len: Integer; enum: array of AnsiString; out Value: Integer);
- begin
- if not xsdTryParseEnum(Chars, Len, enum, Value) then
- raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:enum']);
- end;
- function xsdParseString(Chars: PChar; Len: Integer): AnsiString;
- begin
- xsdParseString(Chars, Len, Result);
- end;
- function xsdParseStringLower(Chars: PChar; Len: Integer): AnsiString;
- begin
- xsdParseStringLower(Chars, Len, Result);
- end;
- function xsdParseBoolean(Chars: PChar; Len: Integer): Boolean;
- begin
- xsdParseBoolean(Chars, Len, Result);
- end;
- function xsdParseDate(Chars: PChar; Len: Integer; Timezone: PXsdTimezone): TDateTime;
- begin
- xsdParseDate(Chars, Len, Result, Timezone);
- end;
- function xsdParseTime(Chars: PChar; Len: Integer; Timezone: PXsdTimezone): TDateTime;
- begin
- xsdParseTime(Chars, Len, Result, Timezone);
- end;
- function xsdParseDateTime(Chars: PChar; Len: Integer; Timezone: PXsdTimezone): TDateTime;
- begin
- xsdParseDateTime(Chars, Len, Result, Timezone);
- end;
- function xsdParseDecimal(Chars: PChar; Len: Integer): Extended;
- begin
- xsdParseDecimal(Chars, Len, Result);
- end;
- function xsdParseDouble(Chars: PChar; Len: Integer): Double;
- begin
- xsdParseDouble(Chars, Len, Result);
- end;
- function xsdParseFloat(Chars: PChar; Len: Integer): Single;
- begin
- xsdParseFloat(Chars, Len, Result);
- end;
- function xsdParseInteger(Chars: PChar; Len: Integer): Int64;
- begin
- xsdParseInteger(Chars, Len, Result);
- end;
- function xsdParseNonNegativeInteger(Chars: PChar; Len: Integer): QWord;
- begin
- xsdParseNonNegativeInteger(Chars, Len, Result);
- end;
- function xsdParseNonPositiveInteger(Chars: PChar; Len: Integer): Int64;
- begin
- xsdParseNonPositiveInteger(Chars, Len, Result);
- end;
- function xsdParseNegativeInteger(Chars: PChar; Len: Integer): Int64;
- begin
- xsdParseNegativeInteger(Chars, Len, Result);
- end;
- function xsdParsePositiveInteger(Chars: PChar; Len: Integer): QWord;
- begin
- xsdParsePositiveInteger(Chars, Len, Result);
- end;
- function xsdParseByte(Chars: PChar; Len: Integer): Shortint;
- begin
- xsdParseByte(Chars, Len, Result);
- end;
- function xsdParseShort(Chars: PChar; Len: Integer): Smallint;
- begin
- xsdParseShort(Chars, Len, Result);
- end;
- function xsdParseInt(Chars: PChar; Len: Integer): Longint;
- begin
- xsdParseInt(Chars, Len, Result);
- end;
- function xsdParseLong(Chars: PChar; Len: Integer): Int64;
- begin
- xsdParseLong(Chars, Len, Result);
- end;
- function xsdParseUnsignedByte(Chars: PChar; Len: Integer): Byte;
- begin
- xsdParseUnsignedByte(Chars, Len, Result);
- end;
- function xsdParseUnsignedShort(Chars: PChar; Len: Integer): Word;
- begin
- xsdParseUnsignedShort(Chars, Len, Result);
- end;
- function xsdParseUnsignedInt(Chars: PChar; Len: Integer): Longword;
- begin
- xsdParseUnsignedInt(Chars, Len, Result);
- end;
- function xsdParseUnsignedLong(Chars: PChar; Len: Integer): QWord;
- begin
- xsdParseUnsignedLong(Chars, Len, Result);
- end;
- function xsdParseEnum(Chars: PChar; Len: Integer; enum: array of AnsiString): Integer;
- begin
- xsdParseEnum(Chars, Len, enum, Result);
- end;
- (*
- function xsdTryParseBase64(const S: AnsiString; const Value: TStream): Boolean;
- begin
- end;
- function xsdTryParseString(const S: AnsiString; out Value: AnsiString): Boolean;
- begin
- end;
- function xsdTryParseStringLower(const S: AnsiString; out Value: AnsiString
- ): Boolean;
- begin
- end;
- function xsdTryParseBoolean(const S: AnsiString; out Value: Boolean): Boolean;
- begin
- end;
- function xsdTryParseDate(const S: AnsiString; out Year, Month, Day: Longword;
- Timezone: PXsdTimezone; BC: PBoolean): Boolean;
- begin
- end;
- function xsdTryParseDate(const S: AnsiString; out Value: TDateTime;
- Timezone: PXsdTimezone): Boolean;
- begin
- end;
- function xsdTryParseTime(const S: AnsiString; out Hour, Minute, Second,
- Milliseconds: Longword; Timezone: PXsdTimezone): Boolean;
- begin
- end;
- function xsdTryParseTime(const S: AnsiString; out Value: TDateTime;
- Timezone: PXsdTimezone): Boolean;
- begin
- end;
- function xsdTryParseDateTime(const S: AnsiString; out Year, Month, Day, Hour,
- Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean
- ): Boolean;
- begin
- end;
- function xsdTryParseDateTime(const S: AnsiString; out Value: TDateTime;
- Timezone: PXsdTimezone): Boolean;
- begin
- end;
- function xsdTryParseDecimal(const S: AnsiString; out Value: Extended): Boolean;
- begin
- end;
- function xsdTryParseDouble(const S: AnsiString; out Value: Double): Boolean;
- begin
- end;
- function xsdTryParseFloat(const S: AnsiString; out Value: Single): Boolean;
- begin
- end;
- function xsdTryParseInteger(const S: AnsiString; out Value: Int64): Boolean;
- begin
- end;
- function xsdTryParseNonNegativeInteger(const S: AnsiString; out Value: QWord
- ): Boolean;
- begin
- end;
- function xsdTryParseNonPositiveInteger(const S: AnsiString; out Value: Int64
- ): Boolean;
- begin
- end;
- function xsdTryParseNegativeInteger(const S: AnsiString; out Value: Int64
- ): Boolean;
- begin
- end;
- function xsdTryParsePositiveInteger(const S: AnsiString; out Value: QWord
- ): Boolean;
- begin
- end;
- function xsdTryParseByte(const S: AnsiString; out Value: Shortint): Boolean;
- begin
- end;
- function xsdTryParseShort(const S: AnsiString; out Value: Smallint): Boolean;
- begin
- end;
- function xsdTryParseInt(const S: AnsiString; out Value: Longint): Boolean;
- begin
- end;
- function xsdTryParseLong(const S: AnsiString; out Value: Int64): Boolean;
- begin
- end;
- function xsdTryParseUnsignedByte(const S: AnsiString; out Value: Byte): Boolean;
- begin
- end;
- function xsdTryParseUnsignedShort(const S: AnsiString; out Value: Word
- ): Boolean;
- begin
- end;
- function xsdTryParseUnsignedInt(const S: AnsiString; out Value: Longword
- ): Boolean;
- begin
- end;
- function xsdTryParseUnsignedLong(const S: AnsiString; out Value: QWord
- ): Boolean;
- begin
- end;
- function xsdTryParseEnum(const S: AnsiString; enum: array of AnsiString;
- out Value: Integer): Boolean;
- begin
- end;
- function xsdParseStringDef(const S: AnsiString; Default: AnsiString
- ): AnsiString;
- begin
- end;
- function xsdParseStringLowerDef(const S: AnsiString; Default: AnsiString
- ): AnsiString;
- begin
- end;
- function xsdParseBooleanDef(const S: AnsiString; Default: Boolean): Boolean;
- begin
- end;
- function xsdParseDateDef(const S: AnsiString; Default: TDateTime;
- Timezone: PXsdTimezone): TDateTime;
- begin
- end;
- function xsdParseTimeDef(const S: AnsiString; Default: TDateTime;
- Timezone: PXsdTimezone): TDateTime;
- begin
- end;
- function xsdParseDateTimeDef(const S: AnsiString; Default: TDateTime;
- Timezone: PXsdTimezone): TDateTime;
- begin
- end;
- function xsdParseDecimalDef(const S: AnsiString; Default: Extended): Extended;
- begin
- end;
- function xsdParseDoubleDef(const S: AnsiString; Default: Double): Double;
- begin
- end;
- function xsdParseFloatDef(const S: AnsiString; Default: Single): Single;
- begin
- end;
- function xsdParseIntegerDef(const S: AnsiString; Default: Int64): Int64;
- begin
- end;
- function xsdParseNonNegativeIntegerDef(const S: AnsiString; Default: QWord
- ): QWord;
- begin
- end;
- function xsdParseNonPositiveIntegerDef(const S: AnsiString; Default: Int64
- ): Int64;
- begin
- end;
- function xsdParseNegativeIntegerDef(const S: AnsiString; Default: Int64): Int64;
- begin
- end;
- function xsdParsePositiveIntegerDef(const S: AnsiString; Default: QWord): QWord;
- begin
- end;
- function xsdParseByteDef(const S: AnsiString; Default: Shortint): Shortint;
- begin
- end;
- function xsdParseShortDef(const S: AnsiString; Default: Smallint): Smallint;
- begin
- end;
- function xsdParseIntDef(const S: AnsiString; Default: Longint): Longint;
- begin
- end;
- function xsdParseLongDef(const S: AnsiString; Default: Int64): Int64;
- begin
- end;
- function xsdParseUnsignedByteDef(const S: AnsiString; Default: Byte): Byte;
- begin
- end;
- function xsdParseUnsignedShortDef(const S: AnsiString; Default: Word): Word;
- begin
- end;
- function xsdParseUnsignedIntDef(const S: AnsiString; Default: Longword
- ): Longword;
- begin
- end;
- function xsdParseUnsignedLongDef(const S: AnsiString; Default: QWord): QWord;
- begin
- end;
- function xsdParseEnumDef(const S: AnsiString; enum: array of AnsiString;
- Default: Integer): Integer;
- begin
- end;*)
- procedure xsdParseBase64(const S: AnsiString; const Value: TStream);
- begin
- xsdParseBase64(PChar(S), Length(S), Value);
- end;
- procedure xsdParseString(const S: AnsiString; out Value: AnsiString);
- begin
- xsdParseString(PChar(S), Length(S), Value);
- end;
- procedure xsdParseStringLower(const S: AnsiString; out Value: AnsiString);
- begin
- xsdParseStringLower(PChar(S), Length(S), Value);
- end;
- procedure xsdParseBoolean(const S: AnsiString; out Value: Boolean);
- begin
- xsdParseBoolean(PChar(S), Length(S), Value);
- end;
- procedure xsdParseDate(const S: AnsiString; out Year, Month, Day: Longword;
- Timezone: PXsdTimezone; BC: PBoolean);
- begin
- xsdParseDate(PChar(S), Length(S), Year, Month, Day, Timezone, BC);
- end;
- procedure xsdParseDate(const S: AnsiString; out Value: TDateTime;
- Timezone: PXsdTimezone);
- begin
- xsdParseDate(PChar(S), Length(S), Value);
- end;
- procedure xsdParseTime(const S: AnsiString; out Hour, Minute, Second,
- Milliseconds: Longword; Timezone: PXsdTimezone);
- begin
- xsdParseTime(PChar(S), Length(S), Hour, Minute, Second,
- Milliseconds, Timezone);
- end;
- procedure xsdParseTime(const S: AnsiString; out Value: TDateTime;
- Timezone: PXsdTimezone);
- begin
- xsdParseTime(PChar(S), Length(S), Value, Timezone);
- end;
- procedure xsdParseDateTime(const S: AnsiString; out Year, Month, Day, Hour,
- Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean);
- begin
- xsdParseDateTime(PChar(S), Length(S), Year, Month, Day, Hour,
- Minute, Second, Milliseconds, Timezone, BC);
- end;
- procedure xsdParseDateTime(const S: AnsiString; out Value: TDateTime;
- Timezone: PXsdTimezone);
- begin
- xsdParseDateTime(PChar(S), Length(S), Value);
- end;
- procedure xsdParseDecimal(const S: AnsiString; out Value: Extended);
- begin
- xsdParseDecimal(PChar(S), Length(S), Value);
- end;
- procedure xsdParseDouble(const S: AnsiString; out Value: Double);
- begin
- xsdParseDouble(PChar(S), Length(S), Value);
- end;
- procedure xsdParseFloat(const S: AnsiString; out Value: Single);
- begin
- xsdParseFloat(PChar(S), Length(S), Value);
- end;
- procedure xsdParseInteger(const S: AnsiString; out Value: Int64);
- begin
- xsdParseInteger(PChar(S), Length(S), Value);
- end;
- procedure xsdParseNonNegativeInteger(const S: AnsiString; out Value: QWord);
- begin
- xsdParseNonNegativeInteger(PChar(S), Length(S), Value);
- end;
- procedure xsdParseNonPositiveInteger(const S: AnsiString; out Value: Int64);
- begin
- xsdParseNonPositiveInteger(PChar(S), Length(S), Value);
- end;
- procedure xsdParseNegativeInteger(const S: AnsiString; out Value: Int64);
- begin
- xsdParseNegativeInteger(PChar(S), Length(S), Value);
- end;
- procedure xsdParsePositiveInteger(const S: AnsiString; out Value: QWord);
- begin
- xsdParsePositiveInteger(PChar(S), Length(S), Value);
- end;
- procedure xsdParseByte(const S: AnsiString; out Value: Shortint);
- begin
- xsdParseByte(PChar(S), Length(S), Value);
- end;
- procedure xsdParseShort(const S: AnsiString; out Value: Smallint);
- begin
- xsdParseShort(PChar(S), Length(S), Value);
- end;
- procedure xsdParseInt(const S: AnsiString; out Value: Longint);
- begin
- xsdParseInt(PChar(S), Length(S), Value);
- end;
- procedure xsdParseLong(const S: AnsiString; out Value: Int64);
- begin
- xsdParseLong(PChar(S), Length(S), Value);
- end;
- procedure xsdParseUnsignedByte(const S: AnsiString; out Value: Byte);
- begin
- xsdParseUnsignedByte(PChar(S), Length(S), Value);
- end;
- procedure xsdParseUnsignedShort(const S: AnsiString; out Value: Word);
- begin
- xsdParseUnsignedShort(PChar(S), Length(S), Value);
- end;
- procedure xsdParseUnsignedInt(const S: AnsiString; out Value: Longword);
- begin
- xsdParseUnsignedInt(PChar(S), Length(S), Value);
- end;
- procedure xsdParseUnsignedLong(const S: AnsiString; out Value: QWord);
- begin
- xsdParseUnsignedLong(PChar(S), Length(S), Value);
- end;
- procedure xsdParseEnum(const S: AnsiString; enum: array of AnsiString; out Value: Integer);
- begin
- xsdParseEnum(PChar(S), Length(S), enum, Value);
- end;
- function xsdParseString(const S: AnsiString): AnsiString;
- begin
- xsdParseString(PChar(S), Length(S), Result);
- end;
- function xsdParseStringLower(const S: AnsiString): AnsiString;
- begin
- xsdParseStringLower(PChar(S), Length(S), Result);
- end;
- function xsdParseBoolean(const S: AnsiString): Boolean;
- begin
- xsdParseBoolean(PChar(S), Length(S), Result);
- end;
- function xsdParseDate(const S: AnsiString; Timezone: PXsdTimezone): TDateTime;
- begin
- xsdParseDate(PChar(S), Length(S), Result, Timezone);
- end;
- function xsdParseTime(const S: AnsiString; Timezone: PXsdTimezone): TDateTime;
- begin
- xsdParseTime(PChar(S), Length(S), Result, Timezone);
- end;
- function xsdParseDateTime(const S: AnsiString; Timezone: PXsdTimezone): TDateTime;
- begin
- xsdParseDateTime(PChar(S), Length(S), Result, Timezone);
- end;
- function xsdParseDecimal(const S: AnsiString): Extended;
- begin
- xsdParseDecimal(PChar(S), Length(S), Result);
- end;
- function xsdParseDouble(const S: AnsiString): Double;
- begin
- xsdParseDouble(PChar(S), Length(S), Result);
- end;
- function xsdParseFloat(const S: AnsiString): Single;
- begin
- xsdParseFloat(PChar(S), Length(S), Result);
- end;
- function xsdParseInteger(const S: AnsiString): Int64;
- begin
- xsdParseInteger(PChar(S), Length(S), Result);
- end;
- function xsdParseNonNegativeInteger(const S: AnsiString): QWord;
- begin
- xsdParseNonNegativeInteger(PChar(S), Length(S), Result);
- end;
- function xsdParseNonPositiveInteger(const S: AnsiString): Int64;
- begin
- xsdParseNonPositiveInteger(PChar(S), Length(S), Result);
- end;
- function xsdParseNegativeInteger(const S: AnsiString): Int64;
- begin
- xsdParseNegativeInteger(PChar(S), Length(S), Result);
- end;
- function xsdParsePositiveInteger(const S: AnsiString): QWord;
- begin
- xsdParsePositiveInteger(PChar(S), Length(S), Result);
- end;
- function xsdParseByte(const S: AnsiString): Shortint;
- begin
- xsdParseByte(PChar(S), Length(S), Result);
- end;
- function xsdParseShort(const S: AnsiString): Smallint;
- begin
- xsdParseShort(PChar(S), Length(S), Result);
- end;
- function xsdParseInt(const S: AnsiString): Longint;
- begin
- xsdParseInt(PChar(S), Length(S), Result);
- end;
- function xsdParseLong(const S: AnsiString): Int64;
- begin
- xsdParseLong(PChar(S), Length(S), Result);
- end;
- function xsdParseUnsignedByte(const S: AnsiString): Byte;
- begin
- xsdParseUnsignedByte(PChar(S), Length(S), Result);
- end;
- function xsdParseUnsignedShort(const S: AnsiString): Word;
- begin
- xsdParseUnsignedShort(PChar(S), Length(S), Result);
- end;
- function xsdParseUnsignedInt(const S: AnsiString): Longword;
- begin
- xsdParseUnsignedInt(PChar(S), Length(S), Result);
- end;
- function xsdParseUnsignedLong(const S: AnsiString): QWord;
- begin
- xsdParseUnsignedLong(PChar(S), Length(S), Result);
- end;
- function xsdParseEnum(const S: AnsiString; enum: array of AnsiString): Integer;
- begin
- xsdParseEnum(PChar(S), Length(S), enum, Result);
- end;
- end.
|