{
===============================================================================
  Copyright (©) 2002. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión: 01-11-2002
  Versión actual: 1.0.1
  Fecha versión actual: 12-10-2004
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
    12-10-2004    Añadimos el metodo quitarMascaraEuro
===============================================================================
}

unit StrFunc;

{$I COMPILE.INC}

interface

uses
  SysUtils;
  
type
  TCharSet = set of Char;

{ Funciones de cadena }
function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet): AnsiString;
function StrPadLeft(const S: AnsiString; Len: Integer; C: AnsiChar): AnsiString;
function StrCapitalize(const S: AnsiString): AnsiString;
function EsCadenaVacia(const S: AnsiString): Boolean; overload;
function EsCadenaVacia(const S: Variant): Boolean; overload;
function EsCadenaVacia(const S: AnsiString; const EmptyChars: TCharSet): Boolean; overload;
function EsNumerico(Cadena: String) : Boolean;

implementation

{$IFDEF RDX_D6}uses Variants;{$ENDIF}

function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet): AnsiString;
var
  Source, Dest: PChar;
begin
  if Delimiters = [] then
    Include(Delimiters, ' ');
  if S <> '' then
  begin
    SetLength(Result, Length(S));
    Source := PChar(S);
    Dest := PChar(Result);
    Dest^ := UpCase(Source^);
    Inc(Source);
    Inc(Dest);
    while Source^ <> #0 do
    begin
      Dest^ := Source^;
      if Source^ in Delimiters then
      begin
        Inc(Source);
        Inc(Dest);
        Dest^ := UpCase(Source^);
      end;
      Inc(Dest);
      Inc(Source);
    end;
  end;
end;

function StrCapitalize(const S: AnsiString): AnsiString;
var
  Source, Dest: PChar;
begin
  if S <> '' then
  begin
    SetLength(Result, Length(S));
    Source := PChar(S);
    Dest := PChar(Result);
    Dest^ := UpCase(Source^);
    Inc(Source);
    Inc(Dest);
    while Source^ <> #0 do
    begin
      Dest^ := Source^;
      Inc(Dest);
      Inc(Source);
    end;
  end;
end;

function StrPadLeft(const S: AnsiString; Len: Integer; C: AnsiChar): AnsiString;
var
  L: Integer;
begin
  L := Length(S);
  if L < Len then
    Result := StringOfChar(C, Len - L) + S
  else
    Result := S;
end;

function EsCadenaVacia(const S: AnsiString): Boolean;
begin
  Result := (Length(Trim(S)) = 0)
end;

function EsCadenaVacia(const S: Variant): Boolean; overload;
begin
  Result := True;
  if VarIsNull(S) then
    Exit;
  Result := EsCadenaVacia(VarToStr(S));
end;

function EsCadenaVacia(const S: AnsiString; const EmptyChars: TCharSet): Boolean;
var
  I, SLen: Integer;
begin
  SLen := Length(S);
  I := 1;
  while I <= SLen do begin
    if not (S[I] in EmptyChars) then begin
      Result := False;
      Exit;
    end
    else Inc(I);
  end;
  Result := True;
end;

function EsNumerico(Cadena: String) : Boolean;
var
  Codigo: Integer;
  Valor: Double;
begin
  Val(Cadena, Valor, Codigo);
  Result := (Codigo = 0)
end;

end.
