| 29 |
function ZenToHan(const s: string): string; |
function ZenToHan(const s: string): string; |
| 30 |
function VaguePos(const Substr, S: string): Integer; |
function VaguePos(const Substr, S: string): Integer; |
| 31 |
|
|
| 32 |
function ReplaseNoValidateChar( inVal : String): String; |
function ReplaseNoValidateChar( inVal : String): String; |
| 33 |
function IsNoValidID( inID :String): Boolean; |
function IsNoValidID( inID :String): Boolean; |
| 34 |
|
|
| 35 |
|
procedure LoadFromFile(Strings: TStrings; const FileName: String); |
| 36 |
implementation |
implementation |
| 37 |
// ポインター&アセンブラによる高速ポス |
// ポインター&アセンブラによる高速ポス |
| 38 |
function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar; |
function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar; |
| 39 |
asm |
asm |
| 40 |
PUSH EBX |
PUSH EBX |
| 41 |
PUSH ESI |
PUSH ESI |
| 42 |
PUSH EDI |
PUSH EDI |
| 43 |
|
|
| 44 |
MOV ESI,ECX { Point ESI to substr } |
MOV ESI,ECX { Point ESI to substr } |
| 45 |
MOV EDI,EAX { Point EDI to s } |
MOV EDI,EAX { Point EDI to s } |
| 46 |
|
|
| 47 |
MOV ECX,EDX { ECX = search length } |
MOV ECX,EDX { ECX = search length } |
| 48 |
SUB ECX,EAX |
SUB ECX,EAX |
| 308 |
Result := CustomStringReplace(inVal, '\', '¥'); |
Result := CustomStringReplace(inVal, '\', '¥'); |
| 309 |
Result := CustomStringReplace(Result, '/', '/'); |
Result := CustomStringReplace(Result, '/', '/'); |
| 310 |
Result := CustomStringReplace(Result, '*', '*'); |
Result := CustomStringReplace(Result, '*', '*'); |
| 311 |
Result := CustomStringReplace(Result, '>', '>'); |
Result := CustomStringReplace(Result, '>', '>'); |
| 312 |
Result := CustomStringReplace(Result, '<', '<'); |
Result := CustomStringReplace(Result, '<', '<'); |
| 313 |
Result := CustomStringReplace(Result, '|', '|'); |
Result := CustomStringReplace(Result, '|', '|'); |
| 314 |
end; |
end; |
| 315 |
(************************************************************************* |
(************************************************************************* |
| 316 |
* 無効なIDかのチェック(無効例:ID:??? , ID:???0) |
* 無効なIDかのチェック(無効例:ID:??? , ID:???0) |
| 317 |
*************************************************************************) |
*************************************************************************) |
| 318 |
function IsNoValidID( inID :String): Boolean; |
function IsNoValidID( inID :String): Boolean; |
| 319 |
begin |
begin |
| 320 |
inID := Trim(inID); |
inID := Trim(inID); |
| 321 |
if inID = '' then Result := True |
if inID = '' then Result := True |
| 322 |
else begin |
else begin |
| 323 |
inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) ); |
inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) ); |
| 324 |
inID := CustomStringReplace(inID, '?', ''); |
inID := CustomStringReplace(inID, '?', ''); |
| 325 |
if (inID = '') or (inID = '0') then Result := True |
if (inID = '') or (inID = '0') then Result := True |
| 326 |
else Result := False; |
else Result := False; |
| 327 |
end; |
end; |
| 328 |
end; |
end; |
| 329 |
|
{*********************************************************************** |
| 330 |
|
高速なLoadFromFile : メモリの使用量がファイルサイズ + 8kB |
| 331 |
|
***********************************************************************} |
| 332 |
|
procedure LoadFromFile(Strings: TStrings; const FileName: String); |
| 333 |
|
const |
| 334 |
|
BufferSize = $2000; |
| 335 |
|
var |
| 336 |
|
I, ReadCount, LineCount: Integer; |
| 337 |
|
LineRemained: Boolean; |
| 338 |
|
S, Str: String; |
| 339 |
|
Buffer, P, Start: PChar; |
| 340 |
|
Fs: TFileStream; |
| 341 |
|
begin |
| 342 |
|
Strings.BeginUpdate; |
| 343 |
|
try |
| 344 |
|
Strings.Clear; |
| 345 |
|
Fs := TFileStream.Create(FileName, fmOpenRead); |
| 346 |
|
try |
| 347 |
|
Buffer := StrAlloc(BufferSize + 1); |
| 348 |
|
try |
| 349 |
|
// #13#10 をカウントする #26 以降は読み込まない |
| 350 |
|
LineCount := 0; |
| 351 |
|
LineRemained := False; |
| 352 |
|
repeat |
| 353 |
|
ReadCount := Fs.Read(Buffer^, BufferSize); |
| 354 |
|
if ReadCount > 0 then |
| 355 |
|
LineRemained := False; |
| 356 |
|
Buffer[ReadCount] := #0; |
| 357 |
|
P := Buffer; |
| 358 |
|
// バッファによって #13#10 が分断された場合のために |
| 359 |
|
if P^ = #10 then Inc(P); |
| 360 |
|
|
| 361 |
|
while not(P^ in [#0, #26]) do |
| 362 |
|
begin |
| 363 |
|
|
| 364 |
|
while not (P^ in [#0, #10, #13, #26]) do Inc(P); |
| 365 |
|
|
| 366 |
|
if P^ in [#10, #13] then |
| 367 |
|
Inc(LineCount) |
| 368 |
|
else |
| 369 |
|
LineRemained := True; |
| 370 |
|
|
| 371 |
|
if P^ = #13 then Inc(P); |
| 372 |
|
|
| 373 |
|
if P^ = #10 then Inc(P); |
| 374 |
|
end; |
| 375 |
|
if P^ = #26 then Break; |
| 376 |
|
until ReadCount = 0; |
| 377 |
|
|
| 378 |
|
if LineRemained then |
| 379 |
|
Inc(LineCount); |
| 380 |
|
|
| 381 |
|
// 取得した行数分の Capacity を確保 |
| 382 |
|
for I := 0 to LineCount - 1 do |
| 383 |
|
Strings.Add(''); |
| 384 |
|
|
| 385 |
|
// バッファを利用して読み込み #26 以降は読み込まない |
| 386 |
|
Fs.Seek(0, 0); |
| 387 |
|
LineCount := 0; |
| 388 |
|
Str := ''; |
| 389 |
|
repeat |
| 390 |
|
ReadCount := Fs.Read(Buffer^, BufferSize); |
| 391 |
|
Buffer[ReadCount] := #0; |
| 392 |
|
P := Buffer; |
| 393 |
|
// バッファによって #13#10 が分断された場合のために |
| 394 |
|
if P^ = #10 then Inc(P); |
| 395 |
|
|
| 396 |
|
while not(P^ in [#0, #26]) do |
| 397 |
|
begin |
| 398 |
|
Start := P; |
| 399 |
|
while not (P^ in [#0, #10, #13, #26]) do Inc(P); |
| 400 |
|
|
| 401 |
|
SetString(S, Start, P - Start); |
| 402 |
|
if P^ in [#0, #26] then |
| 403 |
|
Str := S |
| 404 |
|
else |
| 405 |
|
begin |
| 406 |
|
if Str <> '' then |
| 407 |
|
begin |
| 408 |
|
S := Str + S; |
| 409 |
|
Str := ''; |
| 410 |
|
end; |
| 411 |
|
Strings[LineCount] := S; |
| 412 |
|
Inc(LineCount); |
| 413 |
|
end; |
| 414 |
|
|
| 415 |
|
if P^ = #13 then Inc(P); |
| 416 |
|
|
| 417 |
|
if P^ = #10 then Inc(P); |
| 418 |
|
end; |
| 419 |
|
|
| 420 |
|
if P^ = #26 then Break; |
| 421 |
|
|
| 422 |
|
until ReadCount = 0; |
| 423 |
|
|
| 424 |
|
if Str <> '' then |
| 425 |
|
Strings[LineCount] := Str; |
| 426 |
|
finally |
| 427 |
|
StrDispose(Buffer); |
| 428 |
|
end; |
| 429 |
|
finally |
| 430 |
|
Fs.Free; |
| 431 |
|
end; |
| 432 |
|
finally |
| 433 |
|
Strings.EndUpdate; |
| 434 |
|
end; |
| 435 |
|
end; |
| 436 |
|
|
| 437 |
|
|
| 438 |
|
|
| 439 |
end. |
end. |