我对DELPHI写的几个基类型[3]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 qiubolecn 的 blog

function getpyindexchar(achar: string): char;
begin
  case word(achar[1]) shl 8 + word(achar[2]) of
    $b0a1..$b0c4: result := 'a';
    $b0c5..$b2c0: result := 'b';
    $b2c1..$b4ed: result := 'c';
    $b4ee..$b6e9: result := 'd';
    $b6ea..$b7a1: result := 'e';
    $b7a2..$b8c0: result := 'f';
    $b8c1..$b9fd: result := 'g';
    $b9fe..$bbf6: result := 'h';
    $bbf7..$bfa5: result := 'j';
    $bfa6..$c0ab: result := 'k';
    $c0ac..$c2e7: result := 'l';
    $c2e8..$c4c2: result := 'm';
    $c4c3..$c5b5: result := 'n';
    $c5b6..$c5bd: result := 'o';
    $c5be..$c6d9: result := 'p';
    $c6da..$c8ba: result := 'q';
    $c8bb..$c8f5: result := 'r';
    $c8f6..$cbf9: result := 's';
    $cbfa..$cdd9: result := 't';
    $cdda..$cef3: result := 'w';
    $cef4..$d188: result := 'x';
    $d1b9..$d4d0: result := 'y';
    $d4d1..$d7f9: result := 'z';
  else
    result := char(0);
  end;
end;

class function tstring.getpy(astr: string): string;
var
  i: integer;
begin
  result := '';
  for i := 1 to length(astr) do
  begin

    if bytetype(astr, i) = mbtrailbyte then
      result := result + getpyindexchar(astr[i - 1] + astr[i])
    else
      if bytetype(astr, i) = mbsinglebyte then
        result := result + astr[i];
  end;

end;

function tstring.charat(aposition: integer): char;
begin
  result := ftext[aposition];
end;

class function tstring.charsettostring(avalue: tcharset): string;
begin

end;

class function tstring.comparestring(avalue1, avalue2: string): boolean;
begin
  result := uppercase(avalue1) = uppercase(avalue2);
end;

class function tstring.deleteprefix(avalue: string;
  fixedstring: tcharset): string;
begin
  while system.length(avalue) > 0 do
  begin
    if avalue[1] in fixedstring then
      delete(avalue, 1, 1)
    else
      break;
  end;
  result := avalue;
end;

class function tstring.getfirstword(avalue: string; var aword: string; aseparator: tcharset
  ): integer;
var
  tmpstr: string;
  tmppos: integer;
begin
  tmpstr := deletesuffix(avalue, aseparator);
  tmpstr := deleteprefix(avalue, aseparator);

  result := length(avalue) - length(tmpstr);
{  if length(tmpstr) = 0 then exit;

  if (tmpstr[1] = '''') and (tmpstr[2] = '''')then
  begin
    for tmppos := 3 to length(tmpstr) do
    begin
      if tmpstr[tmppos] in [''''] then
        break;
    end;
  end;

  if tmppos > 3 then tmppos :=tmppos + 2;
}
  for tmppos := 1 to length(tmpstr) do
  begin
    if tmpstr[tmppos] in aseparator then
      break;
  end;

  tmppos := tmppos -1;

//  {todo : -oghs 修复最后一个参数解析不正确}
  if (tmppos = 0) and (avalue <> '') then
    tmppos := length(avalue);

  aword := copy(avalue, result + 1, tmppos);

  result := result + tmppos;
end;

class function tstring.hashcode(avalue: string): integer;
var
  i: integer;
  tmpvalue: integer;
begin
  tmpvalue := 0;
  for i := 1 to system.length(avalue) do
  begin
    tmpvalue := 3 * tmpvalue + ord(avalue[i]);
  end;
  result := tmpvalue;
end;

class function tstring.isallchinese(astr: string): boolean;
var
  i: integer;
begin
  result := true;
  for i := 1 to length(astr) do
  begin
    if bytetype(astr, i) = mbsinglebyte then
    begin
      result := false;
      break;
    end;
  end;
end;

class function tstring.isallenglish(astr: string): boolean;
var
  i: integer;
begin
  result := true;
  for i := 1 to length(astr) do
  begin
    if bytetype(astr, i) <> mbsinglebyte then
    begin

本文关键:我对DELPHI写的几个基类型
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top