Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================|
- function MSSL_StrIsBoolean(str: string): Boolean;
- Contributors: Janilabo
- Description: Returns true if str is Boolean.
- Example: 'true' = TRUE; 'false' = TRUE; ..everything else returns FALSE.
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_StrIsBoolean(str: string): Boolean;
- begin
- str := Lowercase(str);
- Result := ((str = 'true') or (str = 'false'));
- end;
- {==============================================================================|
- function MSSL_BooleanLine(x: Boolean; count: Integer): TBoolArray;
- Contributors: Janilabo
- Description: Creates a line of (x) booleans, count being the size of the result.
- Example: MSSL_BooleanLine(True, 3) returns [True, True, True]
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_BooleanLine(x: Boolean; count: Integer): TBoolArray;
- var
- i: Integer;
- begin
- if (count < 1) then
- Exit;
- SetLength(Result, count);
- for i:= 0 to (count - 1) do
- Result[i] := x;
- end;
- {==============================================================================|
- procedure MSSL_TBlACopy(source: TBoolArray; var target: TBoolArray; resetTarget: Boolean);
- Contributors: Janilabo
- Description: Copies source to target. If resetTarget is set to true,
- target will be cleared before the copying process.
- Created: September 30th, 2012.
- [==============================================================================}
- procedure MSSL_TBlACopy(source: TBoolArray; var target: TBoolArray; resetTarget: Boolean);
- var
- i, tAL, sAL: Integer;
- begin
- if resetTarget then
- SetLength(target, 0);
- tAL := Length(target);
- sAL := Length(source);
- SetLength(target, (tAL + sAL));
- for i := 0 to (sAL - 1) do
- target[(tAL + i)] := source[i];
- end;
- {==============================================================================|
- procedure MSSL_TBlAMove(var source, target: TBoolArray; resetTarget: Boolean);
- Contributors: Janilabo
- Description: Moves source to target. If resetTarget is set to true,
- target will be cleared before the moving process.
- Created: September 30th, 2012.
- [==============================================================================}
- procedure MSSL_TBlAMove(var source, target: TBoolArray; resetTarget: Boolean);
- begin
- MSSL_TBlACopy(resetTarget, source, target);
- SetLength(source, 0);
- end;
- {==============================================================================|
- function MSSL_TBlAPos(bool: Boolean; arr: TBoolArray): Integer;
- Contributors: Janilabo
- Description: Returns the position of bool in arr.
- Result will be -1, if bool is not found in arr.
- Example: MSSL_TBlAPos(False, [True, True, False]) returns 2
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlAPos(bool: Boolean; arr: TBoolArray): Integer;
- var
- h: Integer;
- begin
- h := High(arr);
- for Result := 0 to h do
- if (arr[Result] = bool) then
- Exit;
- Result := -1;
- end;
- {==============================================================================|
- function MSSL_TBlALastPos(bool: Boolean; arr: TBoolArray): Integer;
- Contributors: Janilabo
- Description: Returns the last position of bool in arr.
- Result will be -1, if bool is not found in arr.
- Example: MSSL_TBlAPos(True, [True, True, False]) returns 1
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlALastPos(bool: Boolean; arr: TBoolArray): Integer;
- var
- h: Integer;
- begin
- h := High(arr);
- for Result := h downto 0 do
- if (arr[Result] = bool) then
- Exit;
- Result := -1;
- end;
- {==============================================================================|
- function MSSL_TBlAPositions(bool: Boolean; arr: TBoolArray): TIntArray;
- Contributors: Janilabo
- Description: Returns all positions of bool in arr.
- Example: MSSL_TBlAPos(True, [True, False, True]) returns [0, 2]
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlAPositions(bool: Boolean; arr: TBoolArray): TIntArray;
- var
- i, rC, h: Integer;
- begin
- h := High(arr);
- SetLength(Result, (h + 1));
- for i := 0 to h do
- if (arr[i] = bool) then
- begin
- Result[rC] := i;
- inc(rC);
- end;
- SetLength(Result, rC);
- end;
- {==============================================================================|
- procedure MSSL_TBlAInsert(var arr: TBoolArray; index: Integer; bool: Boolean);
- Contributors: Janilabo
- Description: Inserts bool to arr using index as the position.
- Created: September 30th, 2012.
- [==============================================================================}
- procedure MSSL_TBlAInsert(var arr: TBoolArray; index: Integer; bool: Boolean);
- var
- i, l: Integer;
- begin
- l := Length(arr);
- SetLength(arr, (l + 1));
- if (index < 0) then
- index := 0;
- if (index > l) then
- index := l;
- if (l > index) then
- for i := (l - 1) downto index do
- arr[(i + 1)] := arr[i];
- arr[index] := bool;
- end;
- {==============================================================================|
- function MSSL_TBlAContains(arr: TBoolArray; x: Boolean): Boolean;
- Contributors: Janilabo
- Description: Returns true if x is found in arr (arr contains x).
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlAContains(arr: TBoolArray; x: Boolean): Boolean;
- var
- i, h: Integer;
- begin
- h := High(arr);
- for i := 0 to h do
- begin
- Result := (x = arr[i]);
- if Result then
- Exit;
- end;
- end;
- {==============================================================================|
- procedure MSSL_TBlADelete(var arr: TBoolArray; x: Integer);
- Contributors: Janilabo
- Description: Deletes item from arr by position (x).
- Created: September 30th, 2012.
- [==============================================================================}
- procedure MSSL_TBlADelete(var arr: TBoolArray; x: Integer);
- var
- i, h: Integer;
- begin
- h := High(arr);
- if (x > h) then
- Exit;
- for i := x to (h - 1) do
- arr[i] := arr[(i + 1)];
- SetLength(arr, h);
- end;
- {==============================================================================|
- procedure MSSL_TBlAAppend(var arr: TBoolArray; x: Boolean);
- Contributors: Janilabo
- Description: Appends arr with x (adds x to arr).
- Created: September 30th, 2012.
- [==============================================================================}
- procedure MSSL_TBlAAppend(var arr: TBoolArray; x: Boolean);
- var
- aL: Integer;
- begin
- aL := (Length(arr) + 1);
- SetLength(arr, aL);
- arr[(aL - 1)] := x;
- end;
- {==============================================================================|
- function MSSL_TBlALine(x: TBoolArray; count: Integer;): T2DBoolArray;
- Contributors: Janilabo
- Description: Creates a line of (x) boolean arrays, count being the size of the result.
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlALine(x: TBoolArray; count: Integer): T2DBoolArray;
- var
- i: Integer;
- begin
- if (count < 1) then
- Exit;
- SetLength(Result, count);
- for i := 0 to (count - 1) do
- Result[i] := x;
- end;
- {==============================================================================|
- function MSSL_TBlAToATBlAByPartSize(TBlA: TBoolArray; partSize: Integer): T2DBoolArray;
- Contributors: Janilabo
- Description: Breaks TBlA to T2DBlA by part size.
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlAToATBlAByPartSize(TBlA: TBoolArray; partSize: Integer): T2DBoolArray;
- var
- i, i2, r, h, d: Integer;
- begin
- h := High(TBlA);
- if ((h >= 0) and (partSize > 0)) then
- if (partSize <= h) then
- begin
- Inc(h);
- r := (h div partSize);
- if ((r * partSize) < h) then
- Inc(r);
- SetLength(Result, r);
- for i := 0 to (r - 1) do
- for i2 := 0 to (partSize - 1) do
- begin
- SetLength(Result[i], partSize);
- if (d < h) then
- begin
- Result[i][i2] := TBlA[d];
- Inc(d);
- end else
- begin
- SetLength(Result[i], i2);
- Exit;
- end;
- end;
- end else
- Result := [TBlA];
- end;
- {==============================================================================|
- function MSSL_TBlAToATBlAByPartAmount(TBlA: TBoolArray; amount: Integer): T2DBoolArray;
- Contributors: Janilabo
- Description: Breaks TBlA to T2DBlA by part amount.
- Created: September 30th, 2012.
- [==============================================================================}
- function MSSL_TBlAToATBlAByPartAmount(TBlA: TBoolArray; amount: Integer): T2DBoolArray;
- var
- p, h, e, i, i2, h2, a: Integer;
- begin
- h := High(TBlA);
- if ((h <= 0) or (amount < 2)) then
- begin
- if (amount = 1) then
- Result := [TBlA]
- else
- if (amount > 0) then
- SetLength(Result, Amount);
- Exit;
- end;
- if (h < (amount - 1)) then
- amount := (h + 1);
- p := Floor((h + 1) / amount);
- if (p = 0) then
- p := 1;
- e := ((h + 1) - (p * amount));
- if (e >= (h + 1)) then
- e := 0;
- SetLength(Result, amount);
- for i := 0 to (amount - 1) do
- begin
- if ((e >= (i + 1)) and (e > 0)) then
- SetLength(Result[i], (p + 1))
- else
- if (i <= h) then
- SetLength(Result[i], p);
- h2 := High(Result[i]);
- for i2 := 0 to h2 do
- begin
- Result[i][i2] := TBlA[a];
- Inc(a);
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment