string removeDuplicateConsecutiveSubstring(string s, string substring)
The function removes consecutive string duplicates.
Example
string s = removeDuplicateConsecutiveSubstring("AAAAbooeAAAuuvAww", "A");
assert(s == "AbooeAuuvAww");
s = removeDuplicateConsecutiveSubstring("AAAAbcooeAAAgguvAww", "AA");
assert(s == "AAbcooeAAAgguvAww");
ref T[] removeDuplicate(T)(ref T[] arr)
The function removes duplicate elements from an array.
Example
int[] values = [1, 3, 1, 7, 2, 19, 5, 2, 2];
removeDuplicate(values);
assert(values == [1, 3, 7, 2, 19, 5]);
auto assocArrayItems(V, K)(V[K] aarray)
Returns array of tuples with pairs of keys and values from associative array.
auto sortAssocArrayItemsByKeys(V, K)(V[K] aarray, Flag!"desc" desc = No.desc)
Makes key-sorted array of tuples with pairs of keys and values from associative array.
Parameters
aarray | Associative array. |
desc | Flag for sorting (descending/ascending). By default, No.desc. |
Returns
Key-sorted array of tuples with elements of the associative array.
auto sortAssocArrayItemsByValues(V, K)(V[K] aarray, Flag!"desc" desc = No.desc)
Makes value-sorted array of tuples with pairs of keys and values from associative array.
Parameters
aarray | Associative array. |
desc | Flag for sorting (descending/ascending). By default, No.desc. |
Returns
Value-sorted array of tuples with elements of the associative array.
deprecated("Use sortAssocArrayItemsByKeys and sortAssocArrayItemsByValues") void orderAssociativeArray(alias by, V, K)(in V[K] aarray, out K[] orderedKeys, out V[] orderedValues)
if(by == "values" || by == "keys")
The function arranges the associative array by the required sorting method (string "by" is equal to "values" or "keys"), returns an array of keys and an array of values.
deprecated("Use sortAssocArrayItemsByKeys") void orderAssociativeArrayByKeys(V, K)(in V[K] aarray, out K[] orderedKeys, out V[] orderedValues)
The function arranges the associative array by keys, returns an array of keys and an array of values.
deprecated("sortAssocArrayItemsByValues") void orderAssociativeArrayByValues(V, K)(in V[K] aarray, out K[] orderedKeys, out V[] orderedValues)
The function arranges the associative array by values, returns an array of keys and an array of values.
V[K] mixAssociativeArrays(K, V)(V[K] firstArray, V[K] secondArray)
This function combines two associative arrays, returns new associative array. If two arrays have the same keys, the values from the first array are used.
string getOptionValue(string[] args, string flag, string altFlag = "")
Function to get a value by parameter. Used to process command line arguments.
Parameters
args | Command line arguments. |
flag | Parameter with "--". |
altFlag | Synonym for the flat. By default, empty. |
Returns
The value of the required parameter.
string extractOptionValue(ref string[] args, string flag, string altFlag = "")
Function for extracting of value by flag. Unlike getOptionValue(), this function changes the passed args, removing the flag with a value.
Parameters
args | Command line arguments. Changes while the function is running. |
flag | Parameter with "--". |
altFlag | Synonym for the flat. By default, empty. |
Returns
The value of the required parameter.
Example
string[] args = "app -a value1 value2 -b parameter --nothing".split;
assert("parameter" == args.getOptionValue("-b"));
assert("value1" == args.getOptionValue("-a"));
assert("" == args.getOptionValue("--nothing"));
assert(args == "app -a value1 value2 -b parameter --nothing".split);
assert("parameter" == args.extractValueForFlag("-b"));
assert("app -a value1 value2 --nothing".split == args);
assert("value1" == args.extractValueForFlag("-a"));
assert("app value2 --nothing".split == args);
args = "-a value1 value2 -b parameter --nothing".split;
assert("parameter" == args.getOptionValue("-b"));
assert("value1" == args.getOptionValue("-a"));
assert("" == args.getOptionValue("--nothing"));
assert("parameter" == args.extractValueForFlag("-b"));
assert("-a value1 value2 --nothing".split == args);
assert("value1" == args.extractValueForFlag("-a"));
assert("value2 --nothing".split == args);
args = `build --file=/home/user/Project_1/Makefile`.split;
assert("/home/user/Project_1/Makefile" == args.getOptionValue("--file"));
string[] getOptionRange(string[] args, string flag, string altFlag = "")
Function to get values as array by flag.
Parameters
args | Command line arguments. |
flag | Parameter with "--". |
altFlag | Synonym for the flat. By default, empty. |
Returns
array of values after the flag.
string[] extractOptionRange(ref string[] args, string flag, string altFlag = "")
Function for extracting of value as array by flag. Unlike getOptionRange(), this function changes the passed arguments (args), removing the flag with a value.
Parameters
args | Command line arguments. Changes while the function is running. |
flag | Parameter with "--". |
altFlag | Synonym for the flat. By default, empty. |
Returns
array of values after the flag.
Example
string[] args = "app -a value1 value2 -b parameter --nothing".split;
assert(["value1", "value2"] == getOptionRange(args, "-a"));
assert(["parameter"] == getOptionRange(args, "-b"));
string[] nothing = getOptionRange(args, "--nothing");
assert(nothing.empty);
args = "app --alt value1 value2 -b parameter --nothing".split;
assert(["value1", "value2"] == getOptionRange(args, "-a", "--alt"));
args = "app -a -b thing".split;
string[] vacuum = getOptionRange(args, "-a");
assert(vacuum.empty);
args = "app -a value1 value2 -b parameter --nothing".split;
assert("value1 value2".split == extractOptionRange(args, "-a"));
assert("app -b parameter --nothing".split == args);
args = "-a value1 value2 -b parameter --nothing".split;
assert("value1 value2".split == extractOptionRange(args, "-a"));
assert("-b parameter --nothing".split == args);
string getOctalForm(ulong value)
The function converts integer number into an octal form, returns as a string.
Example
short eight = 8;
assert(getOctalForm(eight) == "10");
assert(33261.getOctalForm == "100755");
T[] removeElementsByContent(T)(T[] haystack, T needle)
The function returns an array without unnecessary elements.
Example
auto arr = [1, 8, 17, 4, 23, 8, 8, 3, 13, 19, 8];
auto res = arr.removeElementsByContent(8);
assert(res == [1, 17, 4, 23, 3, 13, 19]);
auto lines = ["", "straw", "", "", "one more straw", "", ""];
auto straws = lines.removeElementsByContent("");
assert(straws == ["straw", "one more straw"]);
string urlEncode(in string[string] values)
Encode associative array using www-form-urlencoding (copied from std.uri).
Parameters
values | An associative array containing the values to be encoded. |
Returns
A string encoded using www-form-urlencoding.
string stripRight(string line, in char symbol = ' ') nothrow
Cuts off consecutive unnecessary characters from the right side.
Returns
truncated string.
string stripRight(string line, in char[] symbols) nothrow
Cuts off consecutive unnecessary characters from the right side.
Returns
truncated string.
size_t countElements(R, E)(R range, E value) nothrow pure @safe
if(isInputRange!R)
Counts the number of required elements in a range.
Parameters
range | Some input range. |
value | Value to find. |
Returns
number of required elements.
T[] divideByElemNumber(T)(T arr, size_t n) nothrow pure @safe
if(std.traits.isArray!T)
in {
assert (arr.length % n == 0);
}
Divides an array: makes a new array of arrays containing elements from source array. Each subarray contains specified number of elements.
Parameters
arr | Source array. |
n | Number of elements in each new subarray. |