TextLib
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Hamster-Coder

//@version=5

// @description TODO: Library with text / string functions
library("TextLib", overlay = true)

// @function TODO: add function description here
// @param x TODO: add parameter x description here
// @returns TODO: add what function returns
// export concat(string value1, string value2, string separator = "\n") =>
// 	string result = ""
// 	if (str.length(value1) == 0 and str.length(value2) == 0)
// 		result := result
// 	else if (str.length(value1) == 0)
// 		result := value2
// 	else if (str.length(value2) == 0)
// 		result := value1
// 	else 
// 		result := value1 + separator + value2
// 	result
export type textFormatOptions	
    string currency_format = "0.00"
    string percent_format = "0.00"
    string basecurrency_format = "0.00"

export concat(string[] values, string separator) =>
	string result = ""
	for [index, value] in values
		if (str.length(result) == 0 and str.length(value) == 0)
			result := result
		else if (str.length(result) == 0)
			result := value
		else if (str.length(value) == 0)
			result := result
		else 
			result := result + separator + value
	//string result = array.join(values, separator)
	result

export concat(string value1, string value2, string separator) =>
	values = array.from(value1, value2)
	concat(values, separator)

export concat(string value1, string value2, string value3, string separator) =>
	values = array.from(value1, value2, value3)
	concat(values, separator)

export concat(string value1, string value2, string value3, string value4, string separator) =>
	values = array.from(value1, value2, value3, value4)
	concat(values, separator)

export concat(string value1, string value2, string value3, string value4, string value5, string separator) =>
	values = array.from(value1, value2, value3, value4, value5)
	concat(values, separator)

export concatLine(string[] values) =>
	concat(values, "\n")

export concatLine(string value1, string value2) =>
	values = array.from(value1, value2)
	concatLine(values)

export concatLine(string value1, string value2, string value3) =>
	values = array.from(value1, value2, value3)
	concatLine(values)

export concatLine(string value1, string value2, string value3, string value4) =>
	values = array.from(value1, value2, value3, value4)
	concatLine(values)

export concatLine(string value1, string value2, string value3, string value4, string value5) =>
	values = array.from(value1, value2, value3, value4, value5)
	concatLine(values)

