亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tntformatstrutils.pas

?? Delphi知道現在也沒有提供Unicode支持
?? PAS
字號:

{*****************************************************************************}
{                                                                             }
{    Tnt Delphi Unicode Controls                                              }
{      http://www.tntware.com/delphicontrols/unicode/                         }
{        Version: 2.3.0                                                       }
{                                                                             }
{    Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com)       }
{                                                                             }
{*****************************************************************************}

unit TntFormatStrUtils;

{$INCLUDE TntCompilers.inc}

interface

// this unit provides functions to work with format strings

uses
  TntSysUtils;

function GetCanonicalFormatStr(const _FormatString: WideString): WideString;
{$IFNDEF COMPILER_9_UP}
function ReplaceFloatingArgumentsInFormatString(const _FormatString: WideString;
  const Args: array of const
    {$IFDEF COMPILER_7_UP}; FormatSettings: PFormatSettings{$ENDIF}): WideString;
{$ENDIF}
procedure CompareFormatStrings(FormatStr1, FormatStr2: WideString);
function FormatStringsAreCompatible(FormatStr1, FormatStr2: WideString): Boolean;

type
  EFormatSpecError = class(ETntGeneralError);

implementation

uses
  SysUtils, Math, TntClasses;

resourcestring
  SInvalidFormatSpecifier = 'Invalid Format Specifier: %s';
  SMismatchedArgumentTypes = 'Argument types for index %d do not match. (%s <> %s)';
  SMismatchedArgumentCounts = 'Number of format specifiers do not match.';

type
  TFormatSpecifierType = (fstInteger, fstFloating, fstPointer, fstString);

function GetFormatSpecifierType(const FormatSpecifier: WideString): TFormatSpecifierType;
var
  LastChar: WideChar;
begin
  LastChar := TntWideLastChar(FormatSpecifier);
  case LastChar of
    'd', 'D', 'u', 'U', 'x', 'X':
      result := fstInteger;
    'e', 'E', 'f', 'F', 'g', 'G', 'n', 'N', 'm', 'M':
      result := fstFloating;
    'p', 'P':
      result := fstPointer;
    's', 'S':
      result := fstString
    else
      raise ETntInternalError.CreateFmt('Internal Error: Unexpected format type (%s)', [LastChar]);
  end;
end;

type
  TFormatStrParser = class(TObject)
  private
    ParsedString: TBufferedWideString;
    PFormatString: PWideChar;
    LastIndex: Integer;
    ExplicitCount: Integer;
    ImplicitCount: Integer;
    procedure RaiseInvalidFormatSpecifier;
    function ParseChar(c: WideChar): Boolean;
    procedure ForceParseChar(c: WideChar);
    function ParseDigit: Boolean;
    function ParseInteger: Boolean;
    procedure ForceParseType;
    function PeekDigit: Boolean;
    function PeekIndexSpecifier(out Index: Integer): Boolean;
  public
    constructor Create(const _FormatString: WideString);
    destructor Destroy; override;
    function ParseFormatSpecifier: Boolean;
  end;

constructor TFormatStrParser.Create(const _FormatString: WideString);
begin
  inherited Create;
  PFormatString := PWideChar(_FormatString);
  ExplicitCount := 0;
  ImplicitCount := 0;
  LastIndex := -1;
  ParsedString := TBufferedWideString.Create;
end;

destructor TFormatStrParser.Destroy;
begin
  FreeAndNil(ParsedString);
  inherited;
end;

procedure TFormatStrParser.RaiseInvalidFormatSpecifier;
begin
  raise EFormatSpecError.CreateFmt(SInvalidFormatSpecifier, [ParsedString.Value + PFormatString]);
end;

function TFormatStrParser.ParseChar(c: WideChar): Boolean;
begin
  result := False;
  if PFormatString^ = c then begin
    result := True;
    ParsedString.AddChar(c);
    Inc(PFormatString);
  end;
end;

procedure TFormatStrParser.ForceParseChar(c: WideChar);
begin
  if not ParseChar(c) then
    RaiseInvalidFormatSpecifier;
end;

