2
0

xmlxsdparser.pas 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441
  1. {
  2. Parser functions to parser xml xsd types
  3. See: http://books.xmlschemata.org/relaxng/relax-CHP-19.html
  4. Copyright (C) 2011 by Ivo Steinmann
  5. }
  6. {$IFNDEF FPC_DOTTEDUNITS}
  7. unit xmlxsdparser;
  8. {$ENDIF FPC_DOTTEDUNITS}
  9. {$mode objfpc}
  10. {$H+}
  11. interface
  12. {$IFDEF FPC_DOTTEDUNITS}
  13. uses
  14. {$IFDEF MSWINDOWS}WinApi.Windows,{$ENDIF}
  15. {$IFDEF UNIX}UnixApi.Unix,{$ENDIF}
  16. System.SysUtils,
  17. System.DateUtils,
  18. System.Math,
  19. System.Classes;
  20. {$ELSE FPC_DOTTEDUNITS}
  21. uses
  22. {$IFDEF MSWINDOWS}windows,{$ENDIF}
  23. {$IFDEF UNIX}unix,{$ENDIF}
  24. sysutils,
  25. dateutils,
  26. math,
  27. Classes;
  28. {$ENDIF FPC_DOTTEDUNITS}
  29. resourcestring
  30. SXsdParserError = 'parsing "%s" as "%s" failed';
  31. type
  32. {$IFDEF MSWINDOWS}
  33. PBoolean = System.PBoolean;
  34. // PBoolean is redefined by windows unit, so redefine it here again!
  35. {$ENDIF}
  36. TXsdTimezoneType = (
  37. tzUnknown,
  38. tzLocal,
  39. tzUtc
  40. );
  41. PXsdTimezone = ^TXsdTimezone;
  42. TXsdTimezone = record
  43. Kind : TXsdTimezoneType;
  44. Hour : Longint; // +/- [00..23]
  45. Minute : Longword; // [00..59]
  46. end;
  47. const
  48. TIMEZONE_UTC: TXsdTimezone = (Kind:tzUTC;Hour:0;Minute:0);
  49. { Format functions }
  50. function xsdFormatBase64(Value: TStream): AnsiString;
  51. function xsdFormatBoolean(Value: Boolean; UseWords: Boolean = False): AnsiString;
  52. function xsdFormatDate(Year, Month, Day: Longword; BC: Boolean; Timezone: PXsdTimezone = nil): AnsiString;
  53. function xsdFormatDate(Value: TDateTime; Timezone: PXsdTimezone = nil): AnsiString;
  54. function xsdFormatTime(Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil): AnsiString;
  55. function xsdFormatTime(Value: TDateTime; Timezone: PXsdTimezone = nil): AnsiString;
  56. function xsdFormatDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; BC: Boolean; Timezone: PXsdTimezone = nil): AnsiString;
  57. function xsdFormatDateTime(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
  58. function xsdFormatDecimal(Value: Extended; Precision: Integer = 4; Digits: Integer = 1): AnsiString;
  59. function xsdFormatDouble(Value: Double): AnsiString;
  60. function xsdFormatFloat(Value: Single): AnsiString;
  61. function xsdFormatByte(Value: Shortint): AnsiString;
  62. function xsdFormatShort(Value: Smallint): AnsiString;
  63. function xsdFormatInt(Value: Longint): AnsiString;
  64. function xsdFormatLong(Value: Int64): AnsiString;
  65. function xsdFormatUnsignedByte(Value: Byte): AnsiString;
  66. function xsdFormatUnsignedShort(Value: Word): AnsiString;
  67. function xsdFormatUnsignedInt(Value: Longword): AnsiString;
  68. function xsdFormatUnsignedLong(Value: QWord): AnsiString;
  69. function xsdFormatEnum(enum: array of AnsiString; Value: Integer): AnsiString;
  70. { DateTime functions }
  71. function xsdNowUTC: TDateTime;
  72. function xsdGetLocalTimezone: TXsdTimezone;
  73. function xsdTimezoneUtcOffsetMinutes(const Timezone: TXsdTimezone): Longint;
  74. function xsdDateTimeToUTC(const DateTime: TDateTime; const Current: TXsdTimezone): TDateTime;
  75. function xsdDateTimeConvert(const DateTime: TDateTime; const Current, Target: TXsdTimezone): TDateTime;
  76. { Parse functions }
  77. function xsdTryParseBase64(Chars: PAnsiChar; Len: Integer; const Value: TStream): Boolean;
  78. function xsdTryParseString(Chars: PAnsiChar; Len: Integer; out Value: AnsiString): Boolean;
  79. function xsdTryParseStringLower(Chars: PAnsiChar; Len: Integer; out Value: AnsiString): Boolean;
  80. function xsdTryParseBoolean(Chars: PAnsiChar; Len: Integer; out Value: Boolean): Boolean;
  81. function xsdTryParseDate(Chars: PAnsiChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
  82. function xsdTryParseDate(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
  83. function xsdTryParseTime(Chars: PAnsiChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil): Boolean;
  84. function xsdTryParseTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
  85. function xsdTryParseDateTime(Chars: PAnsiChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
  86. function xsdTryParseDateTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
  87. function xsdTryParseDecimal(Chars: PAnsiChar; Len: Integer; out Value: Extended): Boolean;
  88. function xsdTryParseDouble(Chars: PAnsiChar; Len: Integer; out Value: Double): Boolean;
  89. function xsdTryParseFloat(Chars: PAnsiChar; Len: Integer; out Value: Single): Boolean;
  90. function xsdTryParseInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  91. function xsdTryParseNonNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord): Boolean;
  92. function xsdTryParseNonPositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  93. function xsdTryParseNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  94. function xsdTryParsePositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord): Boolean;
  95. function xsdTryParseByte(Chars: PAnsiChar; Len: Integer; out Value: Shortint): Boolean;
  96. function xsdTryParseShort(Chars: PAnsiChar; Len: Integer; out Value: Smallint): Boolean;
  97. function xsdTryParseInt(Chars: PAnsiChar; Len: Integer; out Value: Longint): Boolean;
  98. function xsdTryParseLong(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  99. function xsdTryParseUnsignedByte(Chars: PAnsiChar; Len: Integer; out Value: Byte): Boolean;
  100. function xsdTryParseUnsignedShort(Chars: PAnsiChar; Len: Integer; out Value: Word): Boolean;
  101. function xsdTryParseUnsignedInt(Chars: PAnsiChar; Len: Integer; out Value: Longword): Boolean;
  102. function xsdTryParseUnsignedLong(Chars: PAnsiChar; Len: Integer; out Value: QWord): Boolean;
  103. function xsdTryParseEnum(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString; out Value: Integer): Boolean;
  104. function xsdParseStringDef(Chars: PAnsiChar; Len: Integer; Default: AnsiString): AnsiString;
  105. function xsdParseStringLowerDef(Chars: PAnsiChar; Len: Integer; Default: AnsiString): AnsiString;
  106. function xsdParseBooleanDef(Chars: PAnsiChar; Len: Integer; Default: Boolean): Boolean;
  107. function xsdParseDateDef(Chars: PAnsiChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
  108. function xsdParseTimeDef(Chars: PAnsiChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
  109. function xsdParseDateTimeDef(Chars: PAnsiChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
  110. function xsdParseDecimalDef(Chars: PAnsiChar; Len: Integer; Default: Extended): Extended;
  111. function xsdParseDoubleDef(Chars: PAnsiChar; Len: Integer; Default: Double): Double;
  112. function xsdParseFloatDef(Chars: PAnsiChar; Len: Integer; Default: Single): Single;
  113. function xsdParseIntegerDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  114. function xsdParseNonNegativeIntegerDef(Chars: PAnsiChar; Len: Integer; Default: QWord): QWord;
  115. function xsdParseNonPositiveIntegerDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  116. function xsdParseNegativeIntegerDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  117. function xsdParsePositiveIntegerDef(Chars: PAnsiChar; Len: Integer; Default: QWord): QWord;
  118. function xsdParseByteDef(Chars: PAnsiChar; Len: Integer; Default: Shortint): Shortint;
  119. function xsdParseShortDef(Chars: PAnsiChar; Len: Integer; Default: Smallint): Smallint;
  120. function xsdParseIntDef(Chars: PAnsiChar; Len: Integer; Default: Longint): Longint;
  121. function xsdParseLongDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  122. function xsdParseUnsignedByteDef(Chars: PAnsiChar; Len: Integer; Default: Byte): Byte;
  123. function xsdParseUnsignedShortDef(Chars: PAnsiChar; Len: Integer; Default: Word): Word;
  124. function xsdParseUnsignedIntDef(Chars: PAnsiChar; Len: Integer; Default: Longword): Longword;
  125. function xsdParseUnsignedLongDef(Chars: PAnsiChar; Len: Integer; Default: QWord): QWord;
  126. function xsdParseEnumDef(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString; Default: Integer): Integer;
  127. procedure xsdParseBase64(Chars: PAnsiChar; Len: Integer; const Value: TStream);
  128. procedure xsdParseString(Chars: PAnsiChar; Len: Integer; out Value: AnsiString);
  129. procedure xsdParseStringLower(Chars: PAnsiChar; Len: Integer; out Value: AnsiString);
  130. procedure xsdParseBoolean(Chars: PAnsiChar; Len: Integer; out Value: Boolean);
  131. procedure xsdParseDate(Chars: PAnsiChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
  132. procedure xsdParseDate(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil);
  133. procedure xsdParseTime(Chars: PAnsiChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil);
  134. procedure xsdParseTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil);
  135. procedure xsdParseDateTime(Chars: PAnsiChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
  136. procedure xsdParseDateTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone = nil);
  137. procedure xsdParseDecimal(Chars: PAnsiChar; Len: Integer; out Value: Extended);
  138. procedure xsdParseDouble(Chars: PAnsiChar; Len: Integer; out Value: Double);
  139. procedure xsdParseFloat(Chars: PAnsiChar; Len: Integer; out Value: Single);
  140. procedure xsdParseInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  141. procedure xsdParseNonNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord);
  142. procedure xsdParseNonPositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  143. procedure xsdParseNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  144. procedure xsdParsePositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord);
  145. procedure xsdParseByte(Chars: PAnsiChar; Len: Integer; out Value: Shortint);
  146. procedure xsdParseShort(Chars: PAnsiChar; Len: Integer; out Value: Smallint);
  147. procedure xsdParseInt(Chars: PAnsiChar; Len: Integer; out Value: Longint);
  148. procedure xsdParseLong(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  149. procedure xsdParseUnsignedByte(Chars: PAnsiChar; Len: Integer; out Value: Byte);
  150. procedure xsdParseUnsignedShort(Chars: PAnsiChar; Len: Integer; out Value: Word);
  151. procedure xsdParseUnsignedInt(Chars: PAnsiChar; Len: Integer; out Value: Longword);
  152. procedure xsdParseUnsignedLong(Chars: PAnsiChar; Len: Integer; out Value: QWord);
  153. procedure xsdParseEnum(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString; out Value: Integer);
  154. function xsdParseString(Chars: PAnsiChar; Len: Integer): AnsiString;
  155. function xsdParseStringLower(Chars: PAnsiChar; Len: Integer): AnsiString;
  156. function xsdParseBoolean(Chars: PAnsiChar; Len: Integer): Boolean;
  157. function xsdParseDate(Chars: PAnsiChar; Len: Integer; Timezone: PXsdTimezone = nil): TDateTime;
  158. function xsdParseTime(Chars: PAnsiChar; Len: Integer; Timezone: PXsdTimezone = nil): TDateTime;
  159. function xsdParseDateTime(Chars: PAnsiChar; Len: Integer; Timezone: PXsdTimezone = nil): TDateTime;
  160. function xsdParseDecimal(Chars: PAnsiChar; Len: Integer): Extended;
  161. function xsdParseDouble(Chars: PAnsiChar; Len: Integer): Double;
  162. function xsdParseFloat(Chars: PAnsiChar; Len: Integer): Single;
  163. function xsdParseInteger(Chars: PAnsiChar; Len: Integer): Int64;
  164. function xsdParseNonNegativeInteger(Chars: PAnsiChar; Len: Integer): QWord;
  165. function xsdParseNonPositiveInteger(Chars: PAnsiChar; Len: Integer): Int64;
  166. function xsdParseNegativeInteger(Chars: PAnsiChar; Len: Integer): Int64;
  167. function xsdParsePositiveInteger(Chars: PAnsiChar; Len: Integer): QWord;
  168. function xsdParseByte(Chars: PAnsiChar; Len: Integer): Shortint;
  169. function xsdParseShort(Chars: PAnsiChar; Len: Integer): Smallint;
  170. function xsdParseInt(Chars: PAnsiChar; Len: Integer): Longint;
  171. function xsdParseLong(Chars: PAnsiChar; Len: Integer): Int64;
  172. function xsdParseUnsignedByte(Chars: PAnsiChar; Len: Integer): Byte;
  173. function xsdParseUnsignedShort(Chars: PAnsiChar; Len: Integer): Word;
  174. function xsdParseUnsignedInt(Chars: PAnsiChar; Len: Integer): Longword;
  175. function xsdParseUnsignedLong(Chars: PAnsiChar; Len: Integer): QWord;
  176. function xsdParseEnum(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString): Integer;
  177. {
  178. function xsdTryParseBase64(const S: AnsiString; const Value: TStream): Boolean;
  179. function xsdTryParseString(const S: AnsiString; out Value: AnsiString): Boolean;
  180. function xsdTryParseStringLower(const S: AnsiString; out Value: AnsiString): Boolean;
  181. function xsdTryParseBoolean(const S: AnsiString; out Value: Boolean): Boolean;
  182. function xsdTryParseDate(const S: AnsiString; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
  183. function xsdTryParseDate(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
  184. function xsdTryParseTime(const S: AnsiString; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil): Boolean;
  185. function xsdTryParseTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
  186. function xsdTryParseDateTime(const S: AnsiString; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil): Boolean;
  187. function xsdTryParseDateTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil): Boolean;
  188. function xsdTryParseDecimal(const S: AnsiString; out Value: Extended): Boolean;
  189. function xsdTryParseDouble(const S: AnsiString; out Value: Double): Boolean;
  190. function xsdTryParseFloat(const S: AnsiString; out Value: Single): Boolean;
  191. function xsdTryParseInteger(const S: AnsiString; out Value: Int64): Boolean;
  192. function xsdTryParseNonNegativeInteger(const S: AnsiString; out Value: QWord): Boolean;
  193. function xsdTryParseNonPositiveInteger(const S: AnsiString; out Value: Int64): Boolean;
  194. function xsdTryParseNegativeInteger(const S: AnsiString; out Value: Int64): Boolean;
  195. function xsdTryParsePositiveInteger(const S: AnsiString; out Value: QWord): Boolean;
  196. function xsdTryParseByte(const S: AnsiString; out Value: Shortint): Boolean;
  197. function xsdTryParseShort(const S: AnsiString; out Value: Smallint): Boolean;
  198. function xsdTryParseInt(const S: AnsiString; out Value: Longint): Boolean;
  199. function xsdTryParseLong(const S: AnsiString; out Value: Int64): Boolean;
  200. function xsdTryParseUnsignedByte(const S: AnsiString; out Value: Byte): Boolean;
  201. function xsdTryParseUnsignedShort(const S: AnsiString; out Value: Word): Boolean;
  202. function xsdTryParseUnsignedInt(const S: AnsiString; out Value: Longword): Boolean;
  203. function xsdTryParseUnsignedLong(const S: AnsiString; out Value: QWord): Boolean;
  204. function xsdTryParseEnum(const S: AnsiString; enum: array of AnsiString; out Value: Integer): Boolean;
  205. function xsdParseStringDef(const S: AnsiString; Default: AnsiString): AnsiString;
  206. function xsdParseStringLowerDef(const S: AnsiString; Default: AnsiString): AnsiString;
  207. function xsdParseBooleanDef(const S: AnsiString; Default: Boolean): Boolean;
  208. function xsdParseDateDef(const S: AnsiString; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
  209. function xsdParseTimeDef(const S: AnsiString; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
  210. function xsdParseDateTimeDef(const S: AnsiString; Default: TDateTime; Timezone: PXsdTimezone = nil): TDateTime;
  211. function xsdParseDecimalDef(const S: AnsiString; Default: Extended): Extended;
  212. function xsdParseDoubleDef(const S: AnsiString; Default: Double): Double;
  213. function xsdParseFloatDef(const S: AnsiString; Default: Single): Single;
  214. function xsdParseIntegerDef(const S: AnsiString; Default: Int64): Int64;
  215. function xsdParseNonNegativeIntegerDef(const S: AnsiString; Default: QWord): QWord;
  216. function xsdParseNonPositiveIntegerDef(const S: AnsiString; Default: Int64): Int64;
  217. function xsdParseNegativeIntegerDef(const S: AnsiString; Default: Int64): Int64;
  218. function xsdParsePositiveIntegerDef(const S: AnsiString; Default: QWord): QWord;
  219. function xsdParseByteDef(const S: AnsiString; Default: Shortint): Shortint;
  220. function xsdParseShortDef(const S: AnsiString; Default: Smallint): Smallint;
  221. function xsdParseIntDef(const S: AnsiString; Default: Longint): Longint;
  222. function xsdParseLongDef(const S: AnsiString; Default: Int64): Int64;
  223. function xsdParseUnsignedByteDef(const S: AnsiString; Default: Byte): Byte;
  224. function xsdParseUnsignedShortDef(const S: AnsiString; Default: Word): Word;
  225. function xsdParseUnsignedIntDef(const S: AnsiString; Default: Longword): Longword;
  226. function xsdParseUnsignedLongDef(const S: AnsiString; Default: QWord): QWord;
  227. function xsdParseEnumDef(const S: AnsiString; enum: array of AnsiString; Default: Integer): Integer;
  228. }
  229. procedure xsdParseBase64(const S: AnsiString; const Value: TStream);
  230. procedure xsdParseString(const S: AnsiString; out Value: AnsiString);
  231. procedure xsdParseStringLower(const S: AnsiString; out Value: AnsiString);
  232. procedure xsdParseBoolean(const S: AnsiString; out Value: Boolean);
  233. procedure xsdParseDate(const S: AnsiString; out Year, Month, Day: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
  234. procedure xsdParseDate(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil);
  235. procedure xsdParseTime(const S: AnsiString; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil);
  236. procedure xsdParseTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil);
  237. procedure xsdParseDateTime(const S: AnsiString; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone = nil; BC: PBoolean = nil);
  238. procedure xsdParseDateTime(const S: AnsiString; out Value: TDateTime; Timezone: PXsdTimezone = nil);
  239. procedure xsdParseDecimal(const S: AnsiString; out Value: Extended);
  240. procedure xsdParseDouble(const S: AnsiString; out Value: Double);
  241. procedure xsdParseFloat(const S: AnsiString; out Value: Single);
  242. procedure xsdParseInteger(const S: AnsiString; out Value: Int64);
  243. procedure xsdParseNonNegativeInteger(const S: AnsiString; out Value: QWord);
  244. procedure xsdParseNonPositiveInteger(const S: AnsiString; out Value: Int64);
  245. procedure xsdParseNegativeInteger(const S: AnsiString; out Value: Int64);
  246. procedure xsdParsePositiveInteger(const S: AnsiString; out Value: QWord);
  247. procedure xsdParseByte(const S: AnsiString; out Value: Shortint);
  248. procedure xsdParseShort(const S: AnsiString; out Value: Smallint);
  249. procedure xsdParseInt(const S: AnsiString; out Value: Longint);
  250. procedure xsdParseLong(const S: AnsiString; out Value: Int64);
  251. procedure xsdParseUnsignedByte(const S: AnsiString; out Value: Byte);
  252. procedure xsdParseUnsignedShort(const S: AnsiString; out Value: Word);
  253. procedure xsdParseUnsignedInt(const S: AnsiString; out Value: Longword);
  254. procedure xsdParseUnsignedLong(const S: AnsiString; out Value: QWord);
  255. procedure xsdParseEnum(const S: AnsiString; enum: array of AnsiString; out Value: Integer);
  256. function xsdParseString(const S: AnsiString): AnsiString;
  257. function xsdParseStringLower(const S: AnsiString): AnsiString;
  258. function xsdParseBoolean(const S: AnsiString): Boolean;
  259. function xsdParseDate(const S: AnsiString; Timezone: PXsdTimezone = nil): TDateTime;
  260. function xsdParseTime(const S: AnsiString; Timezone: PXsdTimezone = nil): TDateTime;
  261. function xsdParseDateTime(const S: AnsiString; Timezone: PXsdTimezone = nil): TDateTime;
  262. function xsdParseDecimal(const S: AnsiString): Extended;
  263. function xsdParseDouble(const S: AnsiString): Double;
  264. function xsdParseFloat(const S: AnsiString): Single;
  265. function xsdParseInteger(const S: AnsiString): Int64;
  266. function xsdParseNonNegativeInteger(const S: AnsiString): QWord;
  267. function xsdParseNonPositiveInteger(const S: AnsiString): Int64;
  268. function xsdParseNegativeInteger(const S: AnsiString): Int64;
  269. function xsdParsePositiveInteger(const S: AnsiString): QWord;
  270. function xsdParseByte(const S: AnsiString): Shortint;
  271. function xsdParseShort(const S: AnsiString): Smallint;
  272. function xsdParseInt(const S: AnsiString): Longint;
  273. function xsdParseLong(const S: AnsiString): Int64;
  274. function xsdParseUnsignedByte(const S: AnsiString): Byte;
  275. function xsdParseUnsignedShort(const S: AnsiString): Word;
  276. function xsdParseUnsignedInt(const S: AnsiString): Longword;
  277. function xsdParseUnsignedLong(const S: AnsiString): QWord;
  278. function xsdParseEnum(const S: AnsiString; enum: array of AnsiString): Integer;
  279. { INTERNAL HELPERS!!! }
  280. const
  281. XSD_IGNORE_LAST = Pointer(-1); // maybe used as L parameter if the string is zero terminated
  282. function __parseNonNegativeInteger(var P: PAnsiChar; const L: PAnsiChar; out Value: QWord): Boolean;
  283. function __parseInteger(var P: PAnsiChar; const L: PAnsiChar; out Value: Int64): Boolean;
  284. function __parseFloat(var P: PAnsiChar; const L: PAnsiChar; out Value: Extended): Boolean;
  285. function __parseTimezone(var P: PAnsiChar; const L: PAnsiChar; out T: TXsdTimezone): Boolean;
  286. function __parseDate(var P: PAnsiChar; const L: PAnsiChar; out Year, Month, Day: Longword; BC: PBoolean): Boolean;
  287. function __parseTime(var P: PAnsiChar; const L: PAnsiChar; const AllowMoreThan24h: Boolean;
  288. out Hour, Minute, Second, Milliseconds: Longword): Boolean;
  289. function __strpas(Chars: PAnsiChar; Len: Integer): AnsiString;
  290. implementation
  291. function xsdFormatBase64(Value: TStream): AnsiString;
  292. const
  293. Base64: array[0..63] of AnsiChar = (
  294. 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  295. 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
  296. 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
  297. 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
  298. );
  299. BufferSize = 3*512; { buffer size must be a multiple of 3 }
  300. var
  301. Buffer: array[0..BufferSize-1] of Byte;
  302. Num, Ofs: Integer;
  303. b1, b2, b3: Byte;
  304. begin
  305. Result := '';
  306. while True do
  307. begin
  308. Num := Value.Read(Buffer, BufferSize);
  309. if Num = 0 then
  310. Exit;
  311. Ofs := 0;
  312. while Num >= 3 do
  313. begin
  314. b1 := Buffer[Ofs];
  315. b2 := Buffer[Ofs+1];
  316. b3 := Buffer[Ofs+2];
  317. Result := Result +
  318. Base64[b1 shr 2] +
  319. Base64[((b1 and $3) shl 4) or (b2 shr 4)] +
  320. Base64[((b2 and $F) shl 2) or (b3 shr 6)] +
  321. Base64[b3 and $3F];
  322. Num := Num - 3;
  323. Ofs := Ofs + 3;
  324. end;
  325. case Num of
  326. 1: begin
  327. b1 := Buffer[Ofs];
  328. Result := Result +
  329. Base64[b1 shr 2] +
  330. Base64[((b1 and $3) shl 4)] +
  331. '==';
  332. Exit;
  333. end;
  334. 2: begin
  335. b1 := Buffer[Ofs];
  336. b2 := Buffer[Ofs+1];
  337. Result := Result +
  338. Base64[b1 shr 2] +
  339. Base64[((b1 and $3) shl 4) or (b2 shr 4)] +
  340. Base64[((b2 and $F) shl 2)] +
  341. '=';
  342. Exit;
  343. end;
  344. end;
  345. end;
  346. end;
  347. function xsdFormatBoolean(Value: Boolean; UseWords: Boolean): AnsiString;
  348. begin
  349. if UseWords then
  350. if Value then
  351. Result := 'true'
  352. else
  353. Result := 'false'
  354. else
  355. if Value then
  356. Result := '1'
  357. else
  358. Result := '0';
  359. end;
  360. function xsdFormatDate(Year, Month, Day: Longword; BC: Boolean; Timezone: PXsdTimezone): AnsiString;
  361. begin
  362. Result := Format('%4.4d-%2.2u-%2.2u', [Year, Month, Day]);
  363. if BC then
  364. Result := '-' + Result;
  365. if Assigned(Timezone) then
  366. case Timezone^.Kind of
  367. tzUTC:
  368. Result := Result + 'Z';
  369. tzLOCAL:
  370. begin
  371. if Timezone^.Hour >= 0 then
  372. Result := Result + '+'
  373. else
  374. Result := Result + '-';
  375. Result := Result + Format('%2.2d:%2.2u', [Timezone^.Hour, Timezone^.Minute]);
  376. end;
  377. end;
  378. end;
  379. function xsdFormatDate(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
  380. var
  381. Year, Month, Day: Word;
  382. begin
  383. DecodeDate(Value, Year, Month, Day);
  384. Result := xsdFormatDate(Year, Month, Day, False, Timezone);
  385. end;
  386. function xsdFormatTime(Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone): AnsiString;
  387. begin
  388. Result := Format('%2.2u:%2.2u:%2.2u', [Hour, Minute, Second]);
  389. if Milliseconds > 0 then
  390. Result := Result + '.' + IntToStr(Milliseconds);
  391. if Assigned(Timezone) then
  392. case Timezone^.Kind of
  393. tzUTC:
  394. Result := Result + 'Z';
  395. tzLOCAL:
  396. begin
  397. if Timezone^.Hour >= 0 then
  398. Result := Result + '+'
  399. else
  400. Result := Result + '-';
  401. Result := Result + Format('%2.2d:%2.2u', [Timezone^.Hour, Timezone^.Minute]);
  402. end;
  403. end;
  404. end;
  405. function xsdFormatTime(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
  406. var
  407. Hour, Minute, Second, Milliseconds: Word;
  408. begin
  409. DecodeTime(Value, Hour, Minute, Second, Milliseconds);
  410. Result := xsdFormatTime(Hour, Minute, Second, Milliseconds, Timezone);
  411. end;
  412. function xsdFormatDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; BC: Boolean; Timezone: PXsdTimezone): AnsiString;
  413. begin
  414. Result := xsdFormatDate(Year, Month, Day, BC, nil) + 'T' + xsdFormatTime(Hour, Minute, Second, Milliseconds, Timezone);
  415. end;
  416. function xsdFormatDateTime(Value: TDateTime; Timezone: PXsdTimezone): AnsiString;
  417. var
  418. Year, Month, Day, Hour, Minute, Second, Milliseconds: Word;
  419. begin
  420. DecodeDateTime(Value, Year, Month, Day, Hour, Minute, Second, Milliseconds);
  421. Result := xsdFormatDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds, False, Timezone);
  422. end;
  423. function xsdFormatDecimal(Value: Extended; Precision: Integer; Digits: Integer): AnsiString;
  424. begin
  425. Result := FloatToStrF(Value, ffFixed, Precision, Digits);
  426. end;
  427. function xsdFormatDouble(Value: Double): AnsiString;
  428. begin
  429. Result := FloatToStr(Value);
  430. end;
  431. function xsdFormatFloat(Value: Single): AnsiString;
  432. begin
  433. Result := FloatToStr(Value);
  434. end;
  435. function xsdFormatByte(Value: Shortint): AnsiString;
  436. begin
  437. Result := IntToStr(Value);
  438. end;
  439. function xsdFormatShort(Value: Smallint): AnsiString;
  440. begin
  441. Result := IntToStr(Value);
  442. end;
  443. function xsdFormatInt(Value: Integer): AnsiString;
  444. begin
  445. Result := IntToStr(Value);
  446. end;
  447. function xsdFormatLong(Value: Int64): AnsiString;
  448. begin
  449. Result := IntToStr(Value);
  450. end;
  451. function xsdFormatUnsignedByte(Value: Byte): AnsiString;
  452. begin
  453. Result := IntToStr(Value);
  454. end;
  455. function xsdFormatUnsignedShort(Value: Word): AnsiString;
  456. begin
  457. Result := IntToStr(Value);
  458. end;
  459. function xsdFormatUnsignedInt(Value: Longword): AnsiString;
  460. begin
  461. Result := IntToStr(Value);
  462. end;
  463. function xsdFormatUnsignedLong(Value: QWord): AnsiString;
  464. begin
  465. Result := IntToStr(Value);
  466. end;
  467. function xsdFormatEnum(enum: array of AnsiString; Value: Integer): AnsiString;
  468. begin
  469. Result := enum[Value];
  470. end;
  471. function xsdNowUTC: TDateTime;
  472. begin
  473. Result := xsdDateTimeToUTC(Now, xsdGetLocalTimezone);
  474. end;
  475. function xsdGetLocalTimezone: TXsdTimezone;
  476. var
  477. Offset: Integer;
  478. {$IFDEF MSWINDOWS}
  479. TZInfo: TTimeZoneInformation;
  480. {$ENDIF}
  481. begin
  482. Result.Kind := tzLOCAL;
  483. {$IFDEF UNIX}
  484. Offset := Tzseconds div 60;
  485. {$ENDIF}
  486. {$IFDEF MSWINDOWS}
  487. case GetTimeZoneInformation(TZInfo) of
  488. 1: Offset := -TZInfo.Bias - TZInfo.StandardBias;
  489. 2: Offset := -TZInfo.Bias - TZInfo.DaylightBias;
  490. else Result.Kind := tzUnknown;
  491. end;
  492. {$ENDIF}
  493. Result.Hour := Offset div 60;
  494. Result.Minute := abs(Offset) mod 60;
  495. end;
  496. function xsdTimezoneUtcOffsetMinutes(const Timezone: TXsdTimezone): Longint;
  497. begin
  498. case Timezone.Kind of
  499. tzUTC: Result := 0;
  500. tzLOCAL : Result := 60*Timezone.Hour + Timezone.Minute;
  501. else raise Exception.Create('can''t get offset of unknown timezone');
  502. end;
  503. end;
  504. function xsdDateTimeToUTC(const DateTime: TDateTime; const Current: TXsdTimezone): TDateTime;
  505. begin
  506. Result := xsdDateTimeConvert(DateTime, Current, TIMEZONE_UTC);
  507. end;
  508. function xsdDateTimeConvert(const DateTime: TDateTime; const Current, Target: TXsdTimezone): TDateTime;
  509. begin
  510. Result := IncMinute(DateTime, xsdTimezoneUtcOffsetMinutes(Target) - xsdTimezoneUtcOffsetMinutes(Current));
  511. end;
  512. function __parseNonNegativeInteger(var P: PAnsiChar; const L: PAnsiChar; out Value: QWord): Boolean;
  513. begin
  514. { expect integer }
  515. Value := 0;
  516. while (P < L) and (P^ in ['0'..'9']) do
  517. begin
  518. Value := 10*Value + Ord(P^) - Ord('0');
  519. Inc(P);
  520. end;
  521. Result := True;
  522. end;
  523. function __parseInteger(var P: PAnsiChar; const L: PAnsiChar; out Value: Int64): Boolean;
  524. var
  525. N: Boolean;
  526. begin
  527. { allow '-' }
  528. N := (P < L) and (P^ = '-');
  529. if N then
  530. Inc(P);
  531. { expect integer }
  532. Value := 0;
  533. while (P < L) and (P^ in ['0'..'9']) do
  534. begin
  535. Value := 10*Value + Ord(P^) - Ord('0');
  536. Inc(P);
  537. end;
  538. if N then
  539. Value := -Value;
  540. Result := True;
  541. end;
  542. function __parseFloat(var P: PAnsiChar; const L: PAnsiChar; out Value: Extended): Boolean;
  543. var
  544. N: Boolean;
  545. Exp: Int64;
  546. Int: QWord;
  547. begin
  548. { allow 'Nan' }
  549. if (P+2 < L) and ((P^ = 'N') or (P^ = 'n')) then
  550. begin
  551. Inc(P);
  552. if (P^ <> 'A') and (P^ <> 'a') then Exit(False);
  553. Inc(P);
  554. if (P^ <> 'N') and (P^ <> 'n') then Exit(False);
  555. Inc(P);
  556. Value := Nan;
  557. Result := True;
  558. Exit;
  559. end;
  560. { allow '-' }
  561. N := (P < L) and (P^ = '-');
  562. if N then
  563. Inc(P);
  564. { allow 'Inf' }
  565. if (P+2 < L) and ((P^ = 'I') or (P^ = 'i')) then
  566. begin
  567. Inc(P);
  568. if (P^ <> 'N') and (P^ <> 'n') then Exit(False);
  569. Inc(P);
  570. if (P^ <> 'F') and (P^ <> 'f') then Exit(False);
  571. Inc(P);
  572. if N then
  573. Value := NegInfinity
  574. else
  575. Value := Infinity;
  576. Result := True;
  577. Exit;
  578. end;
  579. { expect integer }
  580. Int := 0;
  581. while (P < L) and (P^ in ['0'..'9']) do
  582. begin
  583. Int := 10*Int + Ord(P^) - Ord('0');
  584. Inc(P);
  585. end;
  586. Value := Int;
  587. { allow '.' }
  588. if (P < L) and (P^ = '.') then
  589. begin
  590. Inc(P);
  591. { expect integer }
  592. Exp := 1;
  593. Int := 0;
  594. while (P < L) and (P^ in ['0'..'9']) do
  595. begin
  596. Int := 10*Int + Ord(P^) - Ord('0');
  597. Exp := 10*Exp;
  598. Inc(P);
  599. end;
  600. Value := Value + Int / Exp;
  601. end;
  602. { allow 'E' or 'e' }
  603. if (P < L) and ((P^ = 'E') or (P^ = 'e')) then
  604. begin
  605. Inc(P);
  606. { expect integer }
  607. if not __parseInteger(P, L, Exp) then
  608. Exit(False);
  609. while Exp > 0 do
  610. begin
  611. Value := Value * 10;
  612. Dec(Exp);
  613. end;
  614. while Exp < 0 do
  615. begin
  616. Value := Value * 0.1;
  617. Inc(Exp);
  618. end;
  619. end;
  620. if N then
  621. Value := -Value;
  622. Result := True;
  623. end;
  624. function __parseTimezone(var P: PAnsiChar; const L: PAnsiChar; out T: TXsdTimezone): Boolean;
  625. var
  626. I: Integer;
  627. N: Boolean;
  628. begin
  629. { allow 'Z' }
  630. if (P < L) and (P^ = 'Z') then
  631. begin
  632. T.Kind := tzUTC;
  633. T.Hour := 0;
  634. T.Minute := 0;
  635. Inc(P);
  636. end else
  637. { allow '+' or '-' }
  638. if (P < L) and (P^ in ['+','-']) then
  639. begin
  640. T.Kind := tzLOCAL;
  641. N := P^ = '-';
  642. Inc(P);
  643. { expect 00..13 }
  644. T.Hour := 0; I := 2;
  645. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  646. begin
  647. T.Hour := 10*T.Hour + Ord(P^) - Ord('0');
  648. Dec(I); Inc(P);
  649. end;
  650. if T.Hour > 13 then
  651. Exit(False);
  652. if N then
  653. T.Hour := -T.Hour;
  654. { expect ':' }
  655. if (P >= L) or (P^ <> ':') then
  656. Exit(False);
  657. Inc(P);
  658. { expect 00..59 }
  659. T.Minute := 0; I := 2;
  660. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  661. begin
  662. T.Minute := 10*T.Minute + Ord(P^) - Ord('0');
  663. Dec(I); Inc(P);
  664. end;
  665. if T.Minute > 59 then
  666. Exit(False);
  667. end else
  668. { unknown }
  669. begin
  670. T.Kind := tzUNKNOWN;
  671. T.Hour := 0;
  672. T.Minute := 0;
  673. end;
  674. Result := True;
  675. end;
  676. function __parseDate(var P: PAnsiChar; const L: PAnsiChar; out Year, Month, Day: Longword; BC: PBoolean): Boolean;
  677. var
  678. I: Integer;
  679. begin
  680. { allow '-' }
  681. if (P < L) and (P^ = '-') then
  682. begin
  683. if Assigned(BC) then
  684. BC^ := True
  685. else
  686. Exit(False);
  687. Inc(P);
  688. end else
  689. if Assigned(BC) then
  690. BC^ := False;
  691. { expect Integer }
  692. Year := 0;
  693. while (P < L) and (P^ in ['0'..'9']) do
  694. begin
  695. Year := 10*Year + Ord(P^) - Ord('0');
  696. Inc(P);
  697. end;
  698. { expect '-' }
  699. if (P >= L) or (P^ <> '-') then
  700. Exit(False);
  701. Inc(P);
  702. { expect 01..12 }
  703. Month := 0; I := 2;
  704. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  705. begin
  706. Month := 10*Month + Ord(P^) - Ord('0');
  707. Dec(I); Inc(P);
  708. end;
  709. if (Month < 1) or (Month > 12) then
  710. Exit(False);
  711. { expect '-' }
  712. if (P >= L) or (P^ <> '-') then
  713. Exit(False);
  714. Inc(P);
  715. { expect 01..31 }
  716. Day := 0; I := 2;
  717. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  718. begin
  719. Day := 10*Day + Ord(P^) - Ord('0');
  720. Dec(I); Inc(P);
  721. end;
  722. if (Day < 1) or (Day > 31) then
  723. Exit(False);
  724. Result := True;
  725. end;
  726. function __parseTime(var P: PAnsiChar; const L: PAnsiChar; const AllowMoreThan24h: Boolean;
  727. out Hour, Minute, Second, Milliseconds: Longword): Boolean;
  728. var
  729. I: Integer;
  730. Ms: Longword;
  731. begin
  732. { expect 00..24 (except if AllowMoreThan24h) }
  733. Hour := 0;
  734. if AllowMoreThan24h then I := 9 { maximal 9 digits for hour } else I := 2;
  735. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  736. begin
  737. Hour := 10*Hour + Ord(P^) - Ord('0');
  738. Inc(P); Dec(I);
  739. end;
  740. if not AllowMoreThan24h and (Hour > 24) then
  741. Exit(False);
  742. { expect ':' }
  743. if (P >= L) or (P^ <> ':') then
  744. Exit(False);
  745. Inc(P);
  746. { expect 00..59 }
  747. Minute := 0; I := 2;
  748. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  749. begin
  750. Minute := 10*Minute + Ord(P^) - Ord('0');
  751. Dec(I); Inc(P);
  752. end;
  753. if (Minute > 59) or (not AllowMoreThan24h and (Hour = 24) and (Minute > 0)) then
  754. Exit(False);
  755. { expect ':' }
  756. if (P >= L) or (P^ <> ':') then
  757. Exit(False);
  758. Inc(P);
  759. { expect 00..59 }
  760. Second := 0; I := 2;
  761. while (P < L) and (P^ in ['0'..'9']) and (I > 0) do
  762. begin
  763. Second := 10*Second + Ord(P^) - Ord('0');
  764. Dec(I); Inc(P);
  765. end;
  766. if (Second > 59) or (not AllowMoreThan24h and (Hour = 24) and (Second > 0)) then
  767. Exit(False);
  768. { allow '.' }
  769. if (P < L) and (P^ = '.') then
  770. begin
  771. Inc(P);
  772. { expect integer }
  773. Ms := 0; I := 1;
  774. while (P < L) and (P^ in ['0'..'9']) do
  775. begin
  776. Ms := 10*Ms + Ord(P^) - Ord('0');
  777. I := 10*I;
  778. Inc(P);
  779. end;
  780. Milliseconds := (1000*Ms) div I;
  781. if (Milliseconds >= 999) or (not AllowMoreThan24h and (Hour = 24) and (Milliseconds > 0)) then
  782. Exit(False);
  783. end else
  784. Milliseconds := 0;
  785. Result := True;
  786. end;
  787. function xsdTryParseBase64(Chars: PAnsiChar; Len: Integer; const Value: TStream): Boolean;
  788. const
  789. BufferSize = 3*512;
  790. var
  791. Buffer: array[0..BufferSize-1] of Byte;
  792. Ofs: Integer;
  793. P,L: PByte;
  794. p1,p2,p3,p4: Shortint;
  795. begin
  796. if Assigned(Chars) then
  797. begin
  798. Ofs := 0;
  799. P := PByte(Chars);
  800. if Len >= 0 then
  801. begin
  802. if Len mod 4 <> 0 then
  803. Exit(False);
  804. L := P + Len;
  805. while P < L do
  806. begin
  807. case Chr(P^) of
  808. 'A'..'Z': p1 := P^ - Ord('A');
  809. 'a'..'z': p1 := P^ - Ord('a') + 26;
  810. '0'..'9': p1 := P^ - Ord('0') + 52;
  811. '+' : p1 := 62;
  812. '/' : p1 := 63;
  813. else Exit(False);
  814. end;
  815. Inc(P);
  816. case Chr(P^) of
  817. 'A'..'Z': p2 := P^ - Ord('A');
  818. 'a'..'z': p2 := P^ - Ord('a') + 26;
  819. '0'..'9': p2 := P^ - Ord('0') + 52;
  820. '+' : p2 := 62;
  821. '/' : p2 := 63;
  822. else Exit(False);
  823. end;
  824. Inc(P);
  825. case Chr(P^) of
  826. 'A'..'Z': p3 := P^ - Ord('A');
  827. 'a'..'z': p3 := P^ - Ord('a') + 26;
  828. '0'..'9': p3 := P^ - Ord('0') + 52;
  829. '+' : p3 := 62;
  830. '/' : p3 := 63;
  831. '=' : p3 := -1;
  832. else Exit(False);
  833. end;
  834. Inc(P);
  835. if (p3 >= 0) then
  836. begin
  837. case Chr(P^) of
  838. 'A'..'Z': p4 := P^ - Ord('A');
  839. 'a'..'z': p4 := P^ - Ord('a') + 26;
  840. '0'..'9': p4 := P^ - Ord('0') + 52;
  841. '+' : p4 := 62;
  842. '/' : p4 := 63;
  843. '=' : p4 := -1;
  844. else Exit(False);
  845. end;
  846. end else begin
  847. if P^ <> Ord('=') then
  848. Exit(False);
  849. p4 := -1;
  850. end;
  851. Inc(P);
  852. Buffer[Ofs] := (p1 shl 2) or (p2 shr 4);
  853. Ofs := Ofs + 1;
  854. if p3 >= 0 then
  855. begin
  856. Buffer[Ofs] := ((p2 and $F) shl 4) or (p3 shr 2);
  857. Ofs := Ofs + 1;
  858. if p4 >= 0 then
  859. begin
  860. Buffer[Ofs] := ((p3 and $3) shl 6) or p4;
  861. Ofs := Ofs + 1;
  862. end;
  863. end;
  864. if Ofs >= BufferSize-2 then
  865. begin
  866. Value.Write(Buffer, Ofs);
  867. Ofs := 0;
  868. end;
  869. end;
  870. end else begin
  871. while P^ <> 0 do
  872. begin
  873. case Chr(P^) of
  874. 'A'..'Z': p1 := P^ - Ord('A');
  875. 'a'..'z': p1 := P^ - Ord('a') + 26;
  876. '0'..'9': p1 := P^ - Ord('0') + 52;
  877. '+' : p1 := 62;
  878. '/' : p1 := 63;
  879. else Exit(False);
  880. end;
  881. Inc(P);
  882. case Chr(P^) of
  883. 'A'..'Z': p2 := P^ - Ord('A');
  884. 'a'..'z': p2 := P^ - Ord('a') + 26;
  885. '0'..'9': p2 := P^ - Ord('0') + 52;
  886. '+' : p2 := 62;
  887. '/' : p2 := 63;
  888. else Exit(False);
  889. end;
  890. Inc(P);
  891. case Chr(P^) of
  892. 'A'..'Z': p3 := P^ - Ord('A');
  893. 'a'..'z': p3 := P^ - Ord('a') + 26;
  894. '0'..'9': p3 := P^ - Ord('0') + 52;
  895. '+' : p3 := 62;
  896. '/' : p3 := 63;
  897. '=' : p3 := -1;
  898. else Exit(False);
  899. end;
  900. Inc(P);
  901. if (p3 >= 0) then
  902. begin
  903. case Chr(P^) of
  904. 'A'..'Z': p4 := P^ - Ord('A');
  905. 'a'..'z': p4 := P^ - Ord('a') + 26;
  906. '0'..'9': p4 := P^ - Ord('0') + 52;
  907. '+' : p4 := 62;
  908. '/' : p4 := 63;
  909. '=' : p4 := -1;
  910. else Exit(False);
  911. end;
  912. end else begin
  913. if P^ <> Ord('=') then
  914. Exit(False);
  915. p4 := -1;
  916. end;
  917. Inc(P);
  918. Buffer[Ofs] := (p1 shl 2) or (p2 shr 4);
  919. Ofs := Ofs + 1;
  920. if p3 >= 0 then
  921. begin
  922. Buffer[Ofs] := ((p2 and $F) shl 4) or (p3 shr 2);
  923. Ofs := Ofs + 1;
  924. if p4 >= 0 then
  925. begin
  926. Buffer[Ofs] := ((p3 and $3) shl 6) or p4;
  927. Ofs := Ofs + 1;
  928. end;
  929. end;
  930. if Ofs >= BufferSize-2 then
  931. begin
  932. Value.Write(Buffer, Ofs);
  933. Ofs := 0;
  934. end;
  935. end;
  936. end;
  937. if Ofs > 0 then // flush
  938. Value.Write(Buffer, Ofs);
  939. Result := True;
  940. end else
  941. Result := False;
  942. end;
  943. function xsdTryParseString(Chars: PAnsiChar; Len: Integer; out Value: AnsiString): Boolean;
  944. const
  945. AllocChars = 256;
  946. var
  947. P,L,D: PByte;
  948. begin
  949. if Assigned(Chars) then
  950. begin
  951. P := PByte(Chars);
  952. if Len >= 0 then
  953. begin
  954. L := P + Len;
  955. SetLength(Value, Len);
  956. D := @Value[1];
  957. while P < L do
  958. begin
  959. D^ := P^;
  960. Inc(D);
  961. Inc(P);
  962. end;
  963. end else begin
  964. SetLength(Value, AllocChars);
  965. D := @Value[1];
  966. L := D + AllocChars;
  967. while P^ <> 0 do
  968. begin
  969. if D = L then
  970. begin
  971. Len := Length(Value);
  972. SetLength(Value, Len+AllocChars);
  973. D := @Value[Len+1];
  974. L := D + AllocChars;
  975. end;
  976. D^ := P^;
  977. Inc(D);
  978. Inc(P);
  979. end;
  980. SetLength(Value, P-PByte(Chars));
  981. end;
  982. Result := True;
  983. end else
  984. Result := False;
  985. end;
  986. {begin
  987. if Assigned(Chars) then
  988. begin
  989. if Len >= 0 then
  990. begin
  991. SetLength(Value, Len);
  992. Move(Chars^, Value[1], Len);
  993. end else
  994. Value := PAnsiChar(Chars);
  995. Result := True;
  996. end else
  997. Result := False;
  998. end;}
  999. function xsdTryParseStringLower(Chars: PAnsiChar; Len: Integer; out Value: AnsiString): Boolean;
  1000. const
  1001. AllocChars = 256;
  1002. var
  1003. P,L,D: PByte;
  1004. C: Byte;
  1005. begin
  1006. if Assigned(Chars) then
  1007. begin
  1008. P := PByte(Chars);
  1009. if Len >= 0 then
  1010. begin
  1011. L := P + Len;
  1012. SetLength(Value, Len);
  1013. D := @Value[1];
  1014. while P < L do
  1015. begin
  1016. C := P^;
  1017. if (C>=65) and (C<=90) then Inc(C, 32);
  1018. D^ := C;
  1019. Inc(D);
  1020. Inc(P);
  1021. end;
  1022. end else begin
  1023. SetLength(Value, AllocChars);
  1024. D := @Value[1];
  1025. L := D + AllocChars;
  1026. while P^ <> 0 do
  1027. begin
  1028. C := P^;
  1029. if (C>=65) and (C<=90) then Inc(C, 32);
  1030. if D = L then
  1031. begin
  1032. Len := Length(Value);
  1033. SetLength(Value, Len+AllocChars);
  1034. D := @Value[Len+1];
  1035. L := D + AllocChars;
  1036. end;
  1037. D^ := C;
  1038. Inc(D);
  1039. Inc(P);
  1040. end;
  1041. SetLength(Value, P-PByte(Chars));
  1042. end;
  1043. Result := True;
  1044. end else
  1045. Result := False;
  1046. end;
  1047. function __strpas(Chars: PAnsiChar; Len: Integer): AnsiString;
  1048. begin
  1049. if not xsdTryParseString(Chars, Len, Result) then
  1050. Result := '';
  1051. end;
  1052. function xsdTryParseBoolean(Chars: PAnsiChar; Len: Integer; out Value: Boolean): Boolean;
  1053. var
  1054. P: PAnsiChar;
  1055. Num: QWord;
  1056. begin
  1057. if not Assigned(Chars) then
  1058. Exit(False);
  1059. if Len < 0 then
  1060. begin
  1061. P := PAnsiChar(Chars);
  1062. Len := 0;
  1063. while (Len < 7) and (P^ <> #0) do
  1064. begin
  1065. Inc(Len);
  1066. Inc(P);
  1067. end;
  1068. end;
  1069. case Len of
  1070. 1: Num := PByte(Chars)^;
  1071. 4: Num := PLongword(Chars)^;
  1072. 5: Num := PLongword(Chars)^ or (QWord(Chars[4]) shl 32);
  1073. else Exit(False);
  1074. end;
  1075. case Num of
  1076. $30,
  1077. $65736C6166,$65736C6146,$65736C4166,$65736C4146,$65734C6166,$65734C6146,$65734C4166,$65734C4146,
  1078. $65536C6166,$65536C6146,$65536C4166,$65536C4146,$65534C6166,$65534C6146,$65534C4166,$65534C4146,
  1079. $45736C6166,$45736C6146,$45736C4166,$45736C4146,$45734C6166,$45734C6146,$45734C4166,$45734C4146,
  1080. $45536C6166,$45536C6146,$45536C4166,$45536C4146,$45534C6166,$45534C6146,$45534C4166,$45534C4146:
  1081. Value := False;
  1082. $31,
  1083. $65757274,$65757254,$65755274,$65755254,$65557274,$65557254,$65555274,$65555254,
  1084. $45757274,$45757254,$45755274,$45755254,$45557274,$45557254,$45555274,$45555254:
  1085. Value := True;
  1086. else Exit(False);
  1087. end;
  1088. Result := True;
  1089. end;
  1090. function xsdTryParseDate(Chars: PAnsiChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone; BC: PBoolean): Boolean;
  1091. var
  1092. P: PAnsiChar;
  1093. L: PAnsiChar;
  1094. T: TXsdTimezone;
  1095. begin
  1096. P := PAnsiChar(Chars);
  1097. if Len >= 0 then
  1098. begin
  1099. L := P + Len;
  1100. Result := Assigned(P) and
  1101. __parseDate(P, L, Year, Month, Day, BC) and
  1102. __parseTimezone(P, L, T) and (P = L)
  1103. end else
  1104. Result := Assigned(P) and
  1105. __parseDate(P, XSD_IGNORE_LAST, Year, Month, Day, BC) and
  1106. __parseTimezone(P, XSD_IGNORE_LAST, T) and (P^ = #0);
  1107. { assign Timezone if requested }
  1108. if Result and Assigned(Timezone) then
  1109. Timezone^ := T;
  1110. end;
  1111. function xsdTryParseDate(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone): Boolean;
  1112. var
  1113. Year, Month, Day: Longword;
  1114. begin
  1115. if xsdTryParseDate(Chars, Len, Year, Month, Day, Timezone, nil) then
  1116. Result := TryEncodeDate(Year, Month, Day, Value)
  1117. else
  1118. Result := False;
  1119. end;
  1120. function xsdTryParseTime(Chars: PAnsiChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone): Boolean;
  1121. var
  1122. P: PAnsiChar;
  1123. L: PAnsiChar;
  1124. T: TXsdTimezone;
  1125. begin
  1126. P := PAnsiChar(Chars);
  1127. if Len >= 0 then
  1128. begin
  1129. L := P + Len;
  1130. Result := Assigned(P) and
  1131. __parseTime(P, L, False, Hour, Minute, Second, Milliseconds) and
  1132. __parseTimezone(P, L, T) and (P = L)
  1133. end else
  1134. Result := Assigned(P) and
  1135. __parseTime(P, XSD_IGNORE_LAST, False, Hour, Minute, Second, Milliseconds) and
  1136. __parseTimezone(P, XSD_IGNORE_LAST, T) and (P^ = #0);
  1137. { assign Timezone if requested }
  1138. if Result and Assigned(Timezone) then
  1139. Timezone^ := T;
  1140. end;
  1141. function xsdTryParseTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone): Boolean;
  1142. var
  1143. Hour, Minute, Second, Milliseconds: Longword;
  1144. begin
  1145. if xsdTryParseTime(Chars, Len, Hour, Minute, Second, Milliseconds, Timezone) then
  1146. Result := TryEncodeTime(Hour, Minute, Second, Milliseconds, Value)
  1147. else
  1148. Result := False;
  1149. end;
  1150. function xsdTryParseDateTime(Chars: PAnsiChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean): Boolean;
  1151. function __parseT(var P: PAnsiChar; const L: PAnsiChar): Boolean;
  1152. begin
  1153. Result := (P < L) and (P^ = 'T');
  1154. if Result then Inc(P);
  1155. end;
  1156. var
  1157. P: PAnsiChar;
  1158. L: PAnsiChar;
  1159. T: TXsdTimezone;
  1160. begin
  1161. P := PAnsiChar(Chars);
  1162. if Len >= 0 then
  1163. begin
  1164. L := P + Len;
  1165. Result := Assigned(P) and
  1166. __parseDate(P, L, Year, Month, Day, BC) and
  1167. __parseT(P, L) and
  1168. __parseTime(P, L, False, Hour, Minute, Second, Milliseconds) and
  1169. __parseTimezone(P, L, T) and (P = L)
  1170. end else
  1171. Result := Assigned(P) and
  1172. __parseDate(P, XSD_IGNORE_LAST, Year, Month, Day, BC) and
  1173. __parseT(P, XSD_IGNORE_LAST) and
  1174. __parseTime(P, XSD_IGNORE_LAST, False, Hour, Minute, Second, Milliseconds) and
  1175. __parseTimezone(P, XSD_IGNORE_LAST, T) and (P^ = #0);
  1176. { assign Timezone if requested }
  1177. if Result and Assigned(Timezone) then
  1178. Timezone^ := T;
  1179. end;
  1180. function xsdTryParseDateTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone): Boolean;
  1181. var
  1182. Year, Month, Day: Longword;
  1183. Hour, Minute, Second, Milliseconds: Longword;
  1184. begin
  1185. if xsdTryParseDateTime(Chars, Len, Year, Month, Day, Hour, Minute, Second, Milliseconds, Timezone) then
  1186. Result := TryEncodeDateTime(Year, Month, Day, Hour, Minute, Second, Milliseconds, Value)
  1187. else
  1188. Result := False;
  1189. end;
  1190. function xsdTryParseDecimal(Chars: PAnsiChar; Len: Integer; out Value: Extended): Boolean;
  1191. var
  1192. P: PAnsiChar;
  1193. L: PAnsiChar;
  1194. begin
  1195. P := PAnsiChar(Chars);
  1196. if Len >= 0 then
  1197. begin
  1198. L := P + Len;
  1199. Result := Assigned(P) and __parseFloat(P, L, Value) and (P = L)
  1200. end else
  1201. Result := Assigned(P) and __parseFloat(P, XSD_IGNORE_LAST, Value) and (P^ = #0);
  1202. end;
  1203. function xsdTryParseDouble(Chars: PAnsiChar; Len: Integer; out Value: Double): Boolean;
  1204. var
  1205. P: PAnsiChar;
  1206. L: PAnsiChar;
  1207. Tmp: Extended;
  1208. begin
  1209. P := PAnsiChar(Chars);
  1210. if Len >= 0 then
  1211. begin
  1212. L := P + Len;
  1213. Result := Assigned(P) and __parseFloat(P, L, Tmp) and (P = L)
  1214. end else
  1215. Result := Assigned(P) and __parseFloat(P, XSD_IGNORE_LAST, Tmp) and (P^ = #0);
  1216. Value := Tmp;
  1217. end;
  1218. function xsdTryParseFloat(Chars: PAnsiChar; Len: Integer; out Value: Single): Boolean;
  1219. var
  1220. P: PAnsiChar;
  1221. L: PAnsiChar;
  1222. Tmp: Extended;
  1223. begin
  1224. P := PAnsiChar(Chars);
  1225. if Len >= 0 then
  1226. begin
  1227. L := P + Len;
  1228. Result := Assigned(P) and __parseFloat(P, L, Tmp) and (P = L)
  1229. end else
  1230. Result := Assigned(P) and __parseFloat(P, XSD_IGNORE_LAST, Tmp) and (P^ = #0);
  1231. Value := Tmp;
  1232. end;
  1233. function xsdTryParseInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  1234. var
  1235. P: PAnsiChar;
  1236. L: PAnsiChar;
  1237. begin
  1238. P := PAnsiChar(Chars);
  1239. if Len >= 0 then
  1240. begin
  1241. L := P + Len;
  1242. Result := Assigned(P) and __parseInteger(P, L, Value) and (P = L)
  1243. end else
  1244. Result := Assigned(P) and __parseInteger(P, XSD_IGNORE_LAST, Value) and (P^ = #0);
  1245. end;
  1246. function xsdTryParseNonNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord): Boolean;
  1247. var
  1248. P: PAnsiChar;
  1249. L: PAnsiChar;
  1250. begin
  1251. P := PAnsiChar(Chars);
  1252. if Len >= 0 then
  1253. begin
  1254. L := P + Len;
  1255. Result := Assigned(P) and __parseNonNegativeInteger(P, L, Value) and (P = L)
  1256. end else
  1257. Result := Assigned(P) and __parseNonNegativeInteger(P, XSD_IGNORE_LAST, Value) and (P^ = #0);
  1258. end;
  1259. function xsdTryParseNonPositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  1260. begin
  1261. Result := xsdTryParseInteger(Chars, Len, Value) and (Value <= 0);
  1262. end;
  1263. function xsdTryParseNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  1264. begin
  1265. Result := xsdTryParseInteger(Chars, Len, Value) and (Value <= -1);
  1266. end;
  1267. function xsdTryParsePositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord): Boolean;
  1268. begin
  1269. Result := xsdTryParseNonNegativeInteger(Chars, Len, Value) and (Value >= 1);
  1270. end;
  1271. function xsdTryParseByte(Chars: PAnsiChar; Len: Integer; out Value: Shortint): Boolean;
  1272. var
  1273. Tmp: Int64;
  1274. begin
  1275. Result := xsdTryParseInteger(Chars, Len, Tmp) and (Tmp <= 128) and (Tmp >= -127);
  1276. Value := Tmp;
  1277. end;
  1278. function xsdTryParseShort(Chars: PAnsiChar; Len: Integer; out Value: Smallint): Boolean;
  1279. var
  1280. Tmp: Int64;
  1281. begin
  1282. Result := xsdTryParseInteger(Chars, Len, Tmp) and (Tmp <= 32767) and (Tmp >= -32768);
  1283. Value := Tmp;
  1284. end;
  1285. function xsdTryParseInt(Chars: PAnsiChar; Len: Integer; out Value: Longint): Boolean;
  1286. var
  1287. Tmp: Int64;
  1288. begin
  1289. Result := xsdTryParseInteger(Chars, Len, Tmp) and (Tmp <= 2147483647) and (Tmp >= -2147483648);
  1290. Value := Tmp;
  1291. end;
  1292. function xsdTryParseLong(Chars: PAnsiChar; Len: Integer; out Value: Int64): Boolean;
  1293. begin
  1294. Result := xsdTryParseInteger(Chars, Len, Value);
  1295. end;
  1296. function xsdTryParseUnsignedByte(Chars: PAnsiChar; Len: Integer; out Value: Byte): Boolean;
  1297. var
  1298. Tmp: QWord;
  1299. begin
  1300. Result := xsdTryParseNonNegativeInteger(Chars, Len, Tmp) and (Tmp <= 255);
  1301. Value := Tmp;
  1302. end;
  1303. function xsdTryParseUnsignedShort(Chars: PAnsiChar; Len: Integer; out Value: Word): Boolean;
  1304. var
  1305. Tmp: QWord;
  1306. begin
  1307. Result := xsdTryParseNonNegativeInteger(Chars, Len, Tmp) and (Tmp <= 65535);
  1308. Value := Tmp;
  1309. end;
  1310. function xsdTryParseUnsignedInt(Chars: PAnsiChar; Len: Integer; out Value: Longword): Boolean;
  1311. var
  1312. Tmp: QWord;
  1313. begin
  1314. Result := xsdTryParseNonNegativeInteger(Chars, Len, Tmp) and (Tmp <= 4294967295);
  1315. Value := Tmp;
  1316. end;
  1317. function xsdTryParseUnsignedLong(Chars: PAnsiChar; Len: Integer; out Value: QWord): Boolean;
  1318. begin
  1319. Result := xsdTryParseNonNegativeInteger(Chars, Len, Value)
  1320. end;
  1321. function xsdTryParseEnum(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString; out Value: Integer): Boolean;
  1322. var
  1323. Temp: AnsiString;
  1324. I: Integer;
  1325. begin
  1326. Temp := '';
  1327. Result := xsdTryParseString(Chars, Len, Temp);
  1328. if Result then
  1329. begin
  1330. for I := 0 to High(enum) do
  1331. if Temp = enum[I] then
  1332. begin
  1333. Value := I;
  1334. Exit(True);
  1335. end;
  1336. Result := False;
  1337. end;
  1338. end;
  1339. function xsdParseStringDef(Chars: PAnsiChar; Len: Integer; Default: AnsiString): AnsiString;
  1340. begin
  1341. if not xsdTryParseString(Chars, Len, Result) then
  1342. Result := Default;
  1343. end;
  1344. function xsdParseStringLowerDef(Chars: PAnsiChar; Len: Integer; Default: AnsiString): AnsiString;
  1345. begin
  1346. if not xsdTryParseStringLower(Chars, Len, Result) then
  1347. Result := Default;
  1348. end;
  1349. function xsdParseBooleanDef(Chars: PAnsiChar; Len: Integer; Default: Boolean): Boolean;
  1350. begin
  1351. if not xsdTryParseBoolean(Chars, Len, Result) then
  1352. Result := Default;
  1353. end;
  1354. function xsdParseDateDef(Chars: PAnsiChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone): TDateTime;
  1355. begin
  1356. if not xsdTryParseDate(Chars, Len, Result, Timezone) then
  1357. Result := Default;
  1358. end;
  1359. function xsdParseTimeDef(Chars: PAnsiChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone): TDateTime;
  1360. begin
  1361. if not xsdTryParseTime(Chars, Len, Result, Timezone) then
  1362. Result := Default;
  1363. end;
  1364. function xsdParseDateTimeDef(Chars: PAnsiChar; Len: Integer; Default: TDateTime; Timezone: PXsdTimezone): TDateTime;
  1365. begin
  1366. if not xsdTryParseDateTime(Chars, Len, Result, Timezone) then
  1367. Result := Default;
  1368. end;
  1369. function xsdParseDecimalDef(Chars: PAnsiChar; Len: Integer; Default: Extended): Extended;
  1370. begin
  1371. if not xsdTryParseDecimal(Chars, Len, Result) then
  1372. Result := Default;
  1373. end;
  1374. function xsdParseDoubleDef(Chars: PAnsiChar; Len: Integer; Default: Double): Double;
  1375. begin
  1376. if not xsdTryParseDouble(Chars, Len, Result) then
  1377. Result := Default;
  1378. end;
  1379. function xsdParseFloatDef(Chars: PAnsiChar; Len: Integer; Default: Single): Single;
  1380. begin
  1381. if not xsdTryParseFloat(Chars, Len, Result) then
  1382. Result := Default;
  1383. end;
  1384. function xsdParseIntegerDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  1385. begin
  1386. if not xsdTryParseInteger(Chars, Len, Result) then
  1387. Result := Default;
  1388. end;
  1389. function xsdParseNonNegativeIntegerDef(Chars: PAnsiChar; Len: Integer; Default: QWord): QWord;
  1390. begin
  1391. if not xsdTryParseNonNegativeInteger(Chars, Len, Result) then
  1392. Result := Default;
  1393. end;
  1394. function xsdParseNonPositiveIntegerDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  1395. begin
  1396. if not xsdTryParseNonPositiveInteger(Chars, Len, Result) then
  1397. Result := Default;
  1398. end;
  1399. function xsdParseNegativeIntegerDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  1400. begin
  1401. if not xsdTryParseNegativeInteger(Chars, Len, Result) then
  1402. Result := Default;
  1403. end;
  1404. function xsdParsePositiveIntegerDef(Chars: PAnsiChar; Len: Integer; Default: QWord): QWord;
  1405. begin
  1406. if not xsdTryParsePositiveInteger(Chars, Len, Result) then
  1407. Result := Default;
  1408. end;
  1409. function xsdParseByteDef(Chars: PAnsiChar; Len: Integer; Default: Shortint): Shortint;
  1410. begin
  1411. if not xsdTryParseByte(Chars, Len, Result) then
  1412. Result := Default;
  1413. end;
  1414. function xsdParseShortDef(Chars: PAnsiChar; Len: Integer; Default: Smallint): Smallint;
  1415. begin
  1416. if not xsdTryParseShort(Chars, Len, Result) then
  1417. Result := Default;
  1418. end;
  1419. function xsdParseIntDef(Chars: PAnsiChar; Len: Integer; Default: Longint): Longint;
  1420. begin
  1421. if not xsdTryParseInt(Chars, Len, Result) then
  1422. Result := Default;
  1423. end;
  1424. function xsdParseLongDef(Chars: PAnsiChar; Len: Integer; Default: Int64): Int64;
  1425. begin
  1426. if not xsdTryParseLong(Chars, Len, Result) then
  1427. Result := Default;
  1428. end;
  1429. function xsdParseUnsignedByteDef(Chars: PAnsiChar; Len: Integer; Default: Byte): Byte;
  1430. begin
  1431. if not xsdTryParseUnsignedByte(Chars, Len, Result) then
  1432. Result := Default;
  1433. end;
  1434. function xsdParseUnsignedShortDef(Chars: PAnsiChar; Len: Integer; Default: Word): Word;
  1435. begin
  1436. if not xsdTryParseUnsignedShort(Chars, Len, Result) then
  1437. Result := Default;
  1438. end;
  1439. function xsdParseUnsignedIntDef(Chars: PAnsiChar; Len: Integer; Default: Longword): Longword;
  1440. begin
  1441. if not xsdTryParseUnsignedInt(Chars, Len, Result) then
  1442. Result := Default;
  1443. end;
  1444. function xsdParseUnsignedLongDef(Chars: PAnsiChar; Len: Integer; Default: QWord): QWord;
  1445. begin
  1446. if not xsdTryParseUnsignedLong(Chars, Len, Result) then
  1447. Result := Default;
  1448. end;
  1449. function xsdParseEnumDef(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString; Default: Integer): Integer;
  1450. begin
  1451. if not xsdTryParseEnum(Chars, Len, enum, Result) then
  1452. Result := Default;
  1453. end;
  1454. procedure xsdParseBase64(Chars: PAnsiChar; Len: Integer; const Value: TStream);
  1455. begin
  1456. if not xsdTryParseBase64(Chars, Len, Value) then
  1457. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:base64Binary']);
  1458. end;
  1459. procedure xsdParseString(Chars: PAnsiChar; Len: Integer; out Value: AnsiString);
  1460. begin
  1461. if not xsdTryParseString(Chars, Len, Value) then
  1462. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:string']);
  1463. end;
  1464. procedure xsdParseStringLower(Chars: PAnsiChar; Len: Integer; out Value: AnsiString);
  1465. begin
  1466. if not xsdTryParseStringLower(Chars, Len, Value) then
  1467. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:string']);
  1468. end;
  1469. procedure xsdParseBoolean(Chars: PAnsiChar; Len: Integer; out Value: Boolean);
  1470. begin
  1471. if not xsdTryParseBoolean(Chars, Len, Value) then
  1472. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:boolean']);
  1473. end;
  1474. procedure xsdParseDate(Chars: PAnsiChar; Len: Integer; out Year, Month, Day: Longword; Timezone: PXsdTimezone; BC: PBoolean);
  1475. begin
  1476. if not xsdTryParseDate(Chars, Len, Year, Month, Day, Timezone, BC) then
  1477. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:date']);
  1478. end;
  1479. procedure xsdParseDate(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone);
  1480. begin
  1481. if not xsdTryParseDate(Chars, Len, Value, Timezone) then
  1482. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:date']);
  1483. end;
  1484. procedure xsdParseTime(Chars: PAnsiChar; Len: Integer; out Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone);
  1485. begin
  1486. if not xsdTryParseTime(Chars, Len, Hour, Minute, Second, Milliseconds, Timezone) then
  1487. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:time']);
  1488. end;
  1489. procedure xsdParseTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone);
  1490. begin
  1491. if not xsdTryParseTime(Chars, Len, Value, Timezone) then
  1492. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:time']);
  1493. end;
  1494. procedure xsdParseDateTime(Chars: PAnsiChar; Len: Integer; out Year, Month, Day, Hour, Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean);
  1495. begin
  1496. if not xsdTryParseDateTime(Chars, Len, Year, Month, Day, Hour, Minute, Second, Milliseconds, Timezone, BC) then
  1497. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:dateTime']);
  1498. end;
  1499. procedure xsdParseDateTime(Chars: PAnsiChar; Len: Integer; out Value: TDateTime; Timezone: PXsdTimezone);
  1500. begin
  1501. if not xsdTryParseDateTime(Chars, Len, Value, Timezone) then
  1502. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:dateTime']);
  1503. end;
  1504. procedure xsdParseDecimal(Chars: PAnsiChar; Len: Integer; out Value: Extended);
  1505. begin
  1506. if not xsdTryParseDecimal(Chars, Len, Value) then
  1507. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:decimal']);
  1508. end;
  1509. procedure xsdParseDouble(Chars: PAnsiChar; Len: Integer; out Value: Double);
  1510. begin
  1511. if not xsdTryParseDouble(Chars, Len, Value) then
  1512. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:double']);
  1513. end;
  1514. procedure xsdParseFloat(Chars: PAnsiChar; Len: Integer; out Value: Single);
  1515. begin
  1516. if not xsdTryParseFloat(Chars, Len, Value) then
  1517. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:float']);
  1518. end;
  1519. procedure xsdParseInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  1520. begin
  1521. if not xsdTryParseInteger(Chars, Len, Value) then
  1522. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:integer']);
  1523. end;
  1524. procedure xsdParseNonNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord);
  1525. begin
  1526. if not xsdTryParseNonNegativeInteger(Chars, Len, Value) then
  1527. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:nonNegativeInteger']);
  1528. end;
  1529. procedure xsdParseNonPositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  1530. begin
  1531. if not xsdTryParseNonPositiveInteger(Chars, Len, Value) then
  1532. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:nonPositiveInteger']);
  1533. end;
  1534. procedure xsdParseNegativeInteger(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  1535. begin
  1536. if not xsdTryParseNegativeInteger(Chars, Len, Value) then
  1537. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:negativeInteger']);
  1538. end;
  1539. procedure xsdParsePositiveInteger(Chars: PAnsiChar; Len: Integer; out Value: QWord);
  1540. begin
  1541. if not xsdTryParsePositiveInteger(Chars, Len, Value) then
  1542. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:positiveInteger']);
  1543. end;
  1544. procedure xsdParseByte(Chars: PAnsiChar; Len: Integer; out Value: Shortint);
  1545. begin
  1546. if not xsdTryParseByte(Chars, Len, Value) then
  1547. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:byte']);
  1548. end;
  1549. procedure xsdParseShort(Chars: PAnsiChar; Len: Integer; out Value: Smallint);
  1550. begin
  1551. if not xsdTryParseShort(Chars, Len, Value) then
  1552. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:short']);
  1553. end;
  1554. procedure xsdParseInt(Chars: PAnsiChar; Len: Integer; out Value: Longint);
  1555. begin
  1556. if not xsdTryParseInt(Chars, Len, Value) then
  1557. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:int']);
  1558. end;
  1559. procedure xsdParseLong(Chars: PAnsiChar; Len: Integer; out Value: Int64);
  1560. begin
  1561. if not xsdTryParseLong(Chars, Len, Value) then
  1562. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:long']);
  1563. end;
  1564. procedure xsdParseUnsignedByte(Chars: PAnsiChar; Len: Integer; out Value: Byte);
  1565. begin
  1566. if not xsdTryParseUnsignedByte(Chars, Len, Value) then
  1567. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedByte']);
  1568. end;
  1569. procedure xsdParseUnsignedShort(Chars: PAnsiChar; Len: Integer; out Value: Word);
  1570. begin
  1571. if not xsdTryParseUnsignedShort(Chars, Len, Value) then
  1572. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedShort']);
  1573. end;
  1574. procedure xsdParseUnsignedInt(Chars: PAnsiChar; Len: Integer; out Value: Longword);
  1575. begin
  1576. if not xsdTryParseUnsignedInt(Chars, Len, Value) then
  1577. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedInt']);
  1578. end;
  1579. procedure xsdParseUnsignedLong(Chars: PAnsiChar; Len: Integer; out Value: QWord);
  1580. begin
  1581. if not xsdTryParseUnsignedLong(Chars, Len, Value) then
  1582. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:unsignedLong']);
  1583. end;
  1584. procedure xsdParseEnum(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString; out Value: Integer);
  1585. begin
  1586. if not xsdTryParseEnum(Chars, Len, enum, Value) then
  1587. raise EConvertError.CreateFmt(SXsdParserError, [__strpas(Chars,Len), 'xs:enum']);
  1588. end;
  1589. function xsdParseString(Chars: PAnsiChar; Len: Integer): AnsiString;
  1590. begin
  1591. xsdParseString(Chars, Len, Result);
  1592. end;
  1593. function xsdParseStringLower(Chars: PAnsiChar; Len: Integer): AnsiString;
  1594. begin
  1595. xsdParseStringLower(Chars, Len, Result);
  1596. end;
  1597. function xsdParseBoolean(Chars: PAnsiChar; Len: Integer): Boolean;
  1598. begin
  1599. xsdParseBoolean(Chars, Len, Result);
  1600. end;
  1601. function xsdParseDate(Chars: PAnsiChar; Len: Integer; Timezone: PXsdTimezone): TDateTime;
  1602. begin
  1603. xsdParseDate(Chars, Len, Result, Timezone);
  1604. end;
  1605. function xsdParseTime(Chars: PAnsiChar; Len: Integer; Timezone: PXsdTimezone): TDateTime;
  1606. begin
  1607. xsdParseTime(Chars, Len, Result, Timezone);
  1608. end;
  1609. function xsdParseDateTime(Chars: PAnsiChar; Len: Integer; Timezone: PXsdTimezone): TDateTime;
  1610. begin
  1611. xsdParseDateTime(Chars, Len, Result, Timezone);
  1612. end;
  1613. function xsdParseDecimal(Chars: PAnsiChar; Len: Integer): Extended;
  1614. begin
  1615. xsdParseDecimal(Chars, Len, Result);
  1616. end;
  1617. function xsdParseDouble(Chars: PAnsiChar; Len: Integer): Double;
  1618. begin
  1619. xsdParseDouble(Chars, Len, Result);
  1620. end;
  1621. function xsdParseFloat(Chars: PAnsiChar; Len: Integer): Single;
  1622. begin
  1623. xsdParseFloat(Chars, Len, Result);
  1624. end;
  1625. function xsdParseInteger(Chars: PAnsiChar; Len: Integer): Int64;
  1626. begin
  1627. xsdParseInteger(Chars, Len, Result);
  1628. end;
  1629. function xsdParseNonNegativeInteger(Chars: PAnsiChar; Len: Integer): QWord;
  1630. begin
  1631. xsdParseNonNegativeInteger(Chars, Len, Result);
  1632. end;
  1633. function xsdParseNonPositiveInteger(Chars: PAnsiChar; Len: Integer): Int64;
  1634. begin
  1635. xsdParseNonPositiveInteger(Chars, Len, Result);
  1636. end;
  1637. function xsdParseNegativeInteger(Chars: PAnsiChar; Len: Integer): Int64;
  1638. begin
  1639. xsdParseNegativeInteger(Chars, Len, Result);
  1640. end;
  1641. function xsdParsePositiveInteger(Chars: PAnsiChar; Len: Integer): QWord;
  1642. begin
  1643. xsdParsePositiveInteger(Chars, Len, Result);
  1644. end;
  1645. function xsdParseByte(Chars: PAnsiChar; Len: Integer): Shortint;
  1646. begin
  1647. xsdParseByte(Chars, Len, Result);
  1648. end;
  1649. function xsdParseShort(Chars: PAnsiChar; Len: Integer): Smallint;
  1650. begin
  1651. xsdParseShort(Chars, Len, Result);
  1652. end;
  1653. function xsdParseInt(Chars: PAnsiChar; Len: Integer): Longint;
  1654. begin
  1655. xsdParseInt(Chars, Len, Result);
  1656. end;
  1657. function xsdParseLong(Chars: PAnsiChar; Len: Integer): Int64;
  1658. begin
  1659. xsdParseLong(Chars, Len, Result);
  1660. end;
  1661. function xsdParseUnsignedByte(Chars: PAnsiChar; Len: Integer): Byte;
  1662. begin
  1663. xsdParseUnsignedByte(Chars, Len, Result);
  1664. end;
  1665. function xsdParseUnsignedShort(Chars: PAnsiChar; Len: Integer): Word;
  1666. begin
  1667. xsdParseUnsignedShort(Chars, Len, Result);
  1668. end;
  1669. function xsdParseUnsignedInt(Chars: PAnsiChar; Len: Integer): Longword;
  1670. begin
  1671. xsdParseUnsignedInt(Chars, Len, Result);
  1672. end;
  1673. function xsdParseUnsignedLong(Chars: PAnsiChar; Len: Integer): QWord;
  1674. begin
  1675. xsdParseUnsignedLong(Chars, Len, Result);
  1676. end;
  1677. function xsdParseEnum(Chars: PAnsiChar; Len: Integer; enum: array of AnsiString): Integer;
  1678. begin
  1679. xsdParseEnum(Chars, Len, enum, Result);
  1680. end;
  1681. (*
  1682. function xsdTryParseBase64(const S: AnsiString; const Value: TStream): Boolean;
  1683. begin
  1684. end;
  1685. function xsdTryParseString(const S: AnsiString; out Value: AnsiString): Boolean;
  1686. begin
  1687. end;
  1688. function xsdTryParseStringLower(const S: AnsiString; out Value: AnsiString
  1689. ): Boolean;
  1690. begin
  1691. end;
  1692. function xsdTryParseBoolean(const S: AnsiString; out Value: Boolean): Boolean;
  1693. begin
  1694. end;
  1695. function xsdTryParseDate(const S: AnsiString; out Year, Month, Day: Longword;
  1696. Timezone: PXsdTimezone; BC: PBoolean): Boolean;
  1697. begin
  1698. end;
  1699. function xsdTryParseDate(const S: AnsiString; out Value: TDateTime;
  1700. Timezone: PXsdTimezone): Boolean;
  1701. begin
  1702. end;
  1703. function xsdTryParseTime(const S: AnsiString; out Hour, Minute, Second,
  1704. Milliseconds: Longword; Timezone: PXsdTimezone): Boolean;
  1705. begin
  1706. end;
  1707. function xsdTryParseTime(const S: AnsiString; out Value: TDateTime;
  1708. Timezone: PXsdTimezone): Boolean;
  1709. begin
  1710. end;
  1711. function xsdTryParseDateTime(const S: AnsiString; out Year, Month, Day, Hour,
  1712. Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean
  1713. ): Boolean;
  1714. begin
  1715. end;
  1716. function xsdTryParseDateTime(const S: AnsiString; out Value: TDateTime;
  1717. Timezone: PXsdTimezone): Boolean;
  1718. begin
  1719. end;
  1720. function xsdTryParseDecimal(const S: AnsiString; out Value: Extended): Boolean;
  1721. begin
  1722. end;
  1723. function xsdTryParseDouble(const S: AnsiString; out Value: Double): Boolean;
  1724. begin
  1725. end;
  1726. function xsdTryParseFloat(const S: AnsiString; out Value: Single): Boolean;
  1727. begin
  1728. end;
  1729. function xsdTryParseInteger(const S: AnsiString; out Value: Int64): Boolean;
  1730. begin
  1731. end;
  1732. function xsdTryParseNonNegativeInteger(const S: AnsiString; out Value: QWord
  1733. ): Boolean;
  1734. begin
  1735. end;
  1736. function xsdTryParseNonPositiveInteger(const S: AnsiString; out Value: Int64
  1737. ): Boolean;
  1738. begin
  1739. end;
  1740. function xsdTryParseNegativeInteger(const S: AnsiString; out Value: Int64
  1741. ): Boolean;
  1742. begin
  1743. end;
  1744. function xsdTryParsePositiveInteger(const S: AnsiString; out Value: QWord
  1745. ): Boolean;
  1746. begin
  1747. end;
  1748. function xsdTryParseByte(const S: AnsiString; out Value: Shortint): Boolean;
  1749. begin
  1750. end;
  1751. function xsdTryParseShort(const S: AnsiString; out Value: Smallint): Boolean;
  1752. begin
  1753. end;
  1754. function xsdTryParseInt(const S: AnsiString; out Value: Longint): Boolean;
  1755. begin
  1756. end;
  1757. function xsdTryParseLong(const S: AnsiString; out Value: Int64): Boolean;
  1758. begin
  1759. end;
  1760. function xsdTryParseUnsignedByte(const S: AnsiString; out Value: Byte): Boolean;
  1761. begin
  1762. end;
  1763. function xsdTryParseUnsignedShort(const S: AnsiString; out Value: Word
  1764. ): Boolean;
  1765. begin
  1766. end;
  1767. function xsdTryParseUnsignedInt(const S: AnsiString; out Value: Longword
  1768. ): Boolean;
  1769. begin
  1770. end;
  1771. function xsdTryParseUnsignedLong(const S: AnsiString; out Value: QWord
  1772. ): Boolean;
  1773. begin
  1774. end;
  1775. function xsdTryParseEnum(const S: AnsiString; enum: array of AnsiString;
  1776. out Value: Integer): Boolean;
  1777. begin
  1778. end;
  1779. function xsdParseStringDef(const S: AnsiString; Default: AnsiString
  1780. ): AnsiString;
  1781. begin
  1782. end;
  1783. function xsdParseStringLowerDef(const S: AnsiString; Default: AnsiString
  1784. ): AnsiString;
  1785. begin
  1786. end;
  1787. function xsdParseBooleanDef(const S: AnsiString; Default: Boolean): Boolean;
  1788. begin
  1789. end;
  1790. function xsdParseDateDef(const S: AnsiString; Default: TDateTime;
  1791. Timezone: PXsdTimezone): TDateTime;
  1792. begin
  1793. end;
  1794. function xsdParseTimeDef(const S: AnsiString; Default: TDateTime;
  1795. Timezone: PXsdTimezone): TDateTime;
  1796. begin
  1797. end;
  1798. function xsdParseDateTimeDef(const S: AnsiString; Default: TDateTime;
  1799. Timezone: PXsdTimezone): TDateTime;
  1800. begin
  1801. end;
  1802. function xsdParseDecimalDef(const S: AnsiString; Default: Extended): Extended;
  1803. begin
  1804. end;
  1805. function xsdParseDoubleDef(const S: AnsiString; Default: Double): Double;
  1806. begin
  1807. end;
  1808. function xsdParseFloatDef(const S: AnsiString; Default: Single): Single;
  1809. begin
  1810. end;
  1811. function xsdParseIntegerDef(const S: AnsiString; Default: Int64): Int64;
  1812. begin
  1813. end;
  1814. function xsdParseNonNegativeIntegerDef(const S: AnsiString; Default: QWord
  1815. ): QWord;
  1816. begin
  1817. end;
  1818. function xsdParseNonPositiveIntegerDef(const S: AnsiString; Default: Int64
  1819. ): Int64;
  1820. begin
  1821. end;
  1822. function xsdParseNegativeIntegerDef(const S: AnsiString; Default: Int64): Int64;
  1823. begin
  1824. end;
  1825. function xsdParsePositiveIntegerDef(const S: AnsiString; Default: QWord): QWord;
  1826. begin
  1827. end;
  1828. function xsdParseByteDef(const S: AnsiString; Default: Shortint): Shortint;
  1829. begin
  1830. end;
  1831. function xsdParseShortDef(const S: AnsiString; Default: Smallint): Smallint;
  1832. begin
  1833. end;
  1834. function xsdParseIntDef(const S: AnsiString; Default: Longint): Longint;
  1835. begin
  1836. end;
  1837. function xsdParseLongDef(const S: AnsiString; Default: Int64): Int64;
  1838. begin
  1839. end;
  1840. function xsdParseUnsignedByteDef(const S: AnsiString; Default: Byte): Byte;
  1841. begin
  1842. end;
  1843. function xsdParseUnsignedShortDef(const S: AnsiString; Default: Word): Word;
  1844. begin
  1845. end;
  1846. function xsdParseUnsignedIntDef(const S: AnsiString; Default: Longword
  1847. ): Longword;
  1848. begin
  1849. end;
  1850. function xsdParseUnsignedLongDef(const S: AnsiString; Default: QWord): QWord;
  1851. begin
  1852. end;
  1853. function xsdParseEnumDef(const S: AnsiString; enum: array of AnsiString;
  1854. Default: Integer): Integer;
  1855. begin
  1856. end;*)
  1857. procedure xsdParseBase64(const S: AnsiString; const Value: TStream);
  1858. begin
  1859. xsdParseBase64(PAnsiChar(S), Length(S), Value);
  1860. end;
  1861. procedure xsdParseString(const S: AnsiString; out Value: AnsiString);
  1862. begin
  1863. xsdParseString(PAnsiChar(S), Length(S), Value);
  1864. end;
  1865. procedure xsdParseStringLower(const S: AnsiString; out Value: AnsiString);
  1866. begin
  1867. xsdParseStringLower(PAnsiChar(S), Length(S), Value);
  1868. end;
  1869. procedure xsdParseBoolean(const S: AnsiString; out Value: Boolean);
  1870. begin
  1871. xsdParseBoolean(PAnsiChar(S), Length(S), Value);
  1872. end;
  1873. procedure xsdParseDate(const S: AnsiString; out Year, Month, Day: Longword;
  1874. Timezone: PXsdTimezone; BC: PBoolean);
  1875. begin
  1876. xsdParseDate(PAnsiChar(S), Length(S), Year, Month, Day, Timezone, BC);
  1877. end;
  1878. procedure xsdParseDate(const S: AnsiString; out Value: TDateTime;
  1879. Timezone: PXsdTimezone);
  1880. begin
  1881. xsdParseDate(PAnsiChar(S), Length(S), Value);
  1882. end;
  1883. procedure xsdParseTime(const S: AnsiString; out Hour, Minute, Second,
  1884. Milliseconds: Longword; Timezone: PXsdTimezone);
  1885. begin
  1886. xsdParseTime(PAnsiChar(S), Length(S), Hour, Minute, Second,
  1887. Milliseconds, Timezone);
  1888. end;
  1889. procedure xsdParseTime(const S: AnsiString; out Value: TDateTime;
  1890. Timezone: PXsdTimezone);
  1891. begin
  1892. xsdParseTime(PAnsiChar(S), Length(S), Value, Timezone);
  1893. end;
  1894. procedure xsdParseDateTime(const S: AnsiString; out Year, Month, Day, Hour,
  1895. Minute, Second, Milliseconds: Longword; Timezone: PXsdTimezone; BC: PBoolean);
  1896. begin
  1897. xsdParseDateTime(PAnsiChar(S), Length(S), Year, Month, Day, Hour,
  1898. Minute, Second, Milliseconds, Timezone, BC);
  1899. end;
  1900. procedure xsdParseDateTime(const S: AnsiString; out Value: TDateTime;
  1901. Timezone: PXsdTimezone);
  1902. begin
  1903. xsdParseDateTime(PAnsiChar(S), Length(S), Value);
  1904. end;
  1905. procedure xsdParseDecimal(const S: AnsiString; out Value: Extended);
  1906. begin
  1907. xsdParseDecimal(PAnsiChar(S), Length(S), Value);
  1908. end;
  1909. procedure xsdParseDouble(const S: AnsiString; out Value: Double);
  1910. begin
  1911. xsdParseDouble(PAnsiChar(S), Length(S), Value);
  1912. end;
  1913. procedure xsdParseFloat(const S: AnsiString; out Value: Single);
  1914. begin
  1915. xsdParseFloat(PAnsiChar(S), Length(S), Value);
  1916. end;
  1917. procedure xsdParseInteger(const S: AnsiString; out Value: Int64);
  1918. begin
  1919. xsdParseInteger(PAnsiChar(S), Length(S), Value);
  1920. end;
  1921. procedure xsdParseNonNegativeInteger(const S: AnsiString; out Value: QWord);
  1922. begin
  1923. xsdParseNonNegativeInteger(PAnsiChar(S), Length(S), Value);
  1924. end;
  1925. procedure xsdParseNonPositiveInteger(const S: AnsiString; out Value: Int64);
  1926. begin
  1927. xsdParseNonPositiveInteger(PAnsiChar(S), Length(S), Value);
  1928. end;
  1929. procedure xsdParseNegativeInteger(const S: AnsiString; out Value: Int64);
  1930. begin
  1931. xsdParseNegativeInteger(PAnsiChar(S), Length(S), Value);
  1932. end;
  1933. procedure xsdParsePositiveInteger(const S: AnsiString; out Value: QWord);
  1934. begin
  1935. xsdParsePositiveInteger(PAnsiChar(S), Length(S), Value);
  1936. end;
  1937. procedure xsdParseByte(const S: AnsiString; out Value: Shortint);
  1938. begin
  1939. xsdParseByte(PAnsiChar(S), Length(S), Value);
  1940. end;
  1941. procedure xsdParseShort(const S: AnsiString; out Value: Smallint);
  1942. begin
  1943. xsdParseShort(PAnsiChar(S), Length(S), Value);
  1944. end;
  1945. procedure xsdParseInt(const S: AnsiString; out Value: Longint);
  1946. begin
  1947. xsdParseInt(PAnsiChar(S), Length(S), Value);
  1948. end;
  1949. procedure xsdParseLong(const S: AnsiString; out Value: Int64);
  1950. begin
  1951. xsdParseLong(PAnsiChar(S), Length(S), Value);
  1952. end;
  1953. procedure xsdParseUnsignedByte(const S: AnsiString; out Value: Byte);
  1954. begin
  1955. xsdParseUnsignedByte(PAnsiChar(S), Length(S), Value);
  1956. end;
  1957. procedure xsdParseUnsignedShort(const S: AnsiString; out Value: Word);
  1958. begin
  1959. xsdParseUnsignedShort(PAnsiChar(S), Length(S), Value);
  1960. end;
  1961. procedure xsdParseUnsignedInt(const S: AnsiString; out Value: Longword);
  1962. begin
  1963. xsdParseUnsignedInt(PAnsiChar(S), Length(S), Value);
  1964. end;
  1965. procedure xsdParseUnsignedLong(const S: AnsiString; out Value: QWord);
  1966. begin
  1967. xsdParseUnsignedLong(PAnsiChar(S), Length(S), Value);
  1968. end;
  1969. procedure xsdParseEnum(const S: AnsiString; enum: array of AnsiString; out Value: Integer);
  1970. begin
  1971. xsdParseEnum(PAnsiChar(S), Length(S), enum, Value);
  1972. end;
  1973. function xsdParseString(const S: AnsiString): AnsiString;
  1974. begin
  1975. xsdParseString(PAnsiChar(S), Length(S), Result);
  1976. end;
  1977. function xsdParseStringLower(const S: AnsiString): AnsiString;
  1978. begin
  1979. xsdParseStringLower(PAnsiChar(S), Length(S), Result);
  1980. end;
  1981. function xsdParseBoolean(const S: AnsiString): Boolean;
  1982. begin
  1983. xsdParseBoolean(PAnsiChar(S), Length(S), Result);
  1984. end;
  1985. function xsdParseDate(const S: AnsiString; Timezone: PXsdTimezone): TDateTime;
  1986. begin
  1987. xsdParseDate(PAnsiChar(S), Length(S), Result, Timezone);
  1988. end;
  1989. function xsdParseTime(const S: AnsiString; Timezone: PXsdTimezone): TDateTime;
  1990. begin
  1991. xsdParseTime(PAnsiChar(S), Length(S), Result, Timezone);
  1992. end;
  1993. function xsdParseDateTime(const S: AnsiString; Timezone: PXsdTimezone): TDateTime;
  1994. begin
  1995. xsdParseDateTime(PAnsiChar(S), Length(S), Result, Timezone);
  1996. end;
  1997. function xsdParseDecimal(const S: AnsiString): Extended;
  1998. begin
  1999. xsdParseDecimal(PAnsiChar(S), Length(S), Result);
  2000. end;
  2001. function xsdParseDouble(const S: AnsiString): Double;
  2002. begin
  2003. xsdParseDouble(PAnsiChar(S), Length(S), Result);
  2004. end;
  2005. function xsdParseFloat(const S: AnsiString): Single;
  2006. begin
  2007. xsdParseFloat(PAnsiChar(S), Length(S), Result);
  2008. end;
  2009. function xsdParseInteger(const S: AnsiString): Int64;
  2010. begin
  2011. xsdParseInteger(PAnsiChar(S), Length(S), Result);
  2012. end;
  2013. function xsdParseNonNegativeInteger(const S: AnsiString): QWord;
  2014. begin
  2015. xsdParseNonNegativeInteger(PAnsiChar(S), Length(S), Result);
  2016. end;
  2017. function xsdParseNonPositiveInteger(const S: AnsiString): Int64;
  2018. begin
  2019. xsdParseNonPositiveInteger(PAnsiChar(S), Length(S), Result);
  2020. end;
  2021. function xsdParseNegativeInteger(const S: AnsiString): Int64;
  2022. begin
  2023. xsdParseNegativeInteger(PAnsiChar(S), Length(S), Result);
  2024. end;
  2025. function xsdParsePositiveInteger(const S: AnsiString): QWord;
  2026. begin
  2027. xsdParsePositiveInteger(PAnsiChar(S), Length(S), Result);
  2028. end;
  2029. function xsdParseByte(const S: AnsiString): Shortint;
  2030. begin
  2031. xsdParseByte(PAnsiChar(S), Length(S), Result);
  2032. end;
  2033. function xsdParseShort(const S: AnsiString): Smallint;
  2034. begin
  2035. xsdParseShort(PAnsiChar(S), Length(S), Result);
  2036. end;
  2037. function xsdParseInt(const S: AnsiString): Longint;
  2038. begin
  2039. xsdParseInt(PAnsiChar(S), Length(S), Result);
  2040. end;
  2041. function xsdParseLong(const S: AnsiString): Int64;
  2042. begin
  2043. xsdParseLong(PAnsiChar(S), Length(S), Result);
  2044. end;
  2045. function xsdParseUnsignedByte(const S: AnsiString): Byte;
  2046. begin
  2047. xsdParseUnsignedByte(PAnsiChar(S), Length(S), Result);
  2048. end;
  2049. function xsdParseUnsignedShort(const S: AnsiString): Word;
  2050. begin
  2051. xsdParseUnsignedShort(PAnsiChar(S), Length(S), Result);
  2052. end;
  2053. function xsdParseUnsignedInt(const S: AnsiString): Longword;
  2054. begin
  2055. xsdParseUnsignedInt(PAnsiChar(S), Length(S), Result);
  2056. end;
  2057. function xsdParseUnsignedLong(const S: AnsiString): QWord;
  2058. begin
  2059. xsdParseUnsignedLong(PAnsiChar(S), Length(S), Result);
  2060. end;
  2061. function xsdParseEnum(const S: AnsiString; enum: array of AnsiString): Integer;
  2062. begin
  2063. xsdParseEnum(PAnsiChar(S), Length(S), enum, Result);
  2064. end;
  2065. end.