xmlxsdparser.pas 73 KB

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