ae.utils.text

Utility code related to string and text processing.

Public Imports

ae.utils.regex
public import ae.utils.regex;
Undocumented in source.

Members

Aliases

CIAsciiString
alias CIAsciiString = NormalizedArray!(immutable(char), s => s.byCodeUnit.map!(std.ascii.toLower))

Case-insensitive ASCII string.

CIUniString
alias CIUniString = NormalizedArray!(immutable(char), s => s.map!(std.uni.toLower))

Case-insensitive Unicode string.

ascii
alias ascii = string

Semantic alias for an array of immutable bytes containing some ASCII-based 8-bit character encoding. Might be UTF-8, but not necessarily - thus, is a semantic superset of the D "string" alias.

asciiToLower
alias asciiToLower = xlat!(asciiLower, char)
Undocumented in source.
asciiToUpper
alias asciiToUpper = xlat!(asciiUpper, char)
Undocumented in source.
doubleToString
alias doubleToString = fpToString!double
Undocumented in source.
indexOf
alias indexOf = std.string.indexOf
Undocumented in source.
toLowerHex
alias toLowerHex = toHex!lowerHexDigits
Undocumented in source.

Enums

fpFormatString
eponymoustemplate fpFormatString(T)

Format string for a FP type which includes all necessary significant digits

significantDigits
eponymoustemplate significantDigits(T : real)

How many significant decimal digits does a FP type have (determined empirically)

Functions

UTF8ToRaw
ascii UTF8ToRaw(char[] r)

Undo rawToUTF8.

arrayFromHex
ubyte[] arrayFromHex(char[] hex, ubyte[] buf)
Undocumented in source. Be warned that the author may not have intended to support it.
asciiStrip
T[] asciiStrip(T[] s)
Undocumented in source. Be warned that the author may not have intended to support it.
camelCaseJoin
string camelCaseJoin(string[] arr)
Undocumented in source. Be warned that the author may not have intended to support it.
contains
bool contains(T[] str, U[] what)

Convenience helper

eatLine
T[] eatLine(T[] s, bool eatIncompleteLines)

Consume a LF or CRLF terminated line from s. Sets s to null and returns the remainder if there is no line terminator in s.

fastReplace
T[] fastReplace(T[] what, T[] from, T[] to)
Undocumented in source. Be warned that the author may not have intended to support it.
fastSplit
T[][] fastSplit(T[] s, U d)
Undocumented in source. Be warned that the author may not have intended to support it.
findBestMatch
sizediff_t findBestMatch(string[] items, string target, float threshold)

Select best match from a list of items. Returns -1 if none are above the threshold.

forceValidUTF8
string forceValidUTF8(string s)
Undocumented in source. Be warned that the author may not have intended to support it.
formatAs
string formatAs(T obj, string fmt)

CTFE helper

fromHex
T fromHex(const(C)[] s)
Undocumented in source. Be warned that the author may not have intended to support it.
fromZArray
C[] fromZArray(C[n] arr)
C[] fromZArray(C[] arr)

Return the slice up to the first NUL character, or of the whole array if none is found.

hexDump
string hexDump(const(void)[] b)

Formats binary data as a hex dump (three-column layout consisting of hex offset, byte values in hex, and printable low-ASCII characters).

newlinesToSpaces
T[] newlinesToSpaces(T[] s)
Undocumented in source. Be warned that the author may not have intended to support it.
normalizeWhitespace
ascii normalizeWhitespace(ascii s)
Undocumented in source. Be warned that the author may not have intended to support it.
nullStringTransform
string nullStringTransform(char[] s)

Where a delegate with this signature is required.

numberToString
string numberToString(T v)
Undocumented in source. Be warned that the author may not have intended to support it.
randomString
string randomString(int length, string chars)
Undocumented in source. Be warned that the author may not have intended to support it.
rawToUTF8
string rawToUTF8(char[] s)

Convert any data to a valid UTF-8 bytestream, so D's string functions can properly work on it.

segmentByWhitespace
T[][] segmentByWhitespace(T[] s)

Covering slice-list of s with interleaved whitespace.

selectBestFrom
string selectBestFrom(string[] items, string target, float threshold)

Select best match from a list of items. Returns null if none are above the threshold.

splitAsciiLines
T[][] splitAsciiLines(T[] text)
Undocumented in source. Be warned that the author may not have intended to support it.
splitByCamelCase
string[] splitByCamelCase(string s)
Undocumented in source. Be warned that the author may not have intended to support it.
stringDistance
int stringDistance(string s, string t)

Simpler implementation of Levenshtein string distance

stringSimilarity
float stringSimilarity(string string1, string string2)

Return a number between 0.0 and 1.0 indicating how similar two strings are (1.0 if identical)

toDec
char[] toDec(N o, char[U] buf)

Writes n as decimal number to buf (right-aligned), returns slice of buf containing result.

toDec
string toDec(T n)
Undocumented in source. Be warned that the author may not have intended to support it.
toDecFixed
void toDecFixed(N n, char[U] buf)
char[U] toDecFixed(N n)

Print an unsigned integer as a zero-padded, right-aligned decimal number into a buffer

toHex
string toHex(ubyte[] data, char[] buf)
Undocumented in source. Be warned that the author may not have intended to support it.
toHex
void toHex(T n, char[U] buf)
Undocumented in source. Be warned that the author may not have intended to support it.
xlat
void xlat(T[] buf)
Undocumented in source. Be warned that the author may not have intended to support it.

Templates

DecimalSize
template DecimalSize(T : ulong)
Undocumented in source.
eatLine
deprecated template eatLine(OnEof onEof)
Undocumented in source.
fpToString
template fpToString(F)

Get shortest string representation of a FP type that still converts to exactly the same number.

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <vladimir@thecybershadow.net>