Mudanças entre as edições de "Tiny Types"

De Grupo Acert
Ir para: navegação, pesquisa
Linha 227: Linha 227:
 
   end;
 
   end;
  
−
{ TCPF }
+
  { TCPF }
−
class operator TCPF.Implicit(const CPF: string): TCPF;
+
  class operator TCPF.Implicit(const CPF: string): TCPF;
−
begin
+
  begin
  
−
  Result.FUnformatted := Clear(CPF);
+
    Result.FUnformatted := Clear(CPF);
  
−
end;
+
  end;
  
−
function TCPF.GetFormatted: string;
+
  function TCPF.GetFormatted: string;
−
begin
+
  begin
  
−
  Result := MaskUtils.FormatMaskText('000.000.000-00;0; ', FUnformatted);
+
    Result := MaskUtils.FormatMaskText('000.000.000-00;0; ', FUnformatted);
  
−
end;
+
  end;
  
−
class operator TCPF.Implicit(const CPF: TCPF): string;
+
  class operator TCPF.Implicit(const CPF: TCPF): string;
−
begin
+
  begin
  
−
  Result := CPF.FUnformatted;
+
    Result := CPF.FUnformatted;
  
−
end;
+
  end;
  
−
function TCPF.IsValid: Boolean;
+
  function TCPF.IsValid: Boolean;
−
const
+
  const
−
  BLACKLIST: array[0..9] of string = ('00000000000',
+
    BLACKLIST: array[0..9] of string = ('00000000000',
−
                                      '11111111111',
+
                                        '11111111111',
−
                                      '22222222222',
+
                                        '22222222222',
−
                                      '33333333333',
+
                                        '33333333333',
−
                                      '44444444444',
+
                                        '44444444444',
−
                                      '55555555555',
+
                                        '55555555555',
−
                                      '66666666666',
+
                                        '66666666666',
−
                                      '77777777777',
+
                                        '77777777777',
−
                                      '88888888888',
+
                                        '88888888888',
−
                                      '99999999999');
+
                                        '99999999999');
−
var
+
  var
−
  IsInvalidSize: Boolean;
+
    IsInvalidSize: Boolean;
−
  IsBlacklisted: Boolean;
+
    IsBlacklisted: Boolean;
−
  I: Integer;
+
    I: Integer;
−
  D1, D2: Integer;
+
    D1, D2: Integer;
−
begin
+
  begin
 
    
 
    
−
  IsInvalidSize := Length(FUnformatted) <> 11;
+
    IsInvalidSize := Length(FUnformatted) <> 11;
−
  IsBlacklisted := AnsiIndexStr(FUnformatted, BLACKLIST) >= 0;
+
    IsBlacklisted := AnsiIndexStr(FUnformatted, BLACKLIST) >= 0;
 
    
 
    
−
  if IsInvalidSize or IsBlacklisted then
+
    if IsInvalidSize or IsBlacklisted then
−
  begin
+
    begin
−
    Result := False;
+
      Result := False;
−
  end
+
    end
−
  else  
+
    else  
−
  begin
+
    begin
  
−
    D1 := 0;
+
      D1 := 0;
  
−
    for I := 1 to 9 do
+
      for I := 1 to 9 do
−
      D1 := D1 + (StrToInt(FUnformatted[I]) * (11 - I));
+
        D1 := D1 + (StrToInt(FUnformatted[I]) * (11 - I));
 
      
 
      
−
    D1 := 11 - (D1 mod 11);
+
      D1 := 11 - (D1 mod 11);
 
      
 
      
−
    if D1 >= 10 then
+
      if D1 >= 10 then
  
−
    D1 := 0;
+
      D1 := 0;
 
      
 
      
−
    D2 := D1 * 2;
+
      D2 := D1 * 2;
 
      
 
      
−
    for I := 1 to 9 do
+
      for I := 1 to 9 do
−
      D2 := D2 + (StrToInt(FUnformatted[I]) * (12 - I));
+
        D2 := D2 + (StrToInt(FUnformatted[I]) * (12 - I));
  
−
    D2 := 11 - (D2 mod 11);
+
      D2 := 11 - (D2 mod 11);
 
      
 
      
−
    if D2 >= 10 then
+
      if D2 >= 10 then
−
      D2 :=0;
+
        D2 :=0;
  
−
    Result := (IntToStr(D1) + IntToStr(D2)) = Copy(FUnformatted, 10, 2);
+
      Result := (IntToStr(D1) + IntToStr(D2)) = Copy(FUnformatted, 10, 2);
  
−
  end;
+
    end;
  
−
end;
+
  end;
  
−
end.
+
  end.

Edição das 09h38min de 7 de janeiro de 2015