<commit_before>(*
  Copyright 2016, MARS-Curiosity library

  Home: https://github.com/andrea-magni/MARS
*)
unit MARS.Core.Utils;

{$I MARS.inc}

interface

uses
  SysUtils, Classes, RTTI, SyncObjs, Web.HttpApp
, MARS.Core.JSON
;

type
  TFormParamFile = record
    FieldName: string;
    FileName: string;
    Bytes: TBytes;
    ContentType: string;
    procedure Clear;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFieldName: string); overload;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFileIndex: Integer); overload;
    constructor Create(const AFieldName: string; const AFileName: string; const ABytes: TBytes; const AContentType: string);
    function ToString: string;
  end;

  TFormParam = record
    FieldName: string;
    Value: TValue;
    function IsFile: Boolean;
    function AsFile: TFormParamFile;
    procedure Clear;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFieldName: string); overload;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFileIndex: Integer); overload;
    constructor Create(const AFieldName: string; const AValue: TValue);
    constructor CreateFile(const AFieldName: string; const AFileName: string; const ABytes: TBytes = []; const AContentType: string = '');
    function ToString: string;
  end;

  TDump = class
  public
    class procedure Request(const ARequest: TWebRequest; const AFileName: string); overload; virtual;
  end;


  function CreateCompactGuidStr: string;

  function ObjectToJSON(const AObject: TObject): TJSONObject;
  function ObjectToJSONString(const AObject: TObject): string;

  function BooleanToTJSON(AValue: Boolean): TJSONValue;

  function SmartConcat(const AArgs: array of string; const ADelimiter: string = ',';
    const AAvoidDuplicateDelimiter: Boolean = True; const ATrim: Boolean = True;
    const ACaseInsensitive: Boolean = True): string;

  function EnsurePrefix(const AString, APrefix: string; const AIgnoreCase: Boolean = True): string;
  function EnsureSuffix(const AString, ASuffix: string; const AIgnoreCase: Boolean = True): string;
<commit_msg>Compiling in Seattle (#19)<commit_after>(*
  Copyright 2016, MARS-Curiosity library

  Home: https://github.com/andrea-magni/MARS
*)
unit MARS.Core.Utils;

{$I MARS.inc}

interface

uses
  SysUtils, Classes, RTTI, SyncObjs, Web.HttpApp
, MARS.Core.JSON
;

type
  TFormParamFile = record
    FieldName: string;
    FileName: string;
    Bytes: TBytes;
    ContentType: string;
    procedure Clear;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFieldName: string); overload;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFileIndex: Integer); overload;
    constructor Create(const AFieldName: string; const AFileName: string; const ABytes: TBytes; const AContentType: string);
    function ToString: string;
  end;

  TFormParam = record
    FieldName: string;
    Value: TValue;
    function IsFile: Boolean;
    function AsFile: TFormParamFile;
    procedure Clear;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFieldName: string); overload;
    constructor CreateFromRequest(const ARequest: TWebRequest; const AFileIndex: Integer); overload;
    constructor Create(const AFieldName: string; const AValue: TValue);
    constructor CreateFile(const AFieldName: string; const AFileName: string; const ABytes: TBytes = nil; const AContentType: string = '');
    function ToString: string;
  end;

  TDump = class
  public
    class procedure Request(const ARequest: TWebRequest; const AFileName: string); overload; virtual;
  end;


  function CreateCompactGuidStr: string;

  function ObjectToJSON(const AObject: TObject): TJSONObject;
  function ObjectToJSONString(const AObject: TObject): string;

  function BooleanToTJSON(AValue: Boolean): TJSONValue;

  function SmartConcat(const AArgs: array of string; const ADelimiter: string = ',';
    const AAvoidDuplicateDelimiter: Boolean = True; const ATrim: Boolean = True;
    const ACaseInsensitive: Boolean = True): string;

  function EnsurePrefix(const AString, APrefix: string; const AIgnoreCase: Boolean = True): string;
  function EnsureSuffix(const AString, ASuffix: string; const AIgnoreCase: Boolean = True): string;

{'fraction_non_alphanumeric': 0.08621495327102804, 'fraction_numerical': 0.002336448598130841, 'mean_word_length': 4.962395543175488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1430613', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1228, 'n_words': 388}