<commit_before>unit uHelpers;

interface

uses uTypes, uBearLibItemsCommon, uPlayer;

type
  TIntHelper = record helper for Int
  public
    function Percent(AValue: Int): Int; inline;
    function InRange(AMaxValue: Int): Int; inline;
    function ToString: string;
  end;

type
  TUIntHelper = record helper for UInt
  public
    function Percent(AValue: Int): Int; inline;
    function InRange(AMaxValue: UInt): UInt; inline;
    function ToString: string;
  end;

type
  TStringHelper = record helper for
    string
    function GetName(const Pref: string): string;
  end;

type
  TPlayerHelper = class helper for TPlayer
    function ToString2: string;
  end;

type
  TItemHelper = record helper for Item
    function DoIt: string;
  end;

implementation

uses SysUtils, Math;

{ IntHelper }

function TIntHelper.InRange(AMaxValue: Int): Int;
begin
  Result := EnsureRange(Self, 0, AMaxValue);
end;

function TIntHelper.Percent(AValue: Int): Int;
begin
  Result := Round(Self * AValue / 100);
end;

function TIntHelper.ToString: string;
begin
  Result := IntToStr(Self);
end;

{ UIntHelper }

function TUIntHelper.InRange(AMaxValue: UInt): UInt;
begin
  Result := EnsureRange(Self, 0, AMaxValue);
end;

function TUIntHelper.Percent(AValue: Int): Int;
begin
  Result := Round(Self * AValue / 100);
end;

function TUIntHelper.ToString: string;
begin
  Result := IntToStr(Self);
end;

{ TPlayerHelper }

function TPlayerHelper.ToString2: string;
begin

end;

{ TItemHelper }

function TItemHelper.DoIt: string;
begin

end;

{ TStringHelper }

function TStringHelper.GetName(const Pref: string): string;
begin
  Result := StringReplace(Self, Pref, '', [rfReplaceAll]);
  Result := StringReplace(Result, '_', ' ', [rfReplaceAll]);
end;

end.<commit_msg>TStringList helpers.<commit_after>unit uHelpers;

interface

uses Classes, uTypes, uBearLibItemsCommon, uPlayer;

type
  TIntHelper = record helper for Int
  public
    function Percent(AValue: Int): Int; inline;
    function InRange(AMaxValue: Int): Int; inline;
    function ToString: string;
  end;

type
  TUIntHelper = record helper for UInt
  public
    function Percent(AValue: Int): Int; inline;
    function InRange(AMaxValue: UInt): UInt; inline;
    function ToString: string;
  end;

type
  TStringHelper = record helper for
    string
    function GetName(const Pref: string): string;
  end;

type
  TStringListHelper = class helper for TStringList
    function Join(const CharSeparator: Char): string;
    function Explode(const CharSeparator: Char; const Source: string): TStringList;
  end;

type
  TPlayerHelper = class helper for TPlayer
    function ToString2: string;
  end;

type
  TItemHelper = record helper for Item
    function DoIt: string;
  end;

implementation

uses SysUtils, Math;

{ IntHelper }

function TIntHelper.InRange(AMaxValue: Int): Int;
begin
  Result := EnsureRange(Self, 0, AMaxValue);
end;

function TIntHelper.Percent(AValue: Int): Int;
begin
  Result := Round(Self * AValue / 100);
end;

function TIntHelper.ToString: string;
begin
  Result := IntToStr(Self);
end;

{ UIntHelper }

function TUIntHelper.InRange(AMaxValue: UInt): UInt;
begin
  Result := EnsureRange(Self, 0, AMaxValue);
end;

function TUIntHelper.Percent(AValue: Int): Int;
begin
  Result := Round(Self * AValue / 100);
end;

function TUIntHelper.ToString: string;
begin
  Result := IntToStr(Self);
end;

{ TPlayerHelper }

function TPlayerHelper.ToString2: string;
begin

end;

{ TItemHelper }

function TItemHelper.DoIt: string;
begin

end;

{ TStringHelper }

function TStringHelper.GetName(const Pref: string): string;
begin
  Result := StringReplace(Self, Pref, '', [rfReplaceAll]);
  Result := StringReplace(Result, '_', ' ', [rfReplaceAll]);
end;

{ TStringListHelper }

function TStringListHelper.Join(const CharSeparator: Char): string;
var
  I: Integer;
begin
  Result := '';
  for I := 0 to Self.Count - 1 do
    if (I < Self.Count - 1) then
      Result := Result + Self[I] + CharSeparator
    else
      Result := Result + Self[I];
end;

function TStringListHelper.Explode(const CharSeparator: Char; const Source: string): TStringList;
var
  I: Integer;
  Strings: TStringList;
begin
  Strings := TStringList.Create;
  Strings.Delimiter := CharSeparator;
  Strings.DelimitedText := Source;
  for I := Strings.Count - 1 downto 0 do
    if (Strings[I] = '') then
      Strings.Delete(I);
  Result := Strings;
end;

end.
{'fraction_non_alphanumeric': 0.10466439135381114, 'fraction_numerical': 0.005688282138794084, 'mean_word_length': 4.334951456310679, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3177899', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1435, 'n_words': 425}