Chop the given source by stripping the provided match from the left hand side. Returns a slice of the original content
Chop the given source by stripping the provided match from the right hand side. Returns a slice of the original content
Combine a series of text segments together, each prefixed and/or postfixed with optional strings. An optional output buffer can be provided to avoid heap activity - which should be large enough to contain the entire output, otherwise the heap will be used instead.
Returns whether or not the provided array contains an instance of the given match
Returns whether or not the provided array contains an instance of the given match
Count all instances of match within source
Split the provided array wherever a delimiter-set instance is found, and return the resultant segments. The delimiters are excluded from each of the segments. Note that delimiters are matched as a set of alternates rather than as a pattern.
Iterator to isolate text elements.
Split the provided array on the first pattern instance, and return the resultant head and tail. The pattern is excluded from the two segments.
Return the index of the next instance of 'match' starting at position 'start', or source.length where there is no match.
Returns the index of the first match in str, failing once length is reached. Note that we return 'length' for failure and a 0-based index on success
Is the argument a whitespace character?
jhash() -- hash a variable-length key into a 32-bit value
Combine a series of text segments together, each appended with a postfix pattern. An optional output buffer can be provided to avoid heap activity - it should be large enough to contain the entire output, otherwise the heap will be used instead.
Return the indexed line, where each line is identified by a \n or \r\n combination. The line terminator is stripped from the resultant line
Iterator to isolate lines.
Return the index of the next instance of 'match' starting at position 'start', or source.length where there is no match.
Return the index of the next instance of 'match' starting at position 'start', or source.length where there is no match.
Return the index of the prior instance of 'match' starting just before 'start', or source.length where there is no match.
Return the index of the prior instance of 'match' starting just before 'start', or source.length where there is no match.
Return whether or not the two arrays have matching content
Returns the index of a mismatch between s1 & s2, failing when length is reached. Note that we return 'length' upon failure (array content matches) and a 0-based index upon success.
Iterator to isolate text elements.
Combine a series of text segments together, each appended with an optional postfix pattern. An optional output buffer can be provided to avoid heap activity - it should be large enough to contain the entire output, otherwise the heap will be used instead.
Combine a series of text segments together, each prepended with a prefix pattern. An optional output buffer can be provided to avoid heap activity - it should be large enough to contain the entire output, otherwise the heap will be used instead.
Iterator to isolate optionally quoted text elements.
Repeat an array for a specific number of times. An optional output buffer can be provided to avoid heap activity - it should be large enough to contain the entire output, otherwise the heap will be used instead.
Replace all instances of one element with another (in place)
Return the index of the prior instance of 'match' starting just before 'start', or source.length where there is no match.
Split the provided array wherever a pattern instance is found, and return the resultant segments. The pattern is excluded from each of the segments.
Trim the given array by stripping the provided match from both ends. Returns a slice of the original content
Trim the given array by stripping the provided match from the left hand side. Returns a slice of the original content
Trim the given array by stripping the provided match from the right hand side. Returns a slice of the original content
Substitute all instances of match from source. Set replacement to null in order to remove instead of replace
Split the provided array on the last pattern instance, and return the resultant head and tail. The pattern is excluded from the two segments.
Convert text into a set of lines, where each line is identified by a \n or \r\n combination. The line terminator is stripped from each resultant array
Trim the provided array by stripping whitespace from both ends. Returns a slice of the original content
Trim the provided array by stripping whitespace from the left. Returns a slice of the original content
Trim the provided array by stripping whitespace from the right. Returns a slice of the original content
Convert 'escaped' chars to normal ones: \t => ^t for example. Supports \" \' \\ \a \b \f \n \r \t \v
Helper fruct for iterator patterns(). A fruct is a low impact mechanism for capturing context relating to an opApply (conjunction of the names struct and foreach)
Applying the D "import alias" mechanism to this module is highly recommended, in order to limit namespace pollution:
import Util = ocean.text.Util; auto s = Util.trim (" foo ");
Function templates:
trim (source) // trim whitespace triml (source) // trim whitespace trimr (source) // trim whitespace strip (source, match) // trim elements stripl (source, match) // trim elements stripr (source, match) // trim elements chopl (source, match) // trim pattern match chopr (source, match) // trim pattern match delimit (src, set) // split on delims split (source, pattern) // split on pattern splitLines (source); // split on lines head (source, pattern, tail) // split to head & tail join (source, postfix, output) // join text segments prefix (dst, prefix, content...) // prefix text segments postfix (dst, postfix, content...) // postfix text segments combine (dst, prefix, postfix, content...) // combine lotsa stuff repeat (source, count, output) // repeat source replace (source, match, replacement) // replace chars substitute (source, match, replacement) // replace/remove matches count (source, match) // count instances contains (source, match) // has char? containsPattern (source, match) // has pattern? index (source, match, start) // find match index locate (source, match, start) // find char locatePrior (source, match, start) // find prior char locatePattern (source, match, start); // find pattern locatePatternPrior (source, match, start); // find prior pattern indexOf (s*, match, length) // low-level lookup mismatch (s1*, s2*, length) // low-level compare matching (s1*, s2*, length) // low-level compare isSpace (match) // is whitespace? unescape(source, output) // convert '\' prefixes lines (str) // foreach lines quotes (str, set) // foreach quotes delimiters (str, set) // foreach delimiters patterns (str, pattern) // foreach patterns
Please note that any 'pattern' referred to within this module refers to a pattern of characters, and not some kind of regex descriptor. Use the Regex module for regex operation.
Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. See LICENSE_TANGO.txt for details.
Copyright (c) 2004 Kris Bell. Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH. All rights reserved.
Apr 2004: Initial release Dec 2006: South Seas version
Placeholder for a variety of wee functions.
Several of these functions return an index value, representing where some criteria was identified. When said criteria is not matched, the functions return a value representing the array length provided to them. That is, for those scenarios where C functions might typically return -1 these functions return length instead. This operate nicely with D slices:
The contains() function is more convenient for trivial lookup cases:
Note that where some functions expect a size_t as an argument, the D template-matching algorithm will fail where an int is provided instead. This is the typically the cause of "template not found" errors. Also note that name overloading is not supported cleanly by IFTI at this time, so is not applied here.