⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucharacter.pas

📁 uEncoding字符串UNICODE处理单元 用于处理unicode国际通用
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  if not IsLatin1(C) then
    Result := CheckNumber(GetUnicodeCategory(S, Index))
  else if not IsAscii(C) then
    Result := CheckNumber(InternalGetLatin1Category(C))
  else
    Result := (C >= '0') and (C <= '9');
end;

class function TCharacter.IsPunctuation(const S: Widestring; Index: Integer): Boolean;
var
  C: WideChar;
begin
  CheckStringRange(S, Index);
  C := S[Index];
  if IsLatin1(C) then
    Result := CheckPunctuation(InternalGetLatin1Category(C))
  else
    Result := CheckPunctuation(GetUnicodeCategory(S, Index));
end;

class function TCharacter.IsPunctuation(C: WideChar): Boolean;
begin
  if IsLatin1(C) then
    Result := CheckPunctuation(InternalGetLatin1Category(C))
  else
    Result := CheckPunctuation(InternalGetUnicodeCategory(UCS4Char(C)));
end;

class function TCharacter.IsSeparator(C: WideChar): Boolean;
begin
  if not IsLatin1(C) then
    Result := CheckSeparator(InternalGetUnicodeCategory(UCS4Char(C)))
  else
    {$IFDEF UNICODE}
    Result := (C = ' ') or (C = WideChar($A0));
    {$ELSE}
    Result := (C = ' ');
    {$ENDIF}
end;

class function TCharacter.IsSeparator(const S: Widestring; Index: Integer): Boolean;
var
  C: WideChar;
begin
  CheckStringRange(S, Index);
  C := S[Index];
  if not IsLatin1(C) then
    Result := CheckSeparator(GetUnicodeCategory(S, Index))
  else
    {$IFDEF UNICODE}
    Result := (C = ' ') or (C = WideChar($A0));
    {$ELSE}
    Result := (C = ' ');
    {$ENDIF}
end;

class function TCharacter.IsSurrogate(const S: Widestring; Index: Integer): Boolean;
begin
  CheckStringRange(S, Index);
  Result := IsSurrogate(S[Index]);
end;

class function TCharacter.IsSurrogatePair(const S: Widestring; Index: Integer): Boolean;
begin
  CheckStringRange(S, Index);
  Result := (Index < Length(S)) and IsSurrogatePair(S[Index], S[Index + 1]);
end;

class function TCharacter.IsSymbol(C: WideChar): Boolean;
begin
  if IsLatin1(C) then
    Result := CheckSymbol(InternalGetLatin1Category(C))
  else
    Result := CheckSymbol(InternalGetUnicodeCategory(UCS4Char(C)));
end;

class function TCharacter.IsSymbol(const S: Widestring; Index: Integer): Boolean;
var
  C: WideChar;
begin
  CheckStringRange(S, Index);
  C := S[Index];
  if IsLatin1(C) then
    Result := CheckSymbol(InternalGetLatin1Category(C))
  else
    Result := CheckSymbol(GetUnicodeCategory(S, Index));
end;

class function TCharacter.IsUpper(const S: Widestring; Index: Integer): Boolean;
var
  C: WideChar;
begin
  CheckStringRange(S, Index);
  C := S[Index];
  if not IsLatin1(C) then
    Result := GetUnicodeCategory(S, Index) = ucUppercaseLetter
  else if not IsAscii(C) then
    Result := InternalGetLatin1Category(C) = ucUppercaseLetter
  else
    Result := (C >= 'A') and (C <= 'Z');
end;

class function TCharacter.IsUpper(C: WideChar): Boolean;
begin
  if not IsLatin1(C) then
    Result := InternalGetUnicodeCategory(UCS4Char(C)) = ucUppercaseLetter
  else if not IsAscii(C) then
    Result := InternalGetLatin1Category(C) = ucUppercaseLetter
  else
    Result := (C >= 'A') and (C <= 'Z');
end;

class function TCharacter.IsWhiteSpace(const S: Widestring; Index: Integer): Boolean;
var
  C: WideChar;
