summaryrefslogtreecommitdiff
path: root/packages/libxml/src/xmlxsd.pas
diff options
context:
space:
mode:
authorivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-02-19 11:30:45 +0000
committerivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-02-19 11:30:45 +0000
commitb4074a3a0b400796d0cc3cee9a5349bda9064162 (patch)
tree3f27f67fdd8439c0d3ef9ba627046cc4c482728b /packages/libxml/src/xmlxsd.pas
parentf66fac3229b12105dc795b1c4b7854340ba6ac01 (diff)
downloadfpc-b4074a3a0b400796d0cc3cee9a5349bda9064162.tar.gz
* added new function xsdParseStringLower that parse any string and convert it to lower case
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@14924 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/libxml/src/xmlxsd.pas')
-rw-r--r--packages/libxml/src/xmlxsd.pas67
1 files changed, 62 insertions, 5 deletions
diff --git a/packages/libxml/src/xmlxsd.pas b/packages/libxml/src/xmlxsd.pas
index 671cba0175..9d5f3c80d3 100644
--- a/packages/libxml/src/xmlxsd.pas
+++ b/packages/libxml/src/xmlxsd.pas
@@ -78,6 +78,7 @@ procedure xsdDateTimeConvertTo(var Year, Month, Day, Hour, Minute, Second, Milli
{ Parse functions }
function xsdTryParseString(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String): Boolean;
+function xsdTryParseStringLower(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String): Boolean;
function xsdTryParseBoolean(Chars: xmlCharPtr; Len: Integer; out Value: Boolean): Boolean;
function xsdTryParseDate(Chars: xmlCharPtr; Len: Integer; out Year, Month, Day: Longword; Timezone: PTimezone = nil; BC: PBoolean = nil): Boolean;
function xsdTryParseDate(Chars: xmlCharPtr; Len: Integer; out Value: TDateTime; Timezone: PTimezone = nil): Boolean;
@@ -104,6 +105,7 @@ function xsdTryParseUnsignedLong(Chars: xmlCharPtr; Len: Integer; out Value: QWo
function xsdTryParseEnum(Chars: xmlCharPtr; Len: Integer; enum: array of Utf8String; out Value: Integer): Boolean;
function xsdParseStringDef(Chars: xmlCharPtr; Len: Integer; Default: Utf8String): Utf8String;
+function xsdParseStringLowerDef(Chars: xmlCharPtr; Len: Integer; Default: Utf8String): Utf8String;
function xsdParseBooleanDef(Chars: xmlCharPtr; Len: Integer; Default: Boolean): Boolean;
function xsdParseDateDef(Chars: xmlCharPtr; Len: Integer; Default: TDateTime; Timezone: PTimezone = nil): TDateTime;
function xsdParseTimeDef(Chars: xmlCharPtr; Len: Integer; Default: TDateTime; Timezone: PTimezone = nil): TDateTime;
@@ -127,6 +129,7 @@ function xsdParseUnsignedLongDef(Chars: xmlCharPtr; Len: Integer; Default: QWord
function xsdParseEnumDef(Chars: xmlCharPtr; Len: Integer; enum: array of Utf8String; Default: Integer): Integer;
procedure xsdParseString(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String);
+procedure xsdParseStringLower(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String);
procedure xsdParseBoolean(Chars: xmlCharPtr; Len: Integer; out Value: Boolean);
procedure xsdParseDate(Chars: xmlCharPtr; Len: Integer; out Year, Month, Day: Longword; Timezone: PTimezone = nil; BC: PBoolean = nil);
procedure xsdParseDate(Chars: xmlCharPtr; Len: Integer; out Value: TDateTime; Timezone: PTimezone = nil);
@@ -153,6 +156,7 @@ procedure xsdParseUnsignedLong(Chars: xmlCharPtr; Len: Integer; out Value: QWord
procedure xsdParseEnum(Chars: xmlCharPtr; Len: Integer; enum: array of Utf8String; out Value: Integer);
function xsdParseString(Chars: xmlCharPtr; Len: Integer): Utf8String;
+function xsdParseStringLower(Chars: xmlCharPtr; Len: Integer): Utf8String;
function xsdParseBoolean(Chars: xmlCharPtr; Len: Integer): Boolean;
function xsdParseDate(Chars: xmlCharPtr; Len: Integer; Timezone: PTimezone = nil): TDateTime;
function xsdParseTime(Chars: xmlCharPtr; Len: Integer; Timezone: PTimezone = nil): TDateTime;
@@ -858,16 +862,52 @@ end;
function xsdTryParseString(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String): Boolean;
begin
if Assigned(Chars) then
+ begin
if Len >= 0 then
begin
SetLength(Value, Len);
Move(Chars^, Value[1], Len);
- Result := True;
- end else begin
+ end else
Value := PChar(Chars);
- Result := True;
- end
- else
+ Result := True;
+ end else
+ Result := False;
+end;
+
+function xsdTryParseStringLower(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String): Boolean;
+var
+ P,L,D: PByte;
+ C: Byte;
+begin
+ if Assigned(Chars) then
+ begin
+ P := PByte(Chars);
+ if Len >= 0 then
+ begin
+ L := P + Len;
+ SetLength(Value, Len);
+ D := @Value[1];
+ while P < L do
+ begin
+ C := P^;
+ if (C>=65) and (C<=90) then Inc(C, 32);
+ D^ := C;
+ Inc(D);
+ Inc(P);
+ end;
+ end else begin
+ SetLength(Value, 255);
+ //D := @Value[1];
+ while P^ <> 0 do
+ begin
+ C := P^;
+ if (C>=65) and (C<=90) then Inc(C, 32);
+ Value := Value + Chr(C); {$warning assign char by char maybe quite slow!}
+ Inc(P);
+ end;
+ end;
+ Result := True;
+ end else
Result := False;
end;
@@ -1218,6 +1258,12 @@ begin
Result := Default;
end;
+function xsdParseStringLowerDef(Chars: xmlCharPtr; Len: Integer; Default: Utf8String): Utf8String;
+begin
+ if not xsdTryParseStringLower(Chars, Len, Result) then
+ Result := Default;
+end;
+
function xsdParseBooleanDef(Chars: xmlCharPtr; Len: Integer; Default: Boolean): Boolean;
begin
if not xsdTryParseBoolean(Chars, Len, Result) then
@@ -1350,6 +1396,12 @@ begin
raise XSDException.CreateFmt(ParserError, [__strpas(Chars,Len), 'xs:string']);
end;
+procedure xsdParseStringLower(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String);
+begin
+ if not xsdTryParseStringLower(Chars, Len, Value) then
+ raise XSDException.CreateFmt(ParserError, [__strpas(Chars,Len), 'xs:string']);
+end;
+
procedure xsdParseBoolean(Chars: xmlCharPtr; Len: Integer; out Value: Boolean);
begin
if not xsdTryParseBoolean(Chars, Len, Value) then
@@ -1499,6 +1551,11 @@ begin
xsdParseString(Chars, Len, Result);
end;
+function xsdParseStringLower(Chars: xmlCharPtr; Len: Integer): Utf8String;
+begin
+ xsdParseStringLower(Chars, Len, Result);
+end;
+
function xsdParseBoolean(Chars: xmlCharPtr; Len: Integer): Boolean;
begin
xsdParseBoolean(Chars, Len, Result);