annotate orange/core/string.d @ 27:fc315d786f24 experimental

Added unit testing.
author Jacob Carlborg <doob@me.com>
date Fri, 19 Nov 2010 11:14:55 +0100
parents 78e5fef4bbf2
children 068e853b9c07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 * Copyright: Copyright (c) 2008-2009 Jacob Carlborg. All rights reserved.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Authors: Jacob Carlborg
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Version: Initial created: 2008
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8 module orange.core.string;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 public import orange.util.collection.Array;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
14 static import tango.stdc.stringz;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15 import tango.text.Unicode : toFold, isDigit;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 import tango.text.convert.Utf;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17 import tango.text.Util;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 alias tango.stdc.stringz.toStringz toStringz;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 alias tango.stdc.stringz.toString16z toString16z;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 alias tango.stdc.stringz.toString32z toString32z;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 alias tango.stdc.stringz.fromStringz fromStringz;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 alias tango.stdc.stringz.fromString16z fromString16z;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 alias tango.stdc.stringz.fromString32z fromString32z;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27 alias tango.text.convert.Utf.toString16 toString16;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28 alias tango.text.convert.Utf.toString32 toString32;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33 import std.string;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 import std.utf;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 import std.ctype : isxdigit;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 version = Phobos;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 private alias std.string.tolower toFold;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 alias std.utf.toUTF8 toString;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 alias std.utf.toUTF16 toString16;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43 alias std.utf.toUTF32 toString32;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 alias std.string.toStringz toStringz;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 alias std.utf.toUTF16z toString16z;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48 alias std.string.toString fromStringz;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
51 import orange.util.Traits;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
52
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 * string alias
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 alias char[] string;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61 * wstring alias
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 alias wchar[] wstring;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
65 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 * dstring alias
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 alias dchar[] dstring;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72 * Compares the $(D_PSYMBOL string) to another $(D_PSYMBOL string), ignoring case
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 * considerations. Two strings are considered equal ignoring case if they are of the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74 * same length and corresponding characters in the two strings are equal ignoring case.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
77 * str = The $(D_PSYMBOL string) first string to compare to
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
78 * anotherString = The $(D_PSYMBOL string) to compare the first $(D_PSYMBOL string) with
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
79 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 * Returns: $(D_KEYWORD true) if the arguments is not $(D_KEYWORD null) and it
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81 * represents an equivalent $(D_PSYMBOL string) ignoring case; $(D_KEYWORD false) otherwise
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
82 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83 * Throws: AssertException if the length of any of the strings is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
85 * See_Also: opEquals(Object)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
86 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 bool equalsIgnoreCase (string str, string anotherString)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
88 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90 assert(str.length > 0, "mambo.string.equalsIgnoreCase: The length of the first string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
91 assert(anotherString.length > 0, "mambo.string.equalsIgnoreCase: The length of the second string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
93 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 if (str == anotherString)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98 return toFold(str) == toFold(anotherString);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
102 * Compares the $(D_PSYMBOL wstring) to another $(D_PSYMBOL wstring), ignoring case
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 * considerations. Two wstrings are considered equal ignoring case if they are of the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 * same length and corresponding characters in the two wstrings are equal ignoring case.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
106 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 * str = The $(D_PSYMBOL wstring) first string to compre to
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 * anotherString = The $(D_PSYMBOL wstring) to compare the first $(D_PSYMBOL wstring) against
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110 * Returns: $(D_KEYWORD true) if the argument is not $(D_KEYWORD null) and it
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 * represents an equivalent $(D_PSYMBOL wstring) ignoring case; (D_KEYWORD
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112 * false) otherwise
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 * Throws: AssertException if the length of any of the wstrings is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 * See_Also: opEquals(Object)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118 bool equalsIgnoreCase (wstring str, wstring anotherString)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 assert(str.length > 0, "mambo.string.equalsIgnoreCase: The length of the first string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122 assert(anotherString.length > 0, "mambo.string.equalsIgnoreCase: The length of the second string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 if (str == anotherString)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 return toFold(str) == toFold(anotherString);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
131
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
132 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
133 return toFold(toUTF8(str)) == toFold(toUTF8(anotherString));
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
136 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 * Compares the $(D_PSYMBOL dstring) to another $(D_PSYMBOL dstring), ignoring case
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138 * considerations. Two wstrings are considered equal ignoring case if they are of the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139 * same length and corresponding characters in the two wstrings are equal ignoring case.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142 * str = The $(D_PSYMBOL dstring) first string to compare to
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 * anotherString = The $(D_PSYMBOL wstring) to compare the first $(D_PSYMBOL dstring) against
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
145 * Returns: $(D_KEYWORD true) if the argument is not $(D_KEYWORD null) and it
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 * represents an equivalent $(D_PSYMBOL dstring) ignoring case; $(D_KEYWORD false) otherwise
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148 * Throws: AssertException if the length of any of the dstrings are 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 * See_Also: opEquals(Object)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152 bool equalsIgnoreCase (dstring str, dstring anotherString)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 assert(str.length > 0, "mambo.string.equalsIgnoreCase: The length of the first string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156 assert(anotherString.length > 0, "mambo.string.equalsIgnoreCase: The length of the second string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
157 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 if (str == anotherString)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161 return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 return toFold(str) == toFold(anotherString);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167 return toFold(toUTF8(str)) == toFold(toUTF8(anotherString));
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171 * Returns the char value at the specified index. An index ranges from 0 to length - 1.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172 * The first $(D_KEYWORD char) value of the sequence is at index 0, the next at index 1,
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 * and so on, as for array indexing.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 * str = the string to get the $(D_KEYWORD char) from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177 * index = the index of the $(D_KEYWORD char) value.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 * Returns: the $(D_KEYWORD char) value at the specified index of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 * The first $(D_KEYWORD char) value is at index 0.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
183 * Throws: AssertException if the $(D_CODE index) argument is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
184 * not less than the length of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
185 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 char charAt (string str, size_t index)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 assert(str.length > 0, "mambo.string.charAt: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190 assert(index <= str.length, "mambo.string.charAt: The index was to greater than the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
192 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
193 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194 return str[index];
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
196
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
197 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 * Returns the $(D_KEYWORD char) value at the specified index. An index ranges from 0 to
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 * length - 1. The first $(D_KEYWORD char) value of the sequence is at index 0, the next
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200 * at index 1, and so on, as for array indexing.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
203 * str = the wstring to get the $(D_KEYWORD char) from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 * index = the index of the $(D_KEYWORD char) value.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206 * Returns: the $(D_KEYWORD char) value at the specified index of the wstring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 * The first $(D_KEYWORD char) value is at index 0.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 * Throws: AssertException if the length of the wstring is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210 * Throws: AssertException if the $(D_CODE index) argument is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211 * not less than the length of the wstring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213 wchar charAt (wstring str, size_t index)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 assert(str.length > 0, "mambo.string.charAt: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 assert(index <= str.length, "mambo.string.charAt: The index was to greater than the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
218 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
219 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
221 return str[index];
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
222 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
224 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 * Returns the $(D_KEYWORD char) value at the specified index. An index ranges from 0 to
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 * length - 1. The first $(D_KEYWORD char) value of the sequence is at index 0, the next
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 * at index 1, and so on, as for array indexing.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230 * str = the dstring to get the $(D_KEYWORD char) from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 * index = the index of the $(D_KEYWORD char) value.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233 * Returns: the $(D_KEYWORD char) value at the specified index of the dstring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 * The first $(D_KEYWORD char) value is at index 0.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236 * Throws: AssertException if the length of the dstring is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
237 * Throws: AssertException if the $(D_CODE index) argument is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 * not less than the length of the dstring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240 dchar charAt (dstring str, size_t index)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243 assert(str.length > 0, "mambo.string.charAt: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 assert(index <= str.length, "mambo.string.charAt: The index was to greater than the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
245 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
246 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
247 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
248 return str[index];
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
249 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 * Returns a new string that is a substring of the specified string. The substring begins
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 * at the specified $(D_PARAM beginIndex) and extends to the character at index
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254 * $(D_PARAM endIndex) - 1. Thus the length of the substring is $(D_PARAM endIndex - beginIndex).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
255 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256 * Examples:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
258 * "hamburger".substring(4, 8) returns "urge"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259 * "smiles".substring(1, 5) returns "mile"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
260 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
261 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
262 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
263 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
264 * beginIndex = the beginning index, inclusive.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
265 * endIndex = the ending index, exclusive.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
266 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267 * Returns: the specified substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270 * Throws: AssertException if the $(D_PARAM beginIndex) is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 * larger than $(D_PARAM endIndex).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
272 * Throws: AssertException if $(D_PARAM endIndex) is larger than the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273 * length of the $(D_PSYMBOL string).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 string substring (string str, size_t beginIndex, size_t endIndex)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
276 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278 assert(str.length > 0, "mambo.string.substring: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
282 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
284 version (Tango) return str[beginIndex .. endIndex].dup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
285 else return str[beginIndex .. endIndex].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
287
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
288 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 * Returns a new string that is a substring of the specified string. The substring begins
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 * at the specified $(D_PARAM beginIndex) and extends to the character at index
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291 * $(D_PARAM endIndex) - 1. Thus the length of the substring is $(D_PARAM endIndex - beginIndex).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 * Examples:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
295 * "hamburger".substring(4, 8) returns "urge"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
296 * "smiles".substring(1, 5) returns "mile"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
301 * beginIndex = the beginning index, inclusive.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302 * endIndex = the ending index, exclusive.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
303 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304 * Returns: the specified substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
307 * Throws: AssertException if the $(D_PARAM beginIndex) is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 * larger than $(D_PARAM endIndex).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
309 * Throws: AssertException if $(D_PARAM endIndex) is larger than the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
310 * length of the $(D_PSYMBOL string).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
311 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
312 wstring substring (wstring str, size_t beginIndex, size_t endIndex)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
313 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
314 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
315 assert(str.length > 0, "mambo.string.substring: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
317 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
318 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
319 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 version (Tango) return str[beginIndex .. endIndex].dup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
322 else return str[beginIndex .. endIndex].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
323 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
324
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
326 * Returns a new string that is a substring of the specified string. The substring begins
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327 * at the specified $(D_PARAM beginIndex) and extends to the character at index
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 * $(D_PARAM endIndex) - 1. Thus the length of the substring is $(D_PARAM endIndex - beginIndex).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
330 * Examples:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332 * "hamburger".substring(4, 8) returns "urge"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
333 * "smiles".substring(1, 5) returns "mile"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
334 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
335 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
337 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338 * beginIndex = the beginning index, inclusive.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
339 * endIndex = the ending index, exclusive.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
340 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 * Returns: the specified substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
344 * Throws: AssertException if the $(D_PARAM beginIndex) is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
345 * larger than $(D_PARAM endIndex).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
346 * Throws: AssertException if $(D_PARAM endIndex) is larger than the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
347 * length of the $(D_PSYMBOL string).
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
348 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
349 dstring substring (dstring str, size_t beginIndex, size_t endIndex)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
350 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
351 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
352 assert(str.length > 0, "mambo.string.substring: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
353 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
354 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
355 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
356 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
357 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
358 version (Tango) return str[beginIndex .. endIndex].dup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
359 else return str[beginIndex .. endIndex].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
361
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
362 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363 * Returns a new string that is a substring of the specified string. The substring begins
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364 * with the character at the specified index and extends to the end of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
365 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
366 * Examples:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
367 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
368 * "unhappy".substring(2) returns "happy"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
369 * "Harbison".substring(3) returns "bison"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370 * "emptiness".substring(9) returns "" (an empty string)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
373 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
374 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375 * beginIndex = the beginning index, inclusive
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
376 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
377 * Returns: the specified substring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
378 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
379 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
380 * Throws: AssertException if the $(D_PARAM beginIndex) is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381 * larger than the length of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383 string substring (string str, size_t index)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
384 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
385 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
386 assert(str.length > 0, "mambo.string.substring: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
387 assert(index < str.length, "mambo.string.substring: The index was greater than the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
388 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
389 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
390 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
391 return str.substring(index, str.length);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
392 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
393
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
394 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
395 * Returns a new string that is a substring of the specified string. The substring begins
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396 * with the character at the specified index and extends to the end of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
397 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
398 * Examples:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
399 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
400 * "unhappy".substring(2) returns "happy"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
401 * "Harbison".substring(3) returns "bison"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
402 * "emptiness".substring(9) returns "" (an empty string)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
403 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
404 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
405 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
406 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
407 * beginIndex = the beginning index, inclusive
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
408 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
409 * Returns: the specified substring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
410 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
411 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
412 * Throws: AssertException if the $(D_PARAM beginIndex) is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
413 * larger than the length of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
414 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
415 wstring substring (wstring str, size_t index)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
416 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
417 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
418 assert(str.length > 0, "mambo.string.substring: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
419 assert(index < str.length, "mambo.string.substring: The index was greater than the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
420 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
421 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
422 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
423 return str.substring(index, str.length);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
424 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
425
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
426 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
427 * Returns a new string that is a substring of the specified string. The substring begins
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
428 * with the character at the specified index and extends to the end of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
429 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
430 * Examples:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
431 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
432 * "unhappy".substring(2) returns "happy"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
433 * "Harbison".substring(3) returns "bison"
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
434 * "emptiness".substring(9) returns "" (an empty string)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435 * ---
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
436 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439 * beginIndex = the beginning index, inclusive
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
440 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
441 * Returns: the specified substring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443 * Throws: AssertException if the length of the string is 0
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
444 * Throws: AssertException if the $(D_PARAM beginIndex) is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
445 * larger than the length of the string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
447 dstring substring (dstring str, size_t index)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
448 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 assert(str.length > 0, "mambo.string.substring: The length of the string was 0");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451 assert(index < str.length, "mambo.string.substring: The index was greater than the length of the string");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455 return str.substring(index, str.length);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
459 * Returns a new string that is a substring of the given string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
460 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
461 * This substring is the character sequence that starts at character
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
462 * position pos and has a length of n characters.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
463 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
464 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
465 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
466 * pos = position of a character in the current string to be used
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
467 * as starting character for the substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
468 * n = Length of the substring. If this value would make the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
469 * substring to span past the end of the current string content,
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
470 * only those characters until the end of the string are used.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
471 * size_t.max is the greatest possible value for an element of
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
472 * type size_t, therefore, when this value is used, all the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
473 * characters between pos and the end of the string are used as
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
474 * the initialization substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
475 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
476 * Returns: a string containing a substring of the given string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
477 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
478 * Throws: AssertException if pos is greater than the length of the string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
479 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
480 string substr (string str, size_t pos = 0, size_t n = size_t.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
481 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
482 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
483 assert(pos < str.length, "mambo.string.substr: The given position was greater than the length of the string.");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
484 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
485 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
486 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
487 size_t end;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
488
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
489 if (n == size_t.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
490 end = str.length;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
491
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
492 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
493 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
494 end = pos + n;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
495
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
496 if (end > str.length)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
497 end = str.length;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
498 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
499
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
500 version (Tango) return str[pos .. end].dup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
501 else return str[pos .. end].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
502 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
503
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
504 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
505 * Returns a new string that is a substring of the given string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
506 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
507 * This substring is the character sequence that starts at character
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
508 * position pos and has a length of n characters.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
509 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
510 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
511 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
512 * pos = position of a character in the current string to be used
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
513 * as starting character for the substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
514 * n = Length of the substring. If this value would make the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
515 * substring to span past the end of the current string content,
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
516 * only those characters until the end of the string are used.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
517 * size_t.max is the greatest possible value for an element of
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
518 * type size_t, therefore, when this value is used, all the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
519 * characters between pos and the end of the string are used as
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
520 * the initialization substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
521 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
522 * Returns: a string containing a substring of the given string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
523 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
524 * Throws: AssertException if pos is greater than the length of the string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
525 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
526 wstring substr (wstring str, size_t pos = 0, size_t n = size_t.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
527 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
528 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
529 assert(pos < str.length, "mambo.string.substr: The given position was greater than the length of the string.");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
530 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
531 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
532 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
533 size_t end;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
534
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
535 if (n == size_t.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
536 end = str.length;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
537
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
538 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
539 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
540 end = pos + n;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
541
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
542 if (end > str.length)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
543 end = str.length;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
544 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
545
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
546 version (Tango) return str[pos .. end].dup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
547 else return str[pos .. end].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
548 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
549
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
550 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
551 * Returns a new string that is a substring of the given string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
552 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
553 * This substring is the character sequence that starts at character
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
554 * position pos and has a length of n characters.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
555 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
556 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
557 * str = the string to get the substring from
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
558 * pos = position of a character in the current string to be used
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
559 * as starting character for the substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
560 * n = Length of the substring. If this value would make the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
561 * substring to span past the end of the current string content,
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
562 * only those characters until the end of the string are used.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
563 * size_t.max is the greatest possible value for an element of
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
564 * type size_t, therefore, when this value is used, all the
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
565 * characters between pos and the end of the string are used as
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
566 * the initialization substring.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
567 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
568 * Returns: a string containing a substring of the given string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
569 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
570 * Throws: AssertException if pos is greater than the length of the string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
571 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
572 dstring substr (dstring str, size_t pos = 0, size_t n = size_t.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
573 in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
574 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
575 assert(pos < str.length, "mambo.string.substr: The given position was greater than the length of the string.");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
576 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
577 body
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
578 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
579 size_t end;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
580
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
581 if (n == size_t.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
582 end = str.length;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
583
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
584 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
585 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
586 end = pos + n;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
587
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
588 if (end > str.length)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
589 end = str.length;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
590 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
591
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
592 version (Tango) return str[pos .. end].dup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
593 else return str[pos .. end].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
594 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
595
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
596 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
597 * Finds the first occurence of sub in str
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
598 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
599 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
600 * str = the string to find in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
601 * sub = the substring to find
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
602 * start = where to start finding
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
603 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
604 * Returns: the index of the substring or size_t.max when nothing was found
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
605 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
606 size_t find (string str, string sub)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
607 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
608 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
609 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
610 size_t index = str.locatePattern(sub);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
611
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
612 if (index == str.length)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
613 return size_t.max;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
614
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
615 return index;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
616 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
617
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
618 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
619 return std.string.indexOf(str, sub);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
620
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
621 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
622
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
623 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
624 * Finds the first occurence of sub in str
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
625 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
626 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
627 * str = the string to find in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
628 * sub = the substring to find
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
629 * start = where to start finding
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
630 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
631 * Returns: the index of the substring or size_t.max when nothing was found
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
632 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
633 size_t find (wstring str, wstring sub)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
634 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
635 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
636 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
637 size_t index = str.locatePattern(sub);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
638
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
639 if (index == str.length)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
640 return size_t.max;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
641
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
642 return index;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
643 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
644
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
645 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
646 return std.string.indexOf(str, sub);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
647 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
648
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
649 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
650 * Finds the first occurence of sub in str
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
651 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
652 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
653 * str = the string to find in
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
654 * sub = the substring to find
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
655 * start = where to start finding
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
656 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
657 * Returns: the index of the substring or size_t.max when nothing was found
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
658 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
659 size_t find (dstring str, dstring sub)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
660 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
661 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
662 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
663 size_t index = str.locatePattern(sub);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
664
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
665 if (index == str.length)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
666 return size_t.max;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
667
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
668 return index;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
669 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
670
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
671 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
672 return std.string.indexOf(str, sub);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
673 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
674
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
675 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
676 * Compares to strings, ignoring case differences. Returns 0 if the content
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
677 * matches, less than zero if a is "less" than b, or greater than zero
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
678 * where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
679 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
680 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
681 * a = the first array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
682 * b = the second array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
683 * end = the index where the comparision will end
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
684 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
685 * Returns: Returns 0 if the content matches, less than zero if a is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
686 * "less" than b, or greater than zero where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
687 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
688 * See_Also: mambo.collection.array.compare
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
689 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
690 int compareIgnoreCase (U = size_t) (string a, string b, U end = U.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
691 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
692 return a.toFold().compare(b.toFold(), end);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
693 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
694
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
695 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
696 * Compares to strings, ignoring case differences. Returns 0 if the content
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
697 * matches, less than zero if a is "less" than b, or greater than zero
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
698 * where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
699 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
700 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
701 * a = the first array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
702 * b = the second array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
703 * end = the index where the comparision will end
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
704 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
705 * Returns: Returns 0 if the content matches, less than zero if a is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
706 * "less" than b, or greater than zero where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
707 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
708 * See_Also: mambo.collection.array.compare
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
709 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
710 int compareIgnoreCase (U = size_t) (wstring a, wstring b, U end = U.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
711 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
712 return a.toFold().compare(b.toFold(), end);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
713 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
714
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
715 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
716 * Compares to strings, ignoring case differences. Returns 0 if the content
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
717 * matches, less than zero if a is "less" than b, or greater than zero
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
718 * where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
719 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
720 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
721 * a = the first array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
722 * b = the second array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
723 * end = the index where the comparision will end
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
724 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
725 * Returns: Returns 0 if the content matches, less than zero if a is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
726 * "less" than b, or greater than zero where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
727 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
728 * See_Also: mambo.collection.array.compare
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
729 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
730 int compareIgnoreCase (U = size_t) (dstring a, dstring b, U end = U.max)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
731 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
732 return a.toFold().compare(b.toFold(), end);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
733 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
734
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
735 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
736 * Compares to strings, ignoring case differences. Returns 0 if the content
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
737 * matches, less than zero if a is "less" than b, or greater than zero
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
738 * where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
739 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
740 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
741 * a = the first array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
742 * b = the second array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
743 * end = the index where the comparision will end
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
744 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
745 * Returns: Returns 0 if the content matches, less than zero if a is
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
746 * "less" than b, or greater than zero where a is "bigger".
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
747 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
748 * See_Also: mambo.string.compareIgnoreCase
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
749 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
750 alias compareIgnoreCase icompare;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
751
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
752 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
753 * Checks if the given character is a hexdecimal digit character.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
754 * Hexadecimal digits are any of: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
755 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
756 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
757 * ch = the character to be checked
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
758 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
759 * Returns: true if the given character is a hexdecimal digit character otherwise false
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
760 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
761 bool isHexDigit (dchar ch)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
762 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
763 version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
764 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
765 switch (ch)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
766 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
767 case 'A': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
768 case 'B': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
769 case 'C': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
770 case 'D': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
771 case 'E': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
772 case 'F': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
773
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
774 case 'a': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
775 case 'b': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
776 case 'c': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
777 case 'd': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
778 case 'e': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
779 case 'f': return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
780
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
781 default: break;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
782 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
783
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
784 if (isDigit(ch))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
785 return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
786 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
787
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
788 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
789 if (isxdigit(ch) != 0)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
790 return true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
791
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
792 return false;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
793 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
794
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
795 /*version (Tango)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
796 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
797 string toString (string str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
798 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
799 return str;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
800 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
801
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
802 string toString (wstring str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
803 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
804 return tango.text.convert.Utf.toString(str);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
805 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
806
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
807 string toString (dstring str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
808 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
809 return tango.text.convert.Utf.toString(str);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
810 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
811 }*/
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
812
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
813 version (Phobos)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
814 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
815 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
816 * Converts the given string to C-style 0 terminated string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
817 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
818 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
819 * str = the string to convert
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
820 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
821 * Returns: the a C-style 0 terminated string.
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
822 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
823 dchar* toString32z (dstring str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
824 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
825 return (str ~ '\0').dup.ptr;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
826 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
827
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
828 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
829 * Converts a C-style 0 terminated string to a wstring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
830 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
831 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
832 * str = the C-style 0 terminated string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
833 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
834 * Returns: the converted wstring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
835 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
836 wstring fromString16z (wchar* str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
837 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
838 return str[0 .. strlen(str)].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
839 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
840
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
841 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
842 * Converts a C-style 0 terminated string to a dstring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
843 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
844 * str = the C-style 0 terminated string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
845 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
846 * Returns: the converted dstring
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
847 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
848 dstring fromString32z (dchar* str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
849 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
850 return str[0 .. strlen(str)].idup;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
851 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
852
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
853 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
854 * Gets the length of the given C-style 0 terminated string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
855 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
856 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
857 * str = the C-style 0 terminated string to get the length of
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
858 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
859 * Returns: the length of the string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
860 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
861 size_t strlen (wchar* str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
862 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
863 size_t i = 0;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
864
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
865 if (str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
866 while(*str++)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
867 ++i;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
868
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
869 return i;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
870 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
871
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
872 /**
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
873 * Gets the length of the given C-style 0 terminated string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
874 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
875 * Params:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
876 * str = the C-style 0 terminated string to get the length of
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
877 *
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
878 * Returns: the length of the string
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
879 */
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
880 size_t strlen (dchar* str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
881 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
882 size_t i = 0;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
883
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
884 if (str)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
885 while(*str++)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
886 ++i;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
887
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
888 return i;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
889 }
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
890 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
891
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
892 T[] replace (T) (T[] source, dchar match, dchar replacement)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
893 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
894 static assert(isChar!(T), `The type "` ~ T.stringof ~ `" is not a valid type for this function only strings are accepted`);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
895
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
896 dchar endOfCodeRange;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
897
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
898 static if (is(T == wchar))
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
899 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
900 const encodedLength = 2;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
901 endOfCodeRange = wchar.init;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
902 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
903
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
904 else static if (is(T == char))
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
905 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
906 const encodedLength = 4;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
907 endOfCodeRange = '\x7F';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
908 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
909
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
910 if (replacement <= endOfCodeRange && match <= endOfCodeRange)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
911 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
912 foreach (ref c ; source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
913 if (c == match)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
914 c = replacement;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
915
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
916 return source;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
917 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
918
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
919 else
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
920 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
921 static if (!is(T == dchar))
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
922 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
923 T[encodedLength] encodedMatch;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
924 T[encodedLength] encodedReplacement;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
925
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
926 version (Tango)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
927 return source.substitute(encode(encodedMatch, match), encode(encodedReplacement, replacement));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
928
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
929 else
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
930 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
931 auto matchLength = encode(encodedMatch, match);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
932 auto replacementLength = encode(encodedReplacement, replacement);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
933
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
934 return std.string.replace(source, encodedMatch[0 .. matchLength], encodedReplacement[0 .. replacementLength]);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
935 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
936 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
937 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
938
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
939 return source;
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
940 }