begin
  CheckStringRange(S, Index);
  C := S[Index];
  if IsLatin1(C) then
    {$IFDEF UNICODE}
    Result := (C = ' ') or ((C >= #$0009) and (C <= #$000D)) or (C = #$00A0) or (C = #$0085)
    {$ELSE}
    Result := (C = ' ') or ((C >= #$09) and (C <= #$0D))
    {$ENDIF}
  else
    Result := CheckSeparator(GetUnicodeCategory(S, Index));
end;

class function TCharacter.ToLower(C: WideChar): WideChar;
begin
  Result := WideChar(CharLower(PChar(C)));
end;

class function TCharacter.ToLower(const S: Widestring): Widestring;
begin
  Result := S;
  if LCMapString(GetThreadLocale, LCMAP_LOWERCASE, PChar(S), Length(S), PChar(Result), Length(Result)) = 0 then
    RaiseLastOSError;
end;

class function TCharacter.ToUpper(C: WideChar): WideChar;
begin
  Result := WideChar(CharUpper(PChar(C)));
end;

class function TCharacter.ToUpper(const S: Widestring): Widestring;
begin
  Result := S;
  if LCMapString(GetThreadLocale, LCMAP_UPPERCASE, PChar(S), Length(S), PChar(Result), Length(Result)) = 0 then
    RaiseLastOSError;
end;

class function TCharacter.IsWhiteSpace(C: WideChar): Boolean;
begin
  if IsLatin1(C) then
    {$IFDEF UNICODE}
    Result := (C = ' ') or ((C >= #$0009) and (C <= #$000D)) or (C = #$00A0) or (C = #$0085)
    {$ELSE}
    Result := (C = ' ') or ((C >= #$09) and (C <= #$0D))
    {$ENDIF}
  else
    Result := CheckSeparator(InternalGetUnicodeCategory(UCS4Char(C)));
end;

function ConvertFromUtf32(C: UCS4Char): Widestring;
begin
  Result := TCharacter.ConvertFromUtf32(C);
end;

function ConvertToUtf32(const S: Widestring; Index: Integer): UCS4Char;
begin
  Result := TCharacter.ConvertToUtf32(S, Index);
end;

function ConvertToUtf32(const S: Widestring; Index: Integer; out CharLength: Integer): UCS4Char;
begin
  Result := TCharacter.ConvertToUtf32(S, Index, CharLength);
end;

function ConvertToUtf32(const HighSurrogate, LowSurrogate: WideChar): UCS4Char;
begin
  Result := TCharacter.ConvertToUtf32(HighSurrogate, LowSurrogate);
end;

function GetNumericValue(C: WideChar): Double;
begin
  Result := TCharacter.GetNumericValue(C);
end;

function GetNumericValue(const S: Widestring; Index: Integer): Double;
begin
  Result := TCharacter.GetNumericValue(S, Index);
end;

function GetUnicodeCategory(C: WideChar): TUnicodeCategory;
begin
  Result := TCharacter.GetUnicodeCategory(C);
end;

function GetUnicodeCategory(const S: Widestring; Index: Integer): TUnicodeCategory;
begin
  Result := TCharacter.GetUnicodeCategory(S, Index);
end;

function IsControl(C: WideChar): Boolean;
begin
  Result := TCharacter.IsControl(C);
end;

function IsControl(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsControl(S, Index);
end;

function IsDigit(C: WideChar): Boolean;
begin
  Result := TCharacter.IsDigit(C);
end;

function IsDigit(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsDigit(S, Index);
end;

function IsHighSurrogate(C: WideChar): Boolean;
begin
  Result := TCharacter.IsHighSurrogate(C);
end;

function IsHighSurrogate(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsHighSurrogate(S, Index);
end;

function IsLetter(C: WideChar): Boolean;
begin
  Result := TCharacter.IsLetter(C);
end;

function IsLetter(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsLetter(S, Index);
end;

function IsLetterOrDigit(C: WideChar): Boolean;
begin
  Result := TCharacter.IsLetterOrDigit(C);
end;

function IsLetterOrDigit(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsLetterOrDigit(S, Index);
end;

function IsLower(C: WideChar): Boolean;
begin
  Result := TCharacter.IsLower(C);
end;

function IsLower(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsLower(S, Index);
end;

function IsLowSurrogate(C: WideChar): Boolean;
begin
  Result := TCharacter.IsLowSurrogate(C);
end;

function IsLowSurrogate(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsLowSurrogate(S, Index);
end;

function IsNumber(C: WideChar): Boolean;
begin
  Result := TCharacter.IsNumber(C);
end;

function IsNumber(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsNumber(S, Index);
end;

function IsPunctuation(C: WideChar): Boolean;
begin
  Result := TCharacter.IsPunctuation(C);
end;

function IsPunctuation(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsPunctuation(S, Index);
end;

function IsSeparator(C: WideChar): Boolean;
begin
  Result := TCharacter.IsSeparator(C);
end;

function IsSeparator(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsSeparator(S, Index);
end;

function IsSurrogate(Surrogate: WideChar): Boolean;
begin
  Result := TCharacter.IsSurrogate(Surrogate);
end;

function IsSurrogate(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsSurrogate(S, Index);
end;

function IsSurrogatePair(const HighSurrogate, LowSurrogate: WideChar): Boolean;
begin
  Result := TCharacter.IsSurrogatePair(HighSurrogate, LowSurrogate);
end;

function IsSurrogatePair(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsSurrogatePair(S, Index);
end;

function IsSymbol(C: WideChar): Boolean;
begin
  Result := TCharacter.IsSymbol(C);
end;

function IsSymbol(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsSymbol(S, Index);
end;

function IsUpper(C: WideChar): Boolean;
begin
  Result := TCharacter.IsUpper(C);
end;

function IsUpper(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsUpper(S, Index);
end;

function IsWhiteSpace(C: WideChar): Boolean;
begin
  Result := TCharacter.IsWhiteSpace(C);
end;

function IsWhiteSpace(const S: Widestring; Index: Integer): Boolean;
begin
  Result := TCharacter.IsWhiteSpace(S, Index);
end;

function ToLower(C: WideChar): WideChar;
begin
  Result := TCharacter.ToLower(C);
end;

function ToLower(const S: Widestring): Widestring;
begin
  Result := TCharacter.ToLower(S);
end;

function ToUpper(C: WideChar): WideChar;
begin
  Result := TCharacter.ToUpper(C);
end;

function ToUpper(const S: Widestring): Widestring;
begin
  Result := TCharacter.ToUpper(S);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -