4 Content-type: text/html
7 \8fã
\82Ì
\82æ
\82¤
\82È
\95¶
\8fÍ
\82ð
\93K
\90Ø
\82É
\95ª
\89ð
\82µ
\82Ä
\88µ
\82¢
\82â
\82·
\82
\82·
\82é
\82½
\82ß
\82Ì
\83N
\83\89\83X
\81B
11 uses Classes, SysUtils;
14 EHeadValueError = class(Exception);
16 THeadValue = class(TPersistent)
18 FStrList: TStringList;
19 function GetCount: integer;
20 function GetData(Key: String): String;
21 function GetValueAt(Index: integer): String;
22 function GetKeyAt(Index: integer): String;
23 function GetIntData(Key: String): integer;
24 procedure SetData(Key: String; const Value: String);
25 procedure SetValueAt(Index: integer; const Value: String);
27 constructor Create(const Str: String); overload;
28 constructor Create; overload;
29 destructor Destroy; override;
30 procedure Initialize(const Str: String);
31 function ToStr: String;
32 property Count: integer read GetCount;
33 property KeyAt[Index: integer]: String read GetKeyAt;
34 property ValueAt[Index: integer]: String read GetValueAt write SetValueAt;
35 property Data[Key: String]: String read GetData write SetData; default;
36 property IntData[Key: String]: integer read GetIntData;
37 procedure Assign(Source: TPersistent); override;
44 constructor THeadValue.Create(const Str: String);
50 procedure THeadValue.Assign(Source: TPersistent);
52 if Source is THeadValue then
53 FStrList.Assign((Source as THeadValue).FStrList)
58 constructor THeadValue.Create;
60 FStrList := TStringList.Create;
63 destructor THeadValue.Destroy;
69 function THeadValue.GetCount: integer;
71 Result := FStrList.Count div 2;
74 function THeadValue.GetData(Key: String): String;
78 for i := 0 to Count-1 do
79 if KeyAt[i] = Key then begin
85 function THeadValue.GetIntData(Key: String): integer;
87 Result := StrToIntDef(GetData(Key), -1);
90 function THeadValue.GetKeyAt(Index: integer): String;
92 Result := FStrList[Index * 2];
95 function THeadValue.GetValueAt(Index: integer): String;
97 Result := FStrList[Index * 2 +1];
100 procedure THeadValue.Initialize(const Str: String);
101 var Tmp: TStringList;
103 Key, Value, S: String;
108 Tmp := TStringList.Create;
110 for i := 0 to Tmp.Count-1 do begin
112 Key := ''; Value := '';
115 Key := Copy(S, 1, j-1);
116 if Length(S) > j then Inc(j);
117 while j <= Length(S) do
119 if (S[j] in [' ']) then
124 Value := Copy(S, j, High(integer));
126 if Key <> '' then begin // Value
\82Í
\8bó
\82Å
\82à
\82æ
\82¢
136 function THeadValue.ToStr: String;
139 max := FStrList.Count div 2 - 1;
141 for i := 0 to max do begin
142 Result := Result + Format('%s: %s', [FStrList[i*2], FStrList[i*2+1]]);
143 if i <> max then Result := Result + #13#10;
147 procedure THeadValue.SetData(Key: String; const Value: String);
150 for i := 0 to Count-1 do
151 if KeyAt[i] = Key then begin
160 procedure THeadValue.SetValueAt(Index: integer; const Value: String);
162 FStrList[Index * 2 +1] := Value;