The OpenD Programming Language

translate

This is an ASCII-only overload of _translate. It will not work with Unicode. It exists as an optimization for the cases where Unicode processing is not necessary.

Unlike the other overloads of _translate, this one does not take an AA. Rather, it takes a string generated by makeTransTable.

The array generated by makeTransTable is 256 elements long such that the index is equal to the ASCII character being replaced and the value is equal to the character that it's being replaced with. Note that translate does not decode any of the characters, so you can actually pass it Extended ASCII characters if you want to (ASCII only actually uses 128 characters), but be warned that Extended ASCII characters are not valid Unicode and therefore will result in a UTFException being thrown from most other Phobos functions.

Also, because no decoding occurs, it is possible to use this overload to translate ASCII characters within a proper UTF-8 string without altering the other, non-ASCII characters. It's replacing any code unit greater than 127 with another code unit or replacing any code unit with another code unit greater than 127 which will cause UTF validation issues.

Parameters

str const(char)[]

The original string.

transTable const(char)[]

The string indicating which characters to replace and what to replace them with. It is generated by makeTransTable.

toRemove const(char)[]

The characters to remove from the string.

Examples

auto transTable1 = makeTrans("eo5", "57q");
assert(translate("hello world", transTable1) == "h5ll7 w7rld");

assert(translate("hello world", transTable1, "low") == "h5 rd");

See Also

Meta