function TFormatStrParser.PeekDigit: Boolean;
begin
  result := False;
  if  (PFormatString^ <> #0)
  and (PFormatString^ >= '0')
  and (PFormatString^ <= '9') then
    result := True;
end;

function TFormatStrParser.ParseDigit: Boolean;
begin
  result := False;
  if PeekDigit then begin
    result := True;
    ForceParseChar(PFormatString^);
  end;
end;

function TFormatStrParser.ParseInteger: Boolean;
const
  MAX_INT_DIGITS = 6;
var
  digitcount: integer;
begin
  digitcount := 0;
  While ParseDigit do begin
    inc(digitcount);
  end;
  result := (digitcount > 0);
  if digitcount > MAX_INT_DIGITS then
    RaiseInvalidFormatSpecifier;
end;

procedure TFormatStrParser.ForceParseType;
begin
  if PFormatString^ = #0 then
    RaiseInvalidFormatSpecifier;

  case PFormatString^ of
    'd', 'u', 'x', 'e', 'f', 'g', 'n', 'm', 'p', 's',
    'D', 'U', 'X', 'E', 'F', 'G', 'N', 'M', 'P', 'S':
  begin
    // do nothing
  end
  else
    RaiseInvalidFormatSpecifier;
  end;
  ForceParseChar(PFormatString^);
end;

function TFormatStrParser.PeekIndexSpecifier(out Index: Integer): Boolean;
var
  SaveParsedString: WideString;
  SaveFormatString: PWideChar;
begin
  SaveParsedString := ParsedString.Value;
  SaveFormatString := PFormatString;
  try
    ParsedString.Clear;
    Result := False;
    Index := -1;
    if ParseInteger then begin
      Index := StrToInt(ParsedString.Value);
      if ParseChar(':') then
        Result := True;
    end;
  finally
    ParsedString.Clear;
    ParsedString.AddString(SaveParsedString);
    PFormatString := SaveFormatString;
  end;
end;

function TFormatStrParser.ParseFormatSpecifier: Boolean;
var
  ExplicitIndex: Integer;
begin
  Result := False;
  // Parse entire format specifier
  ForceParseChar('%');
  if (PFormatString^ <> #0)
  and (not ParseChar(' '))
  and (not ParseChar('%')) then begin
    if PeekIndexSpecifier(ExplicitIndex) then begin
      Inc(ExplicitCount);
      LastIndex := Max(LastIndex, ExplicitIndex);
    end else begin
      Inc(ImplicitCount);
      Inc(LastIndex);
      ParsedString.AddString(IntToStr(LastIndex));
      ParsedString.AddChar(':');
    end;
    if ParseChar('*') then
    begin
      Inc(ImplicitCount);
      Inc(LastIndex);
      ParseChar(':');
    end else if ParseInteger then
      ParseChar(':');
    ParseChar('-');
    if ParseChar('*') then begin
      Inc(ImplicitCount);
      Inc(LastIndex);
    end else
      ParseInteger;
    if ParseChar('.') then begin
      if not ParseChar('*') then
        ParseInteger;
    end;
    ForceParseType;
    Result := True;
  end;
end;

//-----------------------------------

function GetCanonicalFormatStr(const _FormatString: WideString): WideString;
var
  PosSpec: Integer;
begin
  with TFormatStrParser.Create(_FormatString) do
  try
    // loop until no more '%'
    PosSpec := Pos('%', PFormatString);
    While PosSpec <> 0 do begin
      try
        // delete everything up until '%'
        ParsedString.AddBuffer(PFormatString, PosSpec - 1);
        Inc(PFormatString, PosSpec - 1);
        // parse format specifier
        ParseFormatSpecifier;
      finally
        PosSpec := Pos('%', PFormatString);
      end;
    end;
    if ((ExplicitCount = 0) and (ImplicitCount = 1)) {simple expression}
    or ((ExplicitCount > 0) and (ImplicitCount = 0)) {nothing converted} then
      result := _FormatString {original}
    else
      result := ParsedString.Value + PFormatString;
  finally
    Free;
  end;
end;

{$IFNDEF COMPILER_9_UP}
function ReplaceFloatingArgumentsInFormatString(const _FormatString: WideString;
  const Args: array of const
    {$IFDEF COMPILER_7_UP}; FormatSettings: PFormatSettings{$ENDIF}): WideString;
{ This function replaces floating point format specifiers with their actual formatted values.
  It also adds index specifiers so that the other format specifiers don't lose their place.
  The reason for this is that WideFormat doesn't correctly format floating point specifiers.
  See QC#4254. }
var
  Parser: TFormatStrParser;
  PosSpec: Integer;
  Output: TBufferedWideString;
begin
  Output := TBufferedWideString.Create;
  try
    Parser := TFormatStrParser.Create(_FormatString);
    with Parser do
    try
      // loop until no more '%'
      PosSpec := Pos('%', PFormatString);
      While PosSpec <> 0 do begin
        try
          // delete everything up until '%'
          Output.AddBuffer(PFormatString, PosSpec - 1);
          Inc(PFormatString, PosSpec - 1);
          // parse format specifier
          ParsedString.Clear;
          if (not ParseFormatSpecifier)
          or (GetFormatSpecifierType(ParsedString.Value) <> fstFloating) then
            Output.AddBuffer(ParsedString.BuffPtr, MaxInt)
          {$IFDEF COMPILER_7_UP}
          else if Assigned(FormatSettings) then
            Output.AddString(Format{TNT-ALLOW Format}(ParsedString.Value, Args, FormatSettings^))
          {$ENDIF}
          else
            Output.AddString(Format{TNT-ALLOW Format}(ParsedString.Value, Args));
        finally
          PosSpec := Pos('%', PFormatString);
        end;
      end;
      Output.AddString(PFormatString);
    finally
      Free;
    end;
    Result := Output.Value;
  finally
    Output.Free;
  end;
end;
{$ENDIF}

procedure GetFormatArgs(const _FormatString: WideString; FormatArgs: TTntStrings);
var
  PosSpec: Integer;
begin
  with TFormatStrParser.Create(_FormatString) do
  try
    FormatArgs.Clear;
    // loop until no more '%'
    PosSpec := Pos('%', PFormatString);
    While PosSpec <> 0 do begin
      try
        // delete everything up until '%'
        Inc(PFormatString, PosSpec - 1);
        // add format specifier to list
        ParsedString.Clear;
        if ParseFormatSpecifier then
          FormatArgs.Add(ParsedString.Value);
      finally
        PosSpec := Pos('%', PFormatString);
      end;
    end;
  finally
    Free;
  end;
end;

function GetExplicitIndex(const FormatSpecifier: WideString): Integer;
var
  IndexStr: WideString;
  PosColon: Integer;
begin
  result := -1;
  PosColon := Pos(':', FormatSpecifier);
  if PosColon <> 0 then begin
    IndexStr := Copy(FormatSpecifier, 2, PosColon - 2);
    result := StrToInt(IndexStr);
  end;
end;

function GetMaxIndex(FormatArgs: TTntStrings): Integer;
var
  i: integer;
  RunningIndex: Integer;
  ExplicitIndex: Integer;
begin
  result := -1;
  RunningIndex := -1;
  for i := 0 to FormatArgs.Count - 1 do begin
    ExplicitIndex := GetExplicitIndex(FormatArgs[i]);
    if ExplicitIndex <> -1 then
      RunningIndex := ExplicitIndex
    else
      inc(RunningIndex);
    result := Max(result, RunningIndex);
  end;
end;

procedure UpdateTypeList(FormatArgs, TypeList: TTntStrings);
var
  i: integer;
  f: WideString;
  SpecType: TFormatSpecifierType;
  ExplicitIndex: Integer;
  MaxIndex: Integer;
  RunningIndex: Integer;
begin
  // set count of TypeList to accomodate maximum index
  MaxIndex := GetMaxIndex(FormatArgs);
  TypeList.Clear;
  for i := 0 to MaxIndex do
    TypeList.Add('');

  // for each arg...
  RunningIndex := -1;
  for i := 0 to FormatArgs.Count - 1 do begin
    f := FormatArgs[i];
    ExplicitIndex := GetExplicitIndex(f);
    SpecType := GetFormatSpecifierType(f);

    // determine running arg index
    if ExplicitIndex <> -1 then
      RunningIndex := ExplicitIndex
    else
      inc(RunningIndex);

    if TypeList[RunningIndex] <> '' then begin
      // already exists in list, check for compatibility
      if TypeList.Objects[RunningIndex] <> TObject(SpecType) then
        raise EFormatSpecError.CreateFmt(SMismatchedArgumentTypes,
          [RunningIndex, TypeList[RunningIndex], f]);
    end else begin
      // not in list so update it
      TypeList[RunningIndex] := f;
      TypeList.Objects[RunningIndex] := TObject(SpecType);
    end;
  end;
end;

procedure CompareFormatStrings(FormatStr1, FormatStr2: WideString);
var
  ArgList1: TTntStringList;
  ArgList2: TTntStringList;
  TypeList1: TTntStringList;
  TypeList2: TTntStringList;
  i: integer;
begin
  ArgList1 := nil;
  ArgList2 := nil;
  TypeList1 := nil;
  TypeList2 := nil;
  try
    ArgList1 := TTntStringList.Create;
    ArgList2 := TTntStringList.Create;
    TypeList1 := TTntStringList.Create;
    TypeList2 := TTntStringList.Create;

    GetFormatArgs(FormatStr1, ArgList1);
    UpdateTypeList(ArgList1, TypeList1);

    GetFormatArgs(FormatStr2, ArgList2);
    UpdateTypeList(ArgList2, TypeList2);

    if TypeList1.Count <> TypeList2.Count then
      raise EFormatSpecError.Create(SMismatchedArgumentCounts + CRLF + CRLF + '> ' + FormatStr1 + CRLF + '> ' + FormatStr2);

    for i := 0 to TypeList1.Count - 1 do begin
      if TypeList1.Objects[i] <> TypeList2.Objects[i] then begin
        raise EFormatSpecError.CreateFmt(SMismatchedArgumentTypes,
          [i, TypeList1[i], TypeList2[i]]);
      end;
    end;

  finally
    ArgList1.Free;
    ArgList2.Free;
    TypeList1.Free;
    TypeList2.Free;
  end;
end;

function FormatStringsAreCompatible(FormatStr1, FormatStr2: WideString): Boolean;
var
  ArgList1: TTntStringList;
  ArgList2: TTntStringList;
  TypeList1: TTntStringList;
  TypeList2: TTntStringList;
  i: integer;
begin
  ArgList1 := nil;
  ArgList2 := nil;
  TypeList1 := nil;
  TypeList2 := nil;
  try
    ArgList1 := TTntStringList.Create;
    ArgList2 := TTntStringList.Create;
    TypeList1 := TTntStringList.Create;
    TypeList2 := TTntStringList.Create;

    GetFormatArgs(FormatStr1, ArgList1);
    UpdateTypeList(ArgList1, TypeList1);

    GetFormatArgs(FormatStr2, ArgList2);
    UpdateTypeList(ArgList2, TypeList2);

    Result := (TypeList1.Count = TypeList2.Count);
    if Result then begin
      for i := 0 to TypeList1.Count - 1 do begin
        if TypeList1.Objects[i] <> TypeList2.Objects[i] then begin
          Result := False;
          break;
        end;
      end;
    end;
  finally
    ArgList1.Free;
    ArgList2.Free;
    TypeList1.Free;
    TypeList2.Free;
  end;
end;

end.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美乱妇15p| 国产精品久久久久aaaa| 黑人巨大精品欧美一区| 久久夜色精品国产噜噜av| 国产精品综合视频| 国产精品女主播av| 色综合久久88色综合天天| 亚洲妇女屁股眼交7| 日韩一区二区在线观看| 国产专区欧美精品| 国产精品久久看| 在线亚洲免费视频| 日韩不卡手机在线v区| 久久九九久久九九| 91亚洲精品一区二区乱码| 一区二区在线观看免费| 91精品国产手机| 国产精品自拍毛片| 最新日韩av在线| 欧美裸体bbwbbwbbw| 国内国产精品久久| 综合激情网...| 666欧美在线视频| 国产精品资源站在线| 亚洲美女精品一区| 欧美一区二区在线视频| 国产大陆精品国产| 一区二区视频在线看| 7777精品伊人久久久大香线蕉| 国产一区二区精品久久91| 亚洲视频精选在线| 日韩欧美一区在线| aaa国产一区| 丝袜国产日韩另类美女| 国产色综合久久| 欧美性猛交xxxx黑人交| 精品无码三级在线观看视频| 亚洲天堂免费在线观看视频| 91精品欧美一区二区三区综合在| 国产精品综合在线视频| 亚洲国产精品久久久久秋霞影院 | 91精品中文字幕一区二区三区| 精品影视av免费| 亚洲三级在线播放| 精品国产一区二区三区不卡| 日本韩国一区二区| 韩日欧美一区二区三区| 一区二区三区久久| 久久久久久久免费视频了| 欧美综合一区二区三区| 国产精品中文字幕日韩精品| 亚洲国产日韩在线一区模特| 国产欧美日韩中文久久| 欧美乱妇一区二区三区不卡视频| 成人晚上爱看视频| 久久精品国产秦先生| 一个色综合网站| 国产欧美精品一区aⅴ影院 | 亚洲色图欧洲色图婷婷| 欧美一区二区黄| 一本大道久久精品懂色aⅴ | 国产一区不卡视频| 亚洲高清在线精品| 国产精品国产三级国产aⅴ中文| 日韩欧美国产午夜精品| 在线观看视频一区| 成人一道本在线| 另类的小说在线视频另类成人小视频在线| 一区二区三区欧美久久| 国产视频一区在线观看| 欧美va天堂va视频va在线| 欧美日韩精品综合在线| 91在线视频免费观看| 国产传媒一区在线| 久久99精品久久久久久动态图 | 亚洲成人黄色小说| 亚洲欧洲无码一区二区三区| 欧美精品一区二| 欧美一区二区精品在线| 欧美日韩国产高清一区二区三区 | 亚洲视频在线一区| 国产欧美精品在线观看| 亚洲精品一线二线三线无人区| 欧美久久高跟鞋激| 欧美专区在线观看一区| 99久久99久久综合| 粉嫩一区二区三区在线看| 精品一区二区三区免费播放| 日本va欧美va精品发布| 亚洲成av人影院| 夜夜嗨av一区二区三区| 亚洲人成7777| ㊣最新国产の精品bt伙计久久| 国产欧美1区2区3区| 久久99九九99精品| 美日韩黄色大片| 日本不卡一区二区三区| 午夜欧美一区二区三区在线播放| 亚洲精品ww久久久久久p站| 中文字幕一区二区三区av| 国产精品麻豆久久久| 国产精品蜜臀av| 国产精品美女久久福利网站| 久久久精品中文字幕麻豆发布| 日韩精品一区二区三区中文不卡 | 欧美中文字幕亚洲一区二区va在线| aaa亚洲精品| 99re热这里只有精品免费视频| 成人久久久精品乱码一区二区三区 | 蜜桃视频免费观看一区| 日韩影院精彩在线| 视频一区视频二区中文| 首页国产丝袜综合| 日韩高清不卡一区二区| 天堂一区二区在线免费观看| 午夜亚洲国产au精品一区二区| 视频精品一区二区| 奇米精品一区二区三区在线观看| 青青草精品视频| 激情综合一区二区三区| 极品美女销魂一区二区三区| 国产乱对白刺激视频不卡| 国产馆精品极品| 成人动漫一区二区| 色综合天天在线| 欧美三级在线播放| 欧美美女bb生活片| 精品久久国产97色综合| 久久综合九色综合97婷婷女人| 国产欧美一区二区三区鸳鸯浴| 国产精品乱人伦| 亚洲黄色小说网站| 五月天激情综合网| 麻豆一区二区在线| 国产成人免费在线观看| 91在线观看成人| 欧美老女人在线| 日韩精品一区二| 欧美国产日产图区| 亚洲女与黑人做爰| 午夜精品视频一区| 紧缚奴在线一区二区三区| 高清久久久久久| 在线日韩一区二区| 日韩欧美中文一区| 亚洲国产高清不卡| 一区二区三区四区在线| 青青草伊人久久| 丁香天五香天堂综合| 在线视频一区二区三区| 欧美电影免费观看高清完整版在 | 欧美亚洲图片小说| 日韩无一区二区| 中文在线资源观看网站视频免费不卡| 亚洲免费在线视频| 日韩精品电影一区亚洲| 国产精品亚洲综合一区在线观看| 91首页免费视频| 日韩情涩欧美日韩视频| 国产精品久久久久婷婷| 日韩有码一区二区三区| 成人免费视频视频在线观看免费 | 亚洲色图欧美在线| 蜜桃一区二区三区四区| 不卡av电影在线播放| 欧美日本一区二区| 国产拍欧美日韩视频二区| 亚洲愉拍自拍另类高清精品| 久久99深爱久久99精品| 91网站黄www| 日韩精品一区国产麻豆| 亚洲免费在线视频一区 二区| 久久精品国产成人一区二区三区| 99久久免费视频.com| 日韩三级中文字幕| 亚洲视频1区2区| 国产一区二区三区在线看麻豆| 色老汉一区二区三区| 精品电影一区二区三区 | 日韩专区中文字幕一区二区| 国产不卡在线播放| 在线成人av影院| 亚洲欧美一区二区在线观看| 捆绑调教美女网站视频一区| 色欧美日韩亚洲| 欧美激情中文不卡| 免播放器亚洲一区| 91福利在线看| 欧美韩日一区二区三区四区| 五月综合激情婷婷六月色窝| av网站免费线看精品| 欧美v亚洲v综合ⅴ国产v| 一区二区三区在线免费视频| 国产精品系列在线观看| 4438亚洲最大| 玉米视频成人免费看| www.视频一区| 久久亚洲一区二区三区明星换脸| 五月婷婷久久丁香| 91视视频在线直接观看在线看网页在线看|