ae.utils.text

Utility code related to string and text processing.

Modules

ascii
module ae.utils.text.ascii

Simple (ASCII-only) text-processing functions, for speed and CTFE.

html
module ae.utils.text.html

ae.utils.text.html

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.

Functions

UTF8ToRaw
ascii UTF8ToRaw(in char[] r)

Undo rawToUTF8.

asciiSplit
T[][] asciiSplit(T[] text)

Like std.string.split (one argument version, which splits by whitespace), but only splits by ASCII and does not autodecode.

contains
bool contains(T[] str, U[] what)

Convenience helper

eatLine
T[] eatLine(ref T[] s, bool eatIncompleteLines = true)

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.

findBestMatch
sizediff_t findBestMatch(in string[] items, string target, float threshold = 0.7)

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

formatAs
string formatAs(auto ref T obj, string fmt)

CTFE helper

fromZArray
C[] fromZArray(ref 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).

nullStringTransform
string nullStringTransform(in char[] s)

Where a delegate with this signature is required.

rawToUTF8
string rawToUTF8(in char[] s)

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

sarrayFromHex
void sarrayFromHex(in ref Hex hex, ref ubyte[N] buf)

Fast version for static arrays of known length.

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

Covering slice-list of s with interleaved whitespace.

selectBestFrom
string selectBestFrom(in string[] items, string target, float threshold = 0.7)

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

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)

Templates

fpToString
template fpToString(F)

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

Meta

Authors

Vladimir Panteleev <vladimir@thecybershadow.net>

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/.