Go to the source code of this file.
Functions | |
C void | memmove (void *dst, void *src, uint bytes) |
class | MutableStringTemplate (T) |
class | StringTemplate (T) |
typedef | StringTemplate (char) String |
typedef | MutableStringTemplate (char) MutableString |
Variables | |
module mango text | String |
import mango text | Text |
import mango convert | Type |
import mango convert mango convert | Format |
import mango convert mango convert mango convert | Unicode |
import mango text model | UniString |
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for damages of any kind arising from the use of this software.
Permission is hereby granted to anyone to use this software for any purpose, including commercial applications, and to alter it and/or redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment within documentation of said product would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any distribution of the source.
4. Derivative works are permitted, but they must carry this notice in full and credit the original source.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class MutableString(T) : String!(T) { reset the content MutableString set (T[] chars, bool mutable=true); MutableString set (String other, bool mutable=true);
get the index and length of the current selection uint selection (inout int length);
make a selection MutableString select (int start=0, int length=int.max);
move the selection around bool select (T c); bool select (T[] chars); bool select (String other); bool rselect (T c); bool rselect (T[] chars); bool rselect (String other);
append behind current selection MutableString append (String other); MutableString append (char[] other); MutableString append (wchar[] other); MutableString append (dchar[] other); MutableString append (T chr, int count=1); MutableString append (int value, T[] format=null); MutableString append (long value, T[] format=null); MutableString append (double value, T[] format=null);
format and layout behind current selection MutableString format (T[] format, ...); MutableString layout (T[] layout ...);
insert before current selection MutableString prepend (T[] other); MutableString prepend (String other); MutableString prepend (T chr, int count=1);
replace current selection MutableString replace (T chr); MutableString replace (T[] other); MutableString replace (String other);
remove current selection MutableString remove ();
truncate at point, or current selection MutableString truncate (int point = int.max);
trim content MutableString trim ();
return content T[] aliasOf (); }
class String(T) : UniString { iterate across content opApply (int delegate(inout T) dg);
hash content uint toHash ();
return length of content uint length ();
compare content bool equals (T[] other); bool equals (String other); bool ends (T[] other); bool ends (String other); bool starts (T[] other); bool starts (String other); int compare (T[] other); int compare (String other); int opEquals (Object other); int opCmp (Object other);
copy content T[] copy (T[] dst); T[] copy (); }
abstract class UniString { convert content abstract char[] utf8 (char[] dst = null); abstract wchar[] utf16 (wchar[] dst = null); abstract dchar[] utf32 (dchar[] dst = null); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Definition in file String.d.
|
|
|
MutableString is a string class that stores Unicode characters. Indexes and lengths of strings always count code units, not code points. This is similar to traditional multi-byte string handling. Operations on strings do not test for code point boundaries since the approach taken here is based upon pattern-matching rather than direct indexing. MutableString maintains a current "selection", controlled via the select() and rselect() methods. Append(), prepend(), replace() and remove() each operate with respect to the selection. The select() methods themselves operate with respect to the current selection also, providing a means of iterating across matched patterns. To reset the selection to the entire string, use the select() method with no arguments. Create an empty MutableString with the specified available space Create a MutableString upon the provided content. If said content is immutable (read-only) then you might consider setting the 'mutable' parameter to false. Doing so will avoid allocating heap-space for the content until it is modified. Create a MutableString via the content of a MutableString. If said content is immutable (read-only) then you might consider setting the 'mutable' parameter to false. Doing so will avoid allocating heap-space for the content until it is modified via MutableString methods. Create a MutableString via the content of a String. Note that the default is to assume the content is immutable Set the content to the provided array. Parameter 'mutable' specifies whether the given array is likely to change. If not, the array is aliased until such time it is altered. Replace the content of this MutableString. If the new content is immutable (read-only) then you might consider setting the 'mutable' parameter to false. Doing so will avoid allocating heap-space for the content until it is modified via one of these methods. Return the index and length of the current selection Explicitly set the current selection Find the first occurrence of a BMP code point in a string. A surrogate code point is found only if its match in the text is not part of a surrogate pair. Find the first occurrence of a substring in a string. The substring is found at code point boundaries. That means that if the substring begins with a trail surrogate or ends with a lead surrogate, then it is found only if these surrogates stand alone in the text. Otherwise, the substring edge units would be matched against halves of surrogate pairs. Find the first occurrence of a substring in a string. The substring is found at code point boundaries. That means that if the substring begins with a trail surrogate or ends with a lead surrogate, then it is found only if these surrogates stand alone in the text. Otherwise, the substring edge units would be matched against halves of surrogate pairs. Find the last occurrence of a BMP code point in a string. A surrogate code point is found only if its match in the text is not part of a surrogate pair. Find the last occurrence of a BMP code point in a string. A surrogate code point is found only if its match in the text is not part of a surrogate pair. Find the last occurrence of a substring in a string. The substring is found at code point boundaries. That means that if the substring begins with a trail surrogate or ends with a lead surrogate, then it is found only if these surrogates stand alone in the text. Otherwise, the substring edge units would be matched against halves of surrogate pairs. Append partial text to this MutableString Append text to this MutableString Append text to this MutableString Append text to this MutableString Append a count of characters to this MutableString Append an integer to this MutableString, using standard printf() notation Append a long to this MutableString, using standard printf() notation Append a double to this MutableString, using standard printf() notation Format a set of arguments using the standard printf() formatting notation Insert characters into this MutableString Insert text into this MutableString Insert another String into this MutableString Replace a section of this MutableString with the specified character Replace a section of this MutableString with the specified array Replace a section of this MutableString with the specified String Remove the selection from this MutableString and reset the selection to zero length Remove the selection from this MutableString and reset the selection to zero length Truncate this string. Default behaviour is to truncate at the current append point Arranges text strings in order, using indices to specify where each particular argument should be positioned within the text. This is handy for collating I18N components.
auto string = new MutableString; string.layout ("%2 %1", "one", "two"); The index numbers range from one through nine Remove leading and trailing whitespace from this String, and reset the selection to the trimmed content Return an alias to the content of this MutableString make room available to insert or append something Replace a section of this MutableString with the specified character Allocate memory due to a change in the content. We handle the distinction between mutable and immutable here. Internal method to support MutableString appending Initialize this MutableString. Allocate conversion buffers and prime the formatter Support for the formatter, to convert from one encoding to another Definition at line 173 of file String.d. References convert(), Format, FormatStructTemplate(), into(), Into(), memmove(), MutableString(), MutableStringTemplate(), String, StringTemplate(), and type(). Referenced by MutableStringTemplate(), and StringTemplate(). |
|
Immutable string Hidden constructor Construct read-only wrapper around the given content Set the comparator delegate Hash this String Return the length of the valid content Is this String equal to another? Is this String equal to the the provided text? Does this String end with another? Does this String end with the specified string? Does this String start with another? Does this String start with the specified string? Compare this String start with another. Returns 0 if the content matches, less than zero if this String is "less" than the other, or greater than zero where this String is "bigger". Compare this String start with an array. Returns 0 if the content matches, less than zero if this String is "less" than the other, or greater than zero where this String is "bigger". Return content from this String A slice of dst is returned, representing a copy of the content. The slice is clipped to the minimum of either the length of the provided array, or the length of the content minus the stipulated start point Return dup'd content from this String Convert to the AbstractString types. The optional argument dst will be resized as required to house the conversion. To minimize heap allocation, use the following pattern: String string; wchar[] buffer; wchar[] result = string.toUtf16 (buffer); if (result.length > buffer.length) buffer = result; You can also provide a buffer from the stack, but the output will be moved to the heap if said buffer is not large enough Iterate over the characters in this string. Note that this is a read-only freachable ~ the worst a user can do is alter the temporary 'c' Compare this String to another Is this String equal to another? hash() -- hash a variable-length key into a 32-bit value k : the key (the unaligned variable-length array of bytes) len : the length of the key, counting by bytes level : can be any 4-byte value Returns a 32-bit value. Every bit of the key affects every bit of the return value. Every 1-bit and 2-bit delta achieves avalanche. About 4.3*len + 80 X86 instructions, with excellent pipelining The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do h = (h & hashmask(10)); In which case, the hash table should have hashsize(10) elements. If you are hashing n strings (ub1 **)k, do it like this: for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h); By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this code any way you wish, private, educational, or commercial. It's free. See http://burlteburtle.net/bob/hash/evahash.html Use for hash table lookup, or anything where one collision in 2^32 is acceptable. Do NOT use for cryptographic purposes. Throw an exception Return the valid content from this String Pin the given index to a valid position. Pin the given index and length to a valid position. Simple comparator Compare two arrays. Returns 0 if the content matches, less than zero if A is "less" than B, or greater than zero where A is "bigger". Where the substrings match, the shorter is considered "less". Definition at line 854 of file String.d. References Exception, from(), String, StringTemplate(), TextTemplate(), UniString::utf16(), UniString::utf32(), and UniString::utf8(). Referenced by MutableStringTemplate(), and StringTemplate(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|