Namespace src/Array
src/Array
Overview
Directory src/Array
file source src/Array/clone.sh
Array::clone
clone the array passed as parameter
Arguments
- $1 (arrayToClone:String): name of the array to clone
- $2 (clonedArray:String): name of the cloned array
Variables set
- clonedArray (containing): the values of arrayToClone
src/Array/contains.sh
file source src/Array/contains.sh
Array::contains
check if an element is contained in an array
Example
Array::contains "${libPath}" "${__BASH_FRAMEWORK_IMPORTED_FILES[@]}"
Arguments
- $1 needle:String
- $@ array:String[]
Exit codes
- 0: if found
- 1: otherwise
src/Array/join.sh
Array::join
concatenate each element of an array with a separator
Example
declare -a array=(test1, test2)
echo "Result= $(Array::join "," "${array[@]})"
Result= test1,test2
Arguments
- $1 glue:String
- $@ array:String[]
src/Array/remove.sh
file source src/Array/remove.sh
Array::remove
remove elements from array
Arguments
- $1 (arrayRemoveArray:&String[]): (reference) array from which elements have to be removed
- … (valuesToRemoveKeys:String[]): list of elements to remove
Warnings
- Performance1 : version taken from https://stackoverflow.com/a/59030460
- Performance2 : for multiple values to remove, prefer using Array::removeIf
See also
src/Array/removeIf.sh
file source src/Array/removeIf.sh
Array::removeIf
more performant version of Array:remove remove elements from array using a predicate function
Example
function predicateElem1to5() {
[[ "$1" =~ ^elem[1-5]$ ]] || return 1
}
local -a myArray=("elem1" "elemX" "elem2" "elemX" "elem3" "elemX" "elem4" "elemX" "elem5" "elemX")
Array::removeIf myArray predicateElem1to5
echo "Result: ${myArray[*]}"
## Result: elemX elemX elemX elemX elemX
Arguments
- $1 (arrayRemoveArray:&String[]): (reference) array from which elements have to be removed
- $2 (predicateFunction:Function): callback function called on each element
Exit codes
- 1: if predicateFunction argument is not a function or empty
See also
src/Array/wrap.sh
Array::wrap
concatenate each element of an array with a separator but wrapping text when line length is more than provided argument The algorithm will try not to cut the array element if can
Arguments
- $1 glue:String
- $2 maxLineLength:int
- $3 indentNextLine:int
- $@ array:String[]
src/Array/wrap2.sh
file source src/Array/wrap2.sh
Array::wrap2
concatenate each element of an array with a separator but wrapping text when line length is more than provided argument The algorithm will try not to cut the array element if it can.
- if an arg can be placed on current line it will be, otherwise current line is printed and arg is added to the new current line
- Empty arg is interpreted as a new line.
- Add \r to arg in order to force break line and avoid following arg to be concatenated with current arg.
Arguments
- $1 glue:String
- $2 maxLineLength:int
- $3 indentNextLine:int
- $@ array:String[]