mtext
Text and strings in D; mtext 2.0
For both Phobos and Tango.
Trademarks:
Unicode(tm) is a trademark of Unicode, Inc.
- struct MString(StringAllocator);
- Unicode string structure that stores strings in a format that is easiest to index, slice, and access UTF-32 (dchar) code points,
as well as attempts to be space efficient.
The size of this structure is guaranteed to be the size of char[] (mstring.sizeof == (char[]).sizeof).
This template allows an allocator.
Use the "mstring" type for the default string type.
- alias Allocator;
- This string's allocator.
- size_t length();
- Property:
get the length of the string.
- TypeInfo type();
- Property:
get the type of the underlying array of characters. May be void if not initialized.
- mstring opCall(char[] s);
mstring opCall(wchar[] s);
mstring opCall(dchar[] s);
- Create a new instance of mstring.
The string passed in may be used as-is, and any string modifying functions may modify the original string memory.
- mstring opCall();
- Shortcut for a null, and thus empty, string: mstring()
- void opAssign(char[] s);
void opAssign(wchar[] s);
void opAssign(dchar[] s);
- Assignment operator.
- mstring empty();
- Property:
get an empty string.
- int opApply(int delegate(ref size_t, ref dchar) dg);
int opApply(int delegate(ref dchar) dg);
- For each character. Modifying the inout dchar in the foreach body may be done in-place or may cause reallocation.
- dchar opIndex(size_t i);
- Index to a single character.
- void opIndexAssign(dchar ch, size_t i);
- Assign to a single character. This may be done in-place or may cause reallocation.
- mstring opSlice(size_t i1, size_t i2);
- Get an mstring slice. The returned slice may or may not refer to the same memory, depending on the allocator.
- void opSliceAssign(mstring s2, size_t i1, size_t i2);
- Assign an mstring to a slice. This may be done in-place or may cause reallocation.
- void opSliceAssign(dchar ch, size_t i1, size_t i2);
void opSliceAssign(dchar ch);
- Assign a repeating character to a slice. This may be done in-place or may cause reallocation.
- char[] toString();
- Convert this string to a UTF-8 string of chars; directly returns toUTF8(). Note that this returns normal D memory, not the mstring allocator.
- mstring opCat(mstring s2);
mstring opCat(char[] s2);
mstring opCat(wchar[] s2);
mstring opCat(dchar[] s2);
mstring opCat_r(char[] s1);
mstring opCat_r(wchar[] s1);
mstring opCat_r(dchar[] s1);
- Concatenation; always returns a copy.
- mstring opCatAssign(mstring s2);
mstring opCatAssign(char[] s2);
mstring opCatAssign(wchar[] s2);
mstring opCatAssign(dchar[] s2);
mstring opCatAssign(dchar ch);
- Concatenate and assign. This may be done in-place using adjacent memory or may cause reallocation.
- mstring fromASCII(char[] s);
mstring fromASCII(ubyte[] s);
mstring fromASCII(byte[] s);
- Create a new instance of string based on an ASCII-only string.
This is faster than string(s) (opCall).
The string passed in may be used as-is, and any string modifying functions may modify the original string memory.
- mstring fromBMP(wchar[] s);
- Create a new instance of string based on an BMP-Unicode-only wide-character string.
This is faster than string(s) (opCall).
The string passed in may be used as-is, and any string modifying functions may modify the original string memory.
Information on BMP can be found at http://en.wikipedia.org/wiki/Basic_Multilingual_Plane
- char[] toUTF8(bool useAllocator = false);
wchar[] toUTF16(bool useAllocator = false);
dchar[] toUTF32(bool useAllocator = false);
- Convert the string to the different UTF types. Note that the default behavior returns normal D memory, not the mstring allocator; set useAllocator to true to use the mstring allocator.
- int compare(mstring s2, bool ignoreCase = false);
int compare(char[] s2, bool ignoreCase = false);
int compare(wchar[] s2, bool ignoreCase = false);
int compare(dchar[] s2, bool ignoreCase = false);
- Compare this mstring with another. If ignoreCase is true, 'a' through 'z' are compared case insensitively.
It is safe to compare strings with different underlying character UTF types.
Returns:
- < 0 if this < s2
- = 0 if match
- > 0 if this > s2
- int find(mstring s2, bool ignoreCase = false);
int find(char[] s2, bool ignoreCase = false);
int find(wchar[] s2, bool ignoreCase = false);
int find(dchar[] s2, bool ignoreCase = false);
- Find a string within this mstring. If ignoreCase is true, 'a' through 'z' are compared case insensitively.
Returns:
the starting index of the found string, or -1 if not found.
- bool startsWith(mstring s, bool ignoreCase = false);
bool startsWith(char[] s, bool ignoreCase = false);
bool startsWith(wchar[] s, bool ignoreCase = false);
bool startsWith(dchar[] s, bool ignoreCase = false);
bool endsWith(mstring s, bool ignoreCase = false);
bool endsWith(char[] s, bool ignoreCase = false);
bool endsWith(wchar[] s, bool ignoreCase = false);
bool endsWith(dchar[] s, bool ignoreCase = false);
- Returns:
true if this mstring starts with, or ends with, the provided string. If ignoreCase is true, 'a' through 'z' are compared case insensitively.
- void* ptr();
- Property:
get the pointer to the internal string memory.
- bool isNull();
- Returns:
true if the pointer to the internal string memory is null.
- bool isEmpty();
- Returns:
true if this string has a length of 0, which includes a null mstring.
- int opEquals(mstring s2);
int opEquals(char[] s2);
int opEquals(wchar[] s2);
int opEquals(dchar[] s2);
int opCmp(mstring s2);
int opCmp(char[] s2);
int opCmp(wchar[] s2);
int opCmp(dchar[] s2);
- Comparison operators. It is safe to compare strings with different underlying character UTF types.
- mstring compact();
- Reallocates this string using a smaller char type if possible. Generally only needed when slicing.
- mstring dup();
- Returns:
duplicate string using new memory; compacts the returned string as necessary.
- void release();
- Release the string memory. Other strings created from this string are still valid, but the underlying memory (ptr) may become invalid.
- size_t MAX_LENGTH;
- The maximum amount of characters allowed in a string.
- class MStringException: object.Exception;
- this(char[] s);
- enum MStringAllocatorFlags;
- Flags for an allocator.
- NONE
- MUTABLE
- The string can be modified.
- REF_EXTERN
- External references (toUTFN(x, false)) don't cause duplication.
- struct MStringAllocator;
- String allocators. An allocator must define all the below static methods and constants.
Allocators provided:
MStringDGcAllocator:
D's garbage collector allocator (the default);
MStringCMallocAllocator:
C's malloc allocator, need to use release() to prevent leaks;
MStringMakeAllocatorImmutable:
immutable allocator wrapper: MStringMakeAllocatorImmutable(Allocator);
- T[] alloc(T)(size_t count);
- Allocate and return count bytes of type T. Must throw an exception on out-of-memory.
- T[] realloc(T)(T[] buffer, size_t count);
- Reallocate buffer and return count bytes of type T, either in-place or new memory. Must throw an exception on out-of-memory.
- T[] concat(T)(T[] buffer, T[] bufferappend);
- Concatenate buffer and bufferappend, reallocating (realloc) buffer.
- T[] reference(T)(T[] buffer);
- Reference the buffer for internal string use. May duplicate or use as-is, depending on the allocator.
- static void free(void* p);
- Release previously allocated or reallocated buffer.
- static MStringAllocatorFlags FLAGS;
- Constant specifying this allocator's flags.
- alias mstring;
- Default string type using default D GC allocator.
- alias imstring;
- An immutable version of mstring. Must be enabled via version=MSTRING_IMSTRING.
- bool isAlphaNumericDiacritic(dchar ch);
- bool isSymbolDiacritic(dchar ch);
- bool isSupplimentDiacritic(dchar ch);
- Added to version 4.1 of the Unicode Standard.
- bool isDiacritic(dchar ch);
- A diacritical mark, or accent mark, combining character.
Returns:
true if isAlphaNumericDiacritic, isSymbolDiacritic or isSupplimentDiacritic.
- bool isHalfMark(dchar ch);
- Half mark combining character.
- bool isCombiningCharacter(dchar ch);
- Includes all of the above diacritics and half marks.
- const wchar REPLACEMENT_CHARACTER;
Page generated by Ddoc.