1
0
mirror of synced 2024-09-16 16:46:09 +00:00

Added: IsValidXMLChar and GetValidXMLText functions

This commit is contained in:
Mark van Renswoude 2014-06-25 14:06:25 +00:00
parent 47e6d988f8
commit 2bf7ac5bf9
4 changed files with 89 additions and 6 deletions

View File

@ -0,0 +1,39 @@
unit XMLDataBindingUtilsTest;
interface
uses
TestFramework;
type
TXMLDataBindingUtilsTest = class(TTestCase)
published
procedure TestIsValidXMLChar;
procedure TestGetValidXMLText;
end;
implementation
uses
XMLDataBindingUtils;
{ TXMLDataBindingUtilsTest }
procedure TXMLDataBindingUtilsTest.TestIsValidXMLChar;
begin
CheckTrue(IsValidXMLChar('A'));
CheckTrue(IsValidXMLChar('ë'));
CheckFalse(IsValidXMLChar(#$1A));
end;
procedure TXMLDataBindingUtilsTest.TestGetValidXMLText;
begin
CheckEquals('AB', GetValidXMLText('AB'));
end;
initialization
RegisterTest(TXMLDataBindingUtilsTest.Suite);
end.

View File

@ -11,7 +11,9 @@ uses
X2UtHashes in '..\X2UtHashes.pas',
X2UtHashesVariants in '..\X2UtHashesVariants.pas',
NamedFormatTest in 'Units\NamedFormatTest.pas',
StringsTest in 'Units\StringsTest.pas';
StringsTest in 'Units\StringsTest.pas',
XMLDataBindingUtilsTest in 'Units\XMLDataBindingUtilsTest.pas',
XMLDataBindingUtils in '..\XMLDataBindingUtils.pas';
//SettingsTest in 'Units\SettingsTest.pas',
//IniParserTest in 'Units\IniParserTest.pas';

View File

@ -31,6 +31,12 @@
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
@ -38,7 +44,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<Debugger_RunParams>ip-to-country.csv countries.csv geo.db</Debugger_RunParams>
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<DCC_Namespace>System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
@ -73,6 +79,11 @@
<DCC_SYMBOL_PLATFORM>False</DCC_SYMBOL_PLATFORM>
<DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<DCC_Namespace>Vcl;$(DCC_Namespace)</DCC_Namespace>
<Manifest_File>None</Manifest_File>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType>VCLApplication</Borland.ProjectType>
@ -136,6 +147,8 @@
<DCCReference Include="..\X2UtHashesVariants.pas"/>
<DCCReference Include="Units\NamedFormatTest.pas"/>
<DCCReference Include="Units\StringsTest.pas"/>
<DCCReference Include="Units\XMLDataBindingUtilsTest.pas"/>
<DCCReference Include="..\XMLDataBindingUtils.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>

View File

@ -1,9 +1,5 @@
{
Helpers functions for the X2Software XML Data Binding
Last changed: $Date: 2010-07-15 12:57:03 +0200 (do, 15 jul 2010) $
Revision: $Rev: 54 $
URL: $URL: http://svn.kamadev.net/private/XMLDataBinding/trunk/Shared/XMLDataBindingUtils.pas $
}
unit XMLDataBindingUtils;
@ -83,6 +79,8 @@ const
procedure CreateRequiredAttributes(AParent: IXMLNode; ANodes: array of string);
procedure SortChildNodes(AParent: IXMLNode; ASortOrder: array of string);
function IsValidXMLChar(AChar: WideChar): Boolean;
function GetValidXMLText(AText: WideString): WideString;
{ Now wraps the JclMime implementation:
Lightening fast Mime (Base64) Encoding and Decoding routines.
@ -583,6 +581,37 @@ begin
end;
function IsValidXMLChar(AChar: WideChar): Boolean;
begin
Result := (Ord(AChar) in [9, 10, 13]) or
(Ord(AChar) >= 32);
end;
function GetValidXMLText(AText: WideString): WideString;
var
validText: WideString;
sourcePos: Integer;
destPos: Integer;
begin
SetLength(validText, Length(AText));
destPos := 0;
for sourcePos := 1 to Length(AText) do
begin
if IsValidXMLChar(AText[sourcePos]) then
begin
Inc(destPos);
validText[destPos] := AText[sourcePos];
end;
end;
SetLength(validText, destPos);
Result := validText;
end;
{ --- JclMime implementation from here. }
type
{$IFDEF WIN64}