Permalink
Browse files

Removed class String from Core.

  • Loading branch information...
1 parent 8d0f2de commit c8e8d5d6b7d3739d6400514dc849166c63a0eff6 @wilkie committed Apr 7, 2010
Showing with 2,919 additions and 5,119 deletions.
  1. +2 −2 Makefile
  2. +4 −4 analyzing/debugger.d
  3. +44 −51 console/prompt.d
  4. +1 −1 core/arguments.d
  5. +0 −4 core/exception.d
  6. +2 −15 core/library.d
  7. +1 −1 core/list.d
  8. +2 −2 core/locales/en_us.d
  9. +2 −2 core/locales/fr_fr.d
  10. +37 −58 core/regex.d
  11. +0 −21 core/stream.d
  12. +677 −958 core/string.d
  13. +12 −13 core/time.d
  14. +3 −4 core/timezone.d
  15. +0 −560 core/tostring.d
  16. +202 −73 core/variant.d
  17. +1 −1 djehuty.d
  18. +3 −3 examples/Snake/win.d
  19. +1 −1 examples/TuiTetris/gamewindow.d
  20. +0 −50 graphics/graphics.d
  21. +5 −18 gui/button.d
  22. +33 −45 gui/listbox.d
  23. +29 −33 gui/listfield.d
  24. +32 −44 gui/textfield.d
  25. +5 −15 gui/togglefield.d
  26. +9 −75 gui/window.d
  27. +4 −8 hashes/digest.d
  28. +1 −9 hashes/md5.d
  29. +0 −8 hashes/sha1.d
  30. +0 −8 hashes/sha224.d
  31. +0 −8 hashes/sha256.d
  32. +0 −10 interfaces/mod.d
  33. +10 −11 io/console.d
  34. +4 −25 io/socket.d
  35. +2 −4 math/currency.d
  36. +1 −3 math/fixed.d
  37. +1 −2 math/integer.d
  38. +0 −1 math/vector.d
  39. +2 −3 networking/http.d
  40. +14 −17 networking/irc.d
  41. +0 −14 networking/telnet.d
  42. +0 −4 opengl/window.d
  43. +0 −1 parsing/ast.d
  44. +13 −41 parsing/cfg.d
  45. +11 −11 parsing/d/lexer.d
  46. +27 −28 parsing/options.d
  47. +0 −1 parsing/parseunit.d
  48. +1 −1 platform/unix/main.d
  49. +2 −2 platform/unix/scaffold/console.d
  50. +0 −1 platform/unix/scaffold/directory.d
  51. +13 −155 platform/unix/scaffold/graphics.d
  52. +2 −2 platform/unix/scaffold/menu.d
  53. +4 −6 platform/unix/scaffold/socket.d
  54. +4 −4 platform/unix/scaffold/system.d
  55. +4 −4 platform/unix/scaffold/window.d
  56. +10 −38 resource/menu.d
  57. +4 −4 resource/sound.d
  58. +8 −25 scripting/lua.d
  59. +5 −31 specs/core/exception.d
  60. +21 −21 specs/core/regex.d
  61. +0 −220 specs/core/string.d
  62. +65 −0 specs/core/variant.d
  63. +4 −4 specs/hashes/digest.d
  64. +4 −9 specs/hashes/md5.d
  65. +2 −7 specs/hashes/sha1.d
  66. +2 −7 specs/hashes/sha224.d
  67. +2 −7 specs/hashes/sha256.d
  68. +1,464 −2,141 specs/test.d
  69. +4 −4 tools/dspec/output.d
  70. +4 −4 tui/codebox.d
  71. +6 −10 tui/container.d
  72. +6 −24 tui/label.d
  73. +26 −26 tui/listbox.d
  74. +23 −22 tui/textbox.d
  75. +9 −9 tui/textfield.d
  76. +5 −12 tui/widget.d
  77. +9 −17 tui/window.d
  78. +1 −4 utils/linkedlist.d
  79. +8 −27 winsamp.d
View
4 Makefile
@@ -38,7 +38,7 @@ DFILES_PLATFORM_WIN = binding/win32/gdipluscolormatrix.d binding/win32/gdiplusin
DFILES_PLATFORM_XOMB = platform/xomb/main.d platform/xomb/common.d platform/xomb/scaffold.d platform/xomb/vars.d platform/xomb/console.d platform/xomb/definitions.d platform/xomb/scaffolds/wave.d platform/xomb/scaffolds/graphics.d platform/xomb/scaffolds/thread.d platform/xomb/scaffolds/menu.d platform/xomb/scaffolds/window.d platform/xomb/scaffolds/view.d platform/xomb/scaffolds/color.d platform/xomb/scaffolds/file.d platform/xomb/scaffolds/socket.d platform/xomb/scaffolds/app.d platform/xomb/scaffolds/time.d platform/xomb/oscontrolinterface.d
DFILES_ANALYZING = analyzing/debugger.d
-DFILES_CORE = core/tostring.d core/locales/en_us.d core/locales/fr_fr.d core/date.d core/locale.d core/variant.d core/list.d core/exception.d core/event.d core/library.d core/system.d core/random.d core/regex.d core/arguments.d core/definitions.d core/application.d core/time.d core/timezone.d core/unicode.d core/endian.d core/stream.d core/string.d core/main.d core/color.d
+DFILES_CORE = core/locales/en_us.d core/locales/fr_fr.d core/date.d core/locale.d core/variant.d core/list.d core/exception.d core/event.d core/library.d core/system.d core/random.d core/regex.d core/arguments.d core/definitions.d core/application.d core/time.d core/timezone.d core/unicode.d core/endian.d core/stream.d core/string.d core/main.d core/color.d
DFILES_GUI = gui/container.d gui/trackbar.d gui/radiogroup.d gui/progressbar.d gui/togglefield.d gui/listfield.d gui/listbox.d gui/vscrollbar.d gui/hscrollbar.d gui/button.d gui/textfield.d gui/window.d gui/widget.d gui/application.d
DFILES_UTILS = utils/stack.d utils/linkedlist.d utils/fibonacci.d utils/heap.d
DFILES_PARSING = parsing/d/trees.d parsing/d/addexprunit.d parsing/d/andexprunit.d parsing/d/assignexprunit.d parsing/d/blockstmtunit.d parsing/d/switchstmtunit.d parsing/d/casestmtunit.d parsing/d/defaultstmtunit.d parsing/d/breakstmtunit.d parsing/d/continuestmtunit.d parsing/d/gotostmtunit.d parsing/d/returnstmtunit.d parsing/d/volatilestmtunit.d parsing/d/throwstmtunit.d parsing/d/postfixexprlistunit.d parsing/d/cmpexprunit.d parsing/d/conditionalexprunit.d parsing/d/declarationunit.d parsing/d/expressionunit.d parsing/d/importdeclunit.d parsing/d/isexprunit.d parsing/d/lexer.d parsing/d/logicalandexprunit.d parsing/d/logicalorexprunit.d parsing/d/moduledeclunit.d parsing/d/moduleunit.d parsing/d/mulexprunit.d parsing/d/nodes.d parsing/d/orexprunit.d parsing/d/parser.d parsing/d/postfixexprunit.d parsing/d/primaryexprunit.d parsing/d/shiftexprunit.d parsing/d/staticunit.d parsing/d/declaratorunit.d parsing/d/declaratorsuffixunit.d parsing/d/declaratortypeunit.d parsing/d/tokens.d parsing/d/enumdeclunit.d parsing/d/typeunit.d parsing/d/enumbodyunit.d parsing/d/aggregatedeclunit.d parsing/d/aggregatebodyunit.d parsing/d/classbodyunit.d parsing/d/templatebodyunit.d parsing/d/interfacebodyunit.d parsing/d/classdeclunit.d parsing/d/interfacedeclunit.d parsing/d/constructorunit.d parsing/d/destructorunit.d parsing/d/parameterlistunit.d parsing/d/functionbodyunit.d parsing/d/staticifunit.d parsing/d/versionunit.d parsing/d/debugunit.d parsing/d/unittestunit.d parsing/d/parameterunit.d parsing/d/basictypeunit.d parsing/d/statementunit.d parsing/d/pragmastmtunit.d parsing/d/staticassertunit.d parsing/d/foreachstmtunit.d parsing/d/scopedstmtunit.d parsing/d/forstmtunit.d parsing/d/typedeclarationunit.d parsing/d/unaryexprunit.d parsing/d/xorexprunit.d parsing/ast.d parsing/lexer.d parsing/token.d parsing/parser.d parsing/options.d parsing/cfg.d parsing/parseunit.d
@@ -56,7 +56,7 @@ DFILES_CONSOLE = console/prompt.d
DFILES_TUI = tui/filebox.d tui/container.d tui/dialog.d tui/window.d tui/application.d tui/widget.d tui/telnet.d tui/buffer.d tui/vt100.d tui/listbox.d tui/textfield.d tui/label.d tui/textbox.d tui/codebox.d tui/tabbox.d
DFILES_SCRIPTING = scripting/lua.d
DFILES_BINDING = binding/opengl/gl.d binding/opengl/glu.d binding/lua.d
-DFILES_INTERFACES = interfaces/container.d interfaces/mod.d
+DFILES_INTERFACES = interfaces/container.d
DFILES_MATH = math/currency.d math/fixed.d math/integer.d math/common.d math/vector.d math/matrix.d math/mathobject.d
DFILES_OPENGL = opengl/window.d opengl/texture.d opengl/light.d
DFILES_SPECS = specs/test.d
View
8 analyzing/debugger.d
@@ -69,17 +69,17 @@ public:
if (w !is null) {
// get class name
ClassInfo ci = w.classinfo;
- String className = new String(ci.name);
+ string className = ci.name.dup;
- Console.putln(" window: ", className.array, " [", w.text.array, "]");
+ Console.putln(" window: ", className, " [", w.text, "]");
}
if (t !is null) {
// get class name
ClassInfo ci = t.classinfo;
- String className = new String(ci.name);
+ string className = ci.name.dup;
- Console.putln(" thread: ", className.array);
+ Console.putln(" thread: ", className);
}
Console.setColor(fgColor.White);
View
95 console/prompt.d
@@ -1,6 +1,7 @@
module console.prompt;
import core.string;
+import core.unicode;
import io.console;
@@ -14,25 +15,19 @@ import utils.linkedlist;
class Prompt {
// TODO: Allow ANSI emulated prompt strings
this() {
- _prompt = new String("");
- }
-
- // Description: This will set the prompt string that will precede the input.
- // prompt: A string representing the prompt.
- void prompt(String prompt) {
- _prompt = new String(prompt);
+ _prompt = "";
}
// Description: This will set the prompt string that will precede the input.
// prompt: A string representing the prompt.
void prompt(string prompt) {
- _prompt = new String(prompt);
+ _prompt = prompt.dup;
}
// Description: This function will return the current prompt.
// Returns: The current prompt.
- String prompt() {
- return new String(_prompt);
+ string prompt() {
+ return _prompt.dup;
}
void promptColor(fgColor fgClr) {
@@ -51,7 +46,7 @@ class Prompt {
}
if (bufferSize != 0) {
- _lineBuffer = new LinkedList!(String)();
+ _lineBuffer = new LinkedList!(string)();
}
else {
_lineBuffer = null;
@@ -62,18 +57,18 @@ class Prompt {
// Description: This will display the prompt and return the line typed by the user.
// Returns: The line typed by the user.
- String line() {
+ string line() {
// the current displayed line
- String line;
+ string line;
// the 'working' line being edited
- String workingLine;
+ string workingLine;
// Print out the prompt string
Console.setColor(_promptClr);
- Console.put(_prompt.array);
+ Console.put(_prompt);
// Go into a key loop, wait for a return
// On any special key, fire the callback and expect a result (for instance, on TAB)
@@ -83,7 +78,7 @@ class Prompt {
uint code;
- line = new String("");
+ line = "";
workingLine = line;
if (_lineBuffer !is null) {
@@ -105,23 +100,23 @@ class Prompt {
else if (code == Key.Backspace) {
// backspace
- if (line.length() > 0 && _pos > 0) {
+ if (line.length > 0 && _pos > 0) {
Console.put(chr);
Console.put(' ');
Console.put(chr);
- if (_pos == line.length()) {
- line = line.subString(0, line.length()-1);
+ if (_pos == line.length) {
+ line = line.substring(0, line.length-1);
}
else {
- String newLine = line.subString(0, _pos-1);
- String restLine = line.subString(_pos);
- newLine.append(restLine);
+ string newLine = line.substring(0, _pos-1);
+ string restLine = line.substring(_pos);
+ newLine ~= restLine;
- Console.put(restLine.array);
+ Console.put(restLine);
Console.put(' ');
- for (uint i=0; i<=restLine.length(); i++) {
+ for (uint i=0; i<=restLine.length; i++) {
Console.put(cast(char)0x8);
}
@@ -144,7 +139,7 @@ class Prompt {
}
}
else if (code == Key.Right) {
- if (_pos < line.length()) {
+ if (_pos < line.length) {
Console.setRelative(1,0);
_pos++;
@@ -156,32 +151,32 @@ class Prompt {
// And then the line buffer spits out
// the previous line submitted
if (_lineBuffer !is null) {
- if (_bufferPos+1 < cast(int)_lineBuffer.length() && _lineBuffer.length() > 0) {
+ if (_bufferPos+1 < cast(int)_lineBuffer.length && _lineBuffer.length > 0) {
// grab the line from the line buffer
_bufferPos++;
line = _lineBuffer.peekAt(_bufferPos);
uint i;
- if (line.length() < _pos) {
- for (i=line.length(); i<_pos; i++) {
+ if (line.length < _pos) {
+ for (i=line.length; i<_pos; i++) {
Console.put(cast(char)0x8);
Console.put(' ');
Console.put(cast(char)0x8);
}
- _pos = line.length();
+ _pos = line.length;
}
for (i=0; i<_pos; i++) {
Console.put(cast(char)0x8);
}
// print the line
- Console.put(line.array);
+ Console.put(line);
- _pos = line.length();
+ _pos = line.length;
}
}
}
@@ -209,58 +204,56 @@ class Prompt {
uint i;
- if (line.length() < _pos) {
- for (i=line.length(); i<_pos; i++) {
+ if (line.length < _pos) {
+ for (i=line.length; i<_pos; i++) {
Console.put(cast(char)0x8);
Console.put(' ');
Console.put(cast(char)0x8);
}
- _pos = line.length();
+ _pos = line.length;
}
for (i=0; i<_pos; i++) {
Console.put(cast(char)0x8);
}
// print the line
- Console.put(line.array);
+ Console.put(line);
// erase the rest of the previous line
- _pos = line.length();
+ _pos = line.length;
}
}
else if (chr != 0) {
// written character
- if (_pos == line.length()) {
+ if (_pos == line.length) {
Console.put(chr);
- line.appendChar(chr);
+ line ~= chr;
}
else if (_pos == 0) {
- String newLine = new String("");
- newLine.appendChar(chr);
- newLine.append(line);
+ string newLine = "" ~ Unicode.toUtf8([chr]) ~ line;
- Console.put(newLine.array);
+ Console.put(newLine);
- for (uint i=1; i<newLine.length(); i++) {
+ for (uint i=1; i<newLine.length; i++) {
Console.put(cast(char)0x8);
}
line = newLine;
}
else {
Console.put(chr);
- String leftLine = line.subString(0, _pos);
- leftLine.appendChar(chr);
- String rightLine = line.subString(_pos);
- leftLine.append(rightLine);
+ string leftLine = line.substring(0, _pos);
+ leftLine ~= chr;
+ string rightLine = line.substring(_pos);
+ leftLine ~= rightLine;
- Console.put(rightLine.array);
+ Console.put(rightLine);
- for (uint i=0; i<rightLine.length(); i++) {
+ for (uint i=0; i<rightLine.length; i++) {
Console.put(cast(char)0x8);
}
@@ -294,11 +287,11 @@ class Prompt {
protected:
// the prompt string, for instance "# " or "C:\>"
- String _prompt;
+ string _prompt;
fgColor _promptClr = fgColor.White;
fgColor _clr = fgColor.White;
- LinkedList!(String) _lineBuffer;
+ LinkedList!(string) _lineBuffer;
int _bufferSize;
int _bufferPos;
View
2 core/arguments.d
@@ -7,7 +7,7 @@ import core.string;
import core.list;
// Description: This class holds the command line arguments that were passed into the app and will aid in parsing them.
-class Arguments : List!(String) {
+class Arguments : List!(string) {
public:
this() {
View
4 core/exception.d
@@ -20,10 +20,6 @@ template CustomException(char[] name, char[] error, char[] error_more) {
super("`~error~`");
}
- this(String msg) {
- super("`~error~error_more~`" ~ msg.toString());
- }
-
this(string msg) {
super("`~error~error_more~`" ~ msg);
}
View
17 core/library.d
@@ -23,14 +23,8 @@ class Library {
// Description: This constructor will dynamically load the library found at the given framework path.
// path: The path to the library in question.
- this(String path) {
- SystemLoadLibrary(_pfvars, path);
- }
-
- // Description: This constructor will dynamically load the library found at the given framework path.
- // path: The path to the library in question.
this(string path) {
- this(new String(path));
+ SystemLoadLibrary(_pfvars, path);
}
~this() {
@@ -48,20 +42,13 @@ protected:
}
// acquire the signature (or null)
- void* signature = SystemLoadLibraryProc(_pfvars, new String(proc));
+ void* signature = SystemLoadLibraryProc(_pfvars, proc);
// set in hash
_funcs[proc] = signature;
return signature;
}
- // Description: This function can only be called within an instance of the class. It will give the function pointer to the procedure specified by proc and null when the procedure cannot be found.
- // proc: The name of the procedure to call upon.
- // Returns: Will return null if the procedure cannot be found, otherwise it will return the address to this function.
- final void* getProc(String proc) {
- return getProc(proc.toString());
- }
-
final void*[string] _funcs;
LibraryPlatformVars _pfvars;
View
2 core/list.d
@@ -12,8 +12,8 @@
module core.list;
import core.definitions;
+import core.string;
import core.util;
-import core.tostring;
import core.exception;
// Description: This template resolves to true when the type T is
View
4 core/locales/en_us.d
@@ -4,8 +4,8 @@ import core.locale;
import core.time;
import core.date;
-import core.tostring;
import core.definitions;
+import core.string;
class LocaleEnglish_US : LocaleInterface {
string formatTime(Time time) {
@@ -166,7 +166,7 @@ class LocaleEnglish_US : LocaleInterface {
}
}
ret ~= ".";
- ret ~= ftoa(value, 10, false);
+ ret ~= toStr(value);
// round last digit
bool roundUp = (ret[$-1] >= '5');
View
4 core/locales/fr_fr.d
@@ -4,7 +4,7 @@ import core.locale;
import core.time;
import core.date;
-import core.tostring;
+import core.string;
import core.definitions;
class LocaleFrench_FR : LocaleInterface {
@@ -154,7 +154,7 @@ class LocaleFrench_FR : LocaleInterface {
}
}
ret ~= ",";
- ret ~= ftoa(value, 10, false);
+ ret ~= toStr(value);
// round last digit
bool roundUp = (ret[$-1] >= '5');
View
95 core/regex.d
@@ -12,7 +12,6 @@
module core.regex;
import core.string;
-import core.tostring;
import core.definitions;
import core.list;
@@ -33,105 +32,105 @@ uint _position() {
return uint.max;
}
-String _1() {
+string _1() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][0];
}
- return new String("");
+ return ("");
}
-String _2() {
+string _2() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][1];
}
- return new String("");
+ return ("");
}
-String _3() {
+string _3() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][2];
}
- return new String("");
+ return ("");
}
-String _4() {
+string _4() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][3];
}
- return new String("");
+ return ("");
}
-String _5() {
+string _5() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][4];
}
- return new String("");
+ return ("");
}
-String _6() {
+string _6() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][5];
}
- return new String("");
+ return ("");
}
-String _7() {
+string _7() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][6];
}
- return new String("");
+ return ("");
}
-String _8() {
+string _8() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][7];
}
- return new String("");
+ return ("");
}
-String _9() {
+string _9() {
if (Thread.getCurrent() in Regex.regexRefs) {
return Regex.regexRefs[Thread.getCurrent()][8];
}
- return new String("");
+ return ("");
}
class Regex {
// Description: This constructor will create an instance of a Regex that will efficiently compute the regular expression given.
// regex: The regular expression to utilize.
- this(String regex) {
- regularExpression = new String(regex);
+ this(string regex) {
+ regularExpression = (regex);
buildDFA(false);
}
this(string regex) {
- regularExpression = new String(regex);
+ regularExpression = (regex);
buildDFA();
}
- // Description: This function will return a matched regular expression on the given String. Single use regular expression functions, such as this one, use a backtracking algorithm.
- // str: The String to run the regular expression upon.
+ // Description: This function will return a matched regular expression on the given string. Single use regular expression functions, such as this one, use a backtracking algorithm.
+ // str: The string to run the regular expression upon.
// regex: The regular expression to use.
// Returns: The matched substring or null when no match could be found.
- static String eval(String str, String regex, string options = "") {
+ static string eval(string str, string regex, string options = "") {
RegexInfo regexInfo;
/*
static RegexInfo[string] oldRuns;
- string oldRunIndex = (regex.toString() ~ "_" ~ options);
+ string oldRunIndex = (regex.tostring() ~ "_" ~ options);
if (oldRunIndex in oldRuns) {
regexInfo = oldRuns[oldRunIndex];
}*/
@@ -190,7 +189,7 @@ class Regex {
bool backtrackedOnCaret = false;
- regexRefs[Thread.getCurrent()] = new String[](9);
+ regexRefs[Thread.getCurrent()] = new string [](9);
// Suppresses group matching until a position is reached.
int noMatchUntilClosedAtPos = -1;
@@ -555,7 +554,7 @@ class Regex {
if (!noMatch) {
if (regexGroupStart < 9) {
- String consumed = new String(str[regexInfo.groupInfo[regexInfo.groupInfo[regexPos].startPos].strStartPos..strPos]);
+ string consumed = (str[regexInfo.groupInfo[regexInfo.groupInfo[regexPos].startPos].strStartPos..strPos]);
regexRefs[Thread.getCurrent()][regexGroupStart] = consumed;
regexGroupStart++;
}
@@ -1201,35 +1200,23 @@ class Regex {
// Return the result
if (matchMade && strPosStart <= str.length) {
if (strPos-strPosStart == 0) {
- return new String("");
+ return ("");
}
// Save the position where the string was consumed
this.regexPos[Thread.getCurrent()] = strPosStart;
// Slice and return the consumed string
- return str.subString(strPosStart, strPos-strPosStart);
+ return str.substring(strPosStart, strPos-strPosStart);
}
return null;
}
- static String eval(string str, String regex, string options = "") {
- return eval(new String(str), regex, options);
- }
-
- static String eval(String str, string regex, string options = "") {
- return eval(str, new String(regex), options);
- }
-
- static String eval(string str, string regex, string options = "") {
- return eval(new String(str), new String(regex), options);
- }
-
- // Description: This function will return a matched regular expression on the given String. Instances of a Regex will use a DFA based approach.
- // str: The String to run the regular expression upon.
+ // Description: This function will return a matched regular expression on the given string. Instances of a Regex will use a DFA based approach.
+ // str: The string to run the regular expression upon.
// Returns: The matched substring or null when no match could be found.
- String eval(String str) {
+ string eval(string str) {
State currentState = startingState;
uint strPos;
@@ -1294,24 +1281,20 @@ class Regex {
// Return consumed string
if (currentState.accept) {
- return str.subString(startingStrPos, strPos - startingStrPos);
+ return str.substring(startingStrPos, strPos - startingStrPos);
}
// No match
return null;
}
- String eval(string str) {
- return eval(new String(str));
- }
-
protected:
// These instance variables contain the data structures
// that will build and maintain the DFA for the regular expression
// Holds the regular expression for the instance
- String regularExpression;
+ string regularExpression;
// For DFA regex operations
@@ -1355,7 +1338,7 @@ protected:
all.add(this);
}
- string toString() {
+ string tostring() {
string ret = "State " ~ toStr(id) ~ ": [";
if (accept) {
@@ -1446,17 +1429,13 @@ private:
}
State buildDFA(string regex) {
- return buildDFA(new String(regex));
- }
-
- State buildDFA(String regex) {
fillGroupInfo();
uint regexPos = 0;
List!(State) current = new List!(State);
return buildDFA(regex, regexPos, current);
}
- State buildDFA(String regex, ref uint regexPos, ref List!(State) current, bool isKleene = false) {
+ State buildDFA(string regex, ref uint regexPos, ref List!(State) current, bool isKleene = false) {
State startState = new State();
Console.putln("Start State: ", startState.id);
@@ -1695,7 +1674,7 @@ private:
// Common
- static String[][Thread] regexRefs;
+ static string[][Thread] regexRefs;
static uint[Thread] regexPos;
// For backtracking regex operations
View
21 core/stream.d
@@ -410,14 +410,6 @@ public:
return write(cast(ubyte*)str.ptr, dchar.sizeof * str.length);
}
- bool append(String str) {
- return append(str.array);
- }
-
- bool write(String str) {
- return write(str.array);
- }
-
// Description: This function places the last bytes of information into the front and sets the pointer to end of the information after it is moved.
void flush() {
}
@@ -801,19 +793,6 @@ public:
return ret;
}
- int opApply(int delegate(ref String) loopFunc) {
- string nextLine;
- int ret;
- while(readLine(nextLine)) {
- String str = new String(nextLine);
- ret = loopFunc(str);
-
- if (ret) { break; }
- }
-
- return ret;
- }
-
ubyte[] contents() {
if (_length == 0) {
return null;
View
1,635 core/string.d
@@ -16,9 +16,24 @@ module core.string;
import core.definitions;
import core.unicode;
import core.variant;
+import io.console;
public import core.string;
+string toStrv(Variadic vars) {
+ string ret = "";
+ foreach(var; vars) {
+ ret ~= var.toString();
+ }
+ return ret;
+}
+
+string toStr(...) {
+ Variadic vars = new Variadic(_arguments, _argptr);
+
+ return toStrv(vars);
+}
+
template _StringFormat() {
const char[] _StringFormat = `
@@ -101,975 +116,67 @@ template _StringFormat() {
intToStr = true;
}
- if (intToStr) {
- // convert int to string
- // get length of potential string
- uint actualLength = 1;
- ulong tmpVal;
-
- bool negative;
-
- if (argval < 0) {
- negative = true;
- argval = -argval;
- }
-
- tmpVal = cast(ulong)(argval);
-
- // initial push
- tmpVal /= base;
-
- // finds the length
- while(tmpVal > 0) {
- tmpVal /= base;
- actualLength++;
- }
-
- if (actualLength < length) { actualLength = length; }
-
- // from this, we can determine how much of the string to add
- result ~= new dchar[actualLength];
- result[$-actualLength..$] = '0';
-
- // add the string
- uint valIndex;
- for(int o = result.length-1; ; o--) {
- valIndex = cast(uint)argval % base;
- if (valIndex >= 10) {
- result[o] = (valIndex - 10) + 'a';
- }
- else {
- result[o] = valIndex + '0';
- }
- argval /= base;
-
- if (argval == 0) { break; }
- }
- }
-
- curArg++;
- }
-
- if (curArg == _arguments.length) { // just append the rest and not care
- i++;
- result ~= fmt[i..$];
- break; // exit for
- }
- }
- else {
- result ~= fmt[i];
- }
- }
-
- `;
-}
-
-// Section: Core/Resources
-
-// Description: A class that abstracts a character array with the native platform's perferred unicode format.
-class String {
-
- // Description: Will create an empty string.
- this() {
- this("");
- }
-
- // Description: Will create a string fitting the string passed through via the parameter.
- // str: The string to copy to the class.
- this (string str, ...) {
- if (_arguments.length == 0) {
- _data = Unicode.toNative(str);
- }
- else {
- // formatted string
- // perform format
- mixin(_StringFormat!());
-
- _data = Unicode.toNative(result);
- }
- }
-
- // Description: Will create a string fitting the string passed through via the parameter.
- // str: The string to copy to the class.
- this(String str) {
- _data ~= str._data;
- }
-
- // Description: Will create a string for the given integer.
- // val: The value to use.
- this(long val) {
- fromInteger(val);
- }
-
- // Description: Will return the length of the string.
- // Returns: The length of the string.
- uint length() {
- if (_data.length == 0) {
- return 0;
- }
-
- if (_calcIndices) {
- return _indices.length;
- }
-
- if (_calcLength) {
- return _length;
- }
-
- _length = Unicode.utflen(_data);
-
- _calcLength = true;
-
- return _length;
- }
-
- // Description: Will return the pointer to the character array.
- // Returns: An address to the internal character array for this String class.
- Char* ptr() {
- return _data.ptr;
- }
-
- // Description: Will return a reference to the internal character array.
- // Returns: A reference to the internal character array for this String class.
- Char[] array() {
- return _data;
- }
-
- // Description: Will append a String to the current String. The internal character array is rebuilt.
- // str: The String to append to the internal character array of this String class.
- void append(String str) {
- _data ~= str._data.dup;
- if (str._calcLength) {
- _length += str._length;
- }
- else {
- _calcLength = false;
- }
- _calcIndices = false;
- }
-
- void append(string str, ...) {
- _calcLength = false;
- _calcIndices = false;
- if (_arguments.length == 0) {
- _data ~= Unicode.toNative(str);
- }
- else {
- // formatted string
- // perform format
-
- // scan input, write when appropriate
- mixin(_StringFormat!());
-
- _data ~= Unicode.toNative(result);
- }
- }
-
- // Description: Will append a unicode character to this String. The internal character array is rebuilt.
- // character: The unicode character to append to the internal character array of this String class.
- void appendChar(dchar character) {
- _calcIndices = false;
- static if (Char.sizeof == dchar.sizeof) {
- _data ~= character;
- if (!Unicode.isDeadChar(character)) {
- _length++;
- }
- }
- else {
- dchar[] charArray = [ character ];
- // BLEH
- static if(Char.sizeof == wchar.sizeof) {
- _data ~= Unicode.toUtf16(charArray);
- }
- else {
- char[] chrs = Unicode.toUtf8(charArray);
- _data ~= chrs;
- }
-
- if (!Unicode.isDeadChar(character)) {
- _length++;
- }
- }
- }
-
- // Description: Will append a unicode character with combining marks to this String. The internal character array is rebuilt.
- // characters: The unicode character to append to the internal character array of this String class.
- void appendChar(dstring characters) {
- static if (Char.sizeof == dchar.sizeof) {
- _data ~= characters;
- if (!Unicode.isDeadChar(characters[0])) {
- _length++;
- }
- }
- else {
- static if(Char.sizeof == wchar.sizeof) {
- _data ~= Unicode.toUtf16Chars(characters);
- }
- else {
- _data ~= Unicode.toUtf8Chars(characters);
- }
-
- if (!Unicode.isDeadChar(characters[0])) {
- _length++;
- }
- }
- }
-
- // Description: Inserts a String at an arbitrary position.
- String insertAt(String s, uint pos) {
- if (pos >= this.length())
- return this;
-
- String ret = new String();
-
- ret.append(this.subString(0, pos));
- ret.append(s);
- ret.append(this.subString(pos));
-
- return ret;
- }
-
- String insertAt(string s, uint pos) {
- return insertAt(new String(s), pos);
- }
-
- // Description: Repeats a given string.
- // Returns: s repeated n times.
- static String repeat(String s, uint n) {
- String ret = new String();
-
- for (uint i = 0; i < n; i++) {
- ret.append(s);
- }
-
- return ret;
- }
-
- static String repeat(string s, uint n) {
- return repeat(new String(s), n);
- }
-
- String trim() {
- // find the start and end
- // slice the array
-
- int startpos;
- int endpos;
-
- if (_data.length == 0) {
- return new String("");
- }
-
- for(startpos=0; startpos<_data.length; startpos++) {
- if (_data[startpos] != ' ' &&
- _data[startpos] != '\t' &&
- _data[startpos] != '\r' &&
- _data[startpos] != '\n') {
-
- break;
- }
- }
-
- for(endpos=_data.length-1; endpos>=0; endpos--) {
- if (_data[endpos] != ' ' &&
- _data[endpos] != '\t' &&
- _data[endpos] != '\r' &&
- _data[endpos] != '\n') {
-
- break;
- }
- }
- endpos++;
-
- String ret = new String("");
- if (endpos > _data.length) {
- endpos = _data.length;
- }
-
- if (startpos > endpos) {
- return new String("");
- }
-
- ret._data = _data[startpos..endpos];
- return ret;
- }
-
- template _nextInt(T) {
- bool _nextInt(T)(out T value) {
- int curpos;
-
- for(curpos=0; curpos<_data.length; curpos++) {
- if (_data[curpos] != ' ' &&
- _data[curpos] != '\t' &&
- _data[curpos] != '\r' &&
- _data[curpos] != '\n') {
-
- break;
- }
- }
-
- bool negative = false;
-
- if (_data[curpos] == '-') {
- negative = true;
- curpos++;
- if (curpos == _data.length) { return false; }
- }
-
- if (_data[curpos] < '0' ||
- _data[curpos] > '9') {
-
- return false;
- }
-
- long tmpval = 0;
-
- for (;curpos<_data.length;curpos++) {
- if (_data[curpos] < '0' ||
- _data[curpos] > '9') {
-
- break;
- }
-
- tmpval *= 10;
- tmpval += cast(long)(_data[curpos] - '0');
- }
-
- if (negative) { tmpval = -tmpval; }
-
- value = cast(T)tmpval;
-
- return true;
- }
- }
-
- // Description: This function will return the next integer value found in the string.
- bool nextInt(out int value) {
- return _nextInt!(int)(value);
- }
-
- bool nextInt(out uint value) {
- return _nextInt!(uint)(value);
- }
-
- bool nextInt(out long value) {
- return _nextInt!(long)(value);
- }
-
- bool nextInt(out ulong value) {
- return _nextInt!(ulong)(value);
- }
-
- bool nextInt(out short value) {
- return _nextInt!(short)(value);
- }
-
- bool nextInt(out ushort value) {
- return _nextInt!(ushort)(value);
- }
-
- bool next(out String value, string delimiters) {
- return false;
- }
-
- int findReverse(String search) {
- // look through string for term search
- // in some, hopefully later on, efficient manner
-
- if (!_calcIndices) {
- _indices = Unicode.calcIndices(_data);
- _calcIndices = true;
- }
-
- if (!search._calcIndices) {
- search._indices = Unicode.calcIndices(search._data);
- search._calcIndices = true;
- }
-
- bool found;
-
- int o;
- int i;
- int aPos;
-
- for (i=_indices.length-1; i>=0; i--) {
- aPos = _indices[i];
-
- found = true;
- o=i;
- foreach (bPos; search._indices) {
- dchar aChr, bChr;
-
- aChr = Unicode.toUtf32Char(_data[_indices[o]..$]);
- bChr = Unicode.toUtf32Char(search._data[bPos..$]);
-
- if (aChr != bChr) {
- found = false;
- break;
- }
-
- o++;
- if (o >= _indices.length) {
- found = false;
- break;
- }
- }
- if (found) {
- return i;
- }
- }
-
- return -1;
- }
-
- int find(string search, uint start = 0) {
- return find(new String(search), start);
- }
-
- int find(String search, uint start = 0) {
- // look through string for term search
- // in some, hopefully later on, efficient manner
-
- if (!_calcIndices) {
- _indices = Unicode.calcIndices(_data);
- _calcIndices = true;
- }
-
- if (!search._calcIndices) {
- search._indices = Unicode.calcIndices(search._data);
- search._calcIndices = true;
- }
-
- if (start >= _indices.length) {
- return -1;
- }
-
- bool found;
-
- int o;
-
- foreach (i, aPos; _indices[start..$]) {
- found = true;
- o=i-1+start;
- foreach (bPos; search._indices) {
- o++;
- if (o >= _indices.length) {
- found = false;
- break;
- }
-
- dchar aChr, bChr;
-
- aChr = Unicode.toUtf32Char(_data[_indices[o]..$]);
- bChr = Unicode.toUtf32Char(search._data[bPos..$]);
-
- if (aChr != bChr) {
- found = false;
- break;
- }
- }
- if (found) {
- return i+start;
- }
- }
-
- return -1;
- }
-
- String replace(dchar find, dchar replace) {
- String ret = new String(this);
-
- if (!ret._calcIndices) {
- ret._indices = Unicode.calcIndices(ret._data);
- ret._calcIndices = true;
- }
-
- for(int i = 0; i < ret._indices.length; i++) {
- if (ret.charAt(i) == find) {
- ret._calcIndices = false;
- dchar[1] chrs = [replace];
- ret._data = ret._data[0..ret._indices[i]] ~ Unicode.toNative(chrs) ~ ret._data[ret._indices[i+1]..$];
- }
-
- if (!ret._calcIndices) {
- ret._indices = Unicode.calcIndices(ret._data);
- ret._calcIndices = true;
- }
- }
-
- return ret;
- }
-
- // Description: Will convert the string to lowercase.
- // Returns: The lowercase version of the current string.
- String toLowercase() {
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- String str = new String("");
-
- foreach(idx; _indices) {
- dchar chr = Unicode.toUtf32Char(_data[idx..$]);
-
- if (chr >= 'A' && chr <= 'Z') {
- chr += 32;
- }
-
- str.appendChar(chr);
- }
-
- return str;
- }
-
- // Description: Will convert the string to uppercase.
- // Returns: The uppercase version of the current string.
- String toUppercase() {
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- String str = new String("");
-
- foreach(index; _indices) {
- dchar chr = Unicode.toUtf32Char(_data[index..$]);
-
- if (chr >= 'a' && chr <= 'z') {
- chr -= 32;
- }
-
- str.appendChar(chr);
- }
-
- return str;
- }
-
- // Description: Will build and return a String object representing a slice of the current String.
- // start: The position to start from.
- // len: The length of the slice. Pass -1 to get the remaining string.
- String subString(int start, int len = -1) {
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- if (start >= _indices.length || len == 0) {
- return new String("");
- }
-
- if (len < 0) { len = -1; }
-
- if (len >= 0 && start + len >= _indices.length) {
- len = -1;
- }
-
- // subdivide
-
- String str;
- if (len == -1) {
- start = _indices[start];
- String ret = new String("");
- ret._data = _data[start..$];
- return ret;
- }
-
- // this is the index for one character past the
- // end of the substring of the original string...hence, len is
- // now the exclusive end of the range to slice the array.
- len = _indices[start+len];
-
- start = _indices[start];
-
- String ret = new String();
- ret._data = _data[start..len];
- return ret;
- }
-
- // Description: Will return the UTF-32 character from the position given. This will ignore combining marks! Do not use unless you wish to compute the size of the character, where this function would be more efficient. Otherwise, to ensure that internationalization is supported, use utfCharAt.
- // position: The character index to retreive.
- // Returns: The UTF-32 character at this position, without combining marks.
- dchar charAt(uint position) {
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- if (position >= _indices.length) {
- return '\0';
- }
-
- if (_indices.length == 0) {
- return '\0';
- }
-
- // convert the character starting at that position to a dchar
-
- return Unicode.toUtf32Char(_data[_indices[position]..$]);
- }
-
- void setCharAt(uint position, dchar value) {
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- if (position >= _indices.length) {
- position = 0;
- }
-
- if (_indices.length == 0) {
- return;
- }
-
- _calcIndices = false;
- dchar[1] chrs = [value];
- _data = _data[0.._indices[position]] ~ Unicode.toNative(chrs) ~ _data[_indices[position+1]..$];
- }
-
- // Description: Will return the UTF-32 character along with any combining marks.
- // Returns: An array of UTF-32 characters. The first character is the valid UTF-32 character base, and the rest of the dchars are combining marks.
- // position: The character index to retreive.
- dchar[] utfCharAt(uint position) {
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- if (position >= _indices.length) {
- position = 0;
- }
-
- // convert the character starting at that position to a dchar
-
- return Unicode.toUtf32Chars(_data[_indices[position]..$]);
- }
-
- // Description: Will cast the String object to a string for functions that require it.
- //string opCast() {
- // return toString();
- //}
-
- // Unicode Conversions
-
- // Description: Will return a Unicode character array for this string in UTF-32.
- dstring toUtf32() {
- static if (Char.sizeof == dchar.sizeof) {
- // no change!
- return cast(dstring)_data;
- }
- else {
- return Unicode.toUtf32(_data);
- }
- }
-
- // Description: Will return a Unicode character array for this string in UTF-16.
- wstring toUtf16() {
- static if (Char.sizeof == wchar.sizeof) {
- // no change!
- return cast(wstring)_data;
- }
- else {
- return Unicode.toUtf16(_data);
- }
- }
-
- // Description: Will return a Unicode character array for this string in UTF-8.
- string toUtf8() {
- static if (Char.sizeof == char.sizeof) {
- // no change!
- return _data;
- }
- else {
- return Unicode.toUtf8(_data);
- }
- }
-
- bool opEquals(string string) {
- if (string.length != _data.length) {
- return false;
- }
-
- if (_data[0..$] != Unicode.toNative(string[0..$])) {
- return false;
- }
-
- return true;
- }
-
- // this should work:
- alias Object.opEquals opEquals;
-
- bool opEquals(String string) {
- if (string._data.length != _data.length) {
- return false;
- }
-
- if (_data[0..$] != string._data[0..$]) {
- return false;
- }
-
- return true;
- }
-
- void fromInteger(long val) {
- int intlen;
- long tmp = val;
-
- bool negative;
-
- if (tmp < 0) {
- negative = true;
- tmp = -tmp;
- intlen = 2;
- }
- else {
- negative = false;
- intlen = 1;
- }
-
- while (tmp > 9) {
- tmp /= 10;
- intlen++;
- }
-
- //allocate
-
- _data = new Char[intlen];
-
- // we know the length
- _calcLength = true;
- _length = intlen;
-
- // we also know the indices!!!
-
- intlen--;
-
- if (negative) {
- tmp = -val;
- } else {
- tmp = val;
- }
-
- do {
- _data[intlen] = cast(Char)('0' + (tmp % 10));
- tmp /= 10;
- intlen--;
- } while (tmp != 0);
-
-
- if (negative) {
- _data[intlen] = '-';
- }
-
- _calcIndices = false;
- _calcLength = false;
- }
-
- // array operator overloads
- string opSlice() {
- return Unicode.toUtf8(_data);
- }
-
- string opSlice(size_t start) {
- size_t end = _data.length;
-
- if (start < 0) { start = 0; }
-
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- if (end >= _indices.length) {
- end = _data.length;
- }
- else {
- end = _indices[end];
- }
-
- if (start > end) { return ""; }
-
- return Unicode.toUtf8(_data[start..end]);
- }
-
- string opSlice(size_t start, size_t end) {
- if (start < 0) { start = 0; }
-
- if (!_calcIndices) {
- _calcIndices = true;
- _indices = Unicode.calcIndices(_data);
- }
-
- if (end >= _indices.length) {
- end = _data.length;
- }
- else {
- end = _indices[end];
- }
-
- if (start > end) { return ""; }
-
- return Unicode.toUtf8(_data[start..end]);
- }
-
- //string opSliceAssign(T val)
- //{
- // return _components[] = val;
- //}
-
- //string opSliceAssign(T[] val)
- //{
- // return _components[] = val;
- //}
-
- //string opSliceAssign(T val, size_t x, size_t y)
- //{
- // return _components[x..y] = val;
- //}
-
- //string opSliceAssign(T[] val, size_t x, size_t y)
- //{
- // return _components[x..y] = val;
- //}
-
- Char opIndex(size_t i) {
- return charAt(i);
- }
-
- void opIndexAssign(size_t i, dchar val) {
- setCharAt(i, val);
- }
-
- //string opIndexAssign(T value, size_t i)
- //{
- // return _components[i] = value;
- //}
-
- String opCat(string string) {
- String newStr = new String(this);
- newStr.append(string);
-
- return newStr;
- }
-
- void opCatAssign(string str) {
- append(str);
- }
-
- String opCat(String string) {
- String newStr = new String(this);
- newStr.append(string);
-
- return newStr;
- }
-
- void opCatAssign(String str) {
- append(str);
- }
-
- String opCat(dchar chr) {
- String newStr = new String(this);
- newStr.appendChar(chr);
-
- return newStr;
- }
-
- void opCatAssign(dchar chr) {
- appendChar(chr);
- }
-
- int opApply(int delegate(inout dchar) loopFunc) {
- int ret;
-
- dchar[] utf32 = toUtf32();
-
- foreach(chr; utf32) {
- ret = loopFunc(chr);
- if (ret) { break; }
- }
-
- return ret;
- }
-
- int opApplyReverse(int delegate(inout dchar) loopFunc) {
- int ret;
-
- dchar[] utf32 = toUtf32();
-
- foreach_reverse(chr; utf32) {
- ret = loopFunc(chr);
- if (ret) { break; }
- }
-
- return ret;
- }
-
- int opApply(int delegate(inout int, inout dchar) loopFunc) {
- int ret;
-
- int idx = 0;
-
- dchar[] utf32 = toUtf32();
-
- foreach(chr; utf32) {
- ret = loopFunc(idx,chr);
- idx++;
- if (ret) { break; }
- }
-
- return ret;
- }
+ if (intToStr) {
+ // convert int to string
+ // get length of potential string
+ uint actualLength = 1;
+ ulong tmpVal;
- int opApplyReverse(int delegate(inout int, inout dchar) loopFunc) {
- int ret;
- int idx = length();
+ bool negative;
- dchar[] utf32 = toUtf32();
+ if (argval < 0) {
+ negative = true;
+ argval = -argval;
+ }
- foreach_reverse(chr; utf32) {
- idx--;
- ret = loopFunc(idx,chr);
- if (ret) { break; }
- }
+ tmpVal = cast(ulong)(argval);
- return ret;
- }
+ // initial push
+ tmpVal /= base;
- int opCmp(Object o) {
- if (cast(String)o) {
- String str = cast(String)o;
- if (_data < str._data) {
- return -1;
- }
- else if (_data == str._data) {
- return 0;
- }
- return 1;
- }
- return 0;
- }
+ // finds the length
+ while(tmpVal > 0) {
+ tmpVal /= base;
+ actualLength++;
+ }
- int opCmp(string str) {
- return opCmp(new String(str));
- }
+ if (actualLength < length) { actualLength = length; }
- override char[] toString() {
- return Unicode.toUtf8(_data);
- }
+ // from this, we can determine how much of the string to add
+ result ~= new dchar[actualLength];
+ result[$-actualLength..$] = '0';
-private:
- uint _length;
+ // add the string
+ uint valIndex;
+ for(int o = result.length-1; ; o--) {
+ valIndex = cast(uint)argval % base;
+ if (valIndex >= 10) {
+ result[o] = (valIndex - 10) + 'a';
+ }
+ else {
+ result[o] = valIndex + '0';
+ }
+ argval /= base;
- bool _calcLength; // whether the length has been calculated
+ if (argval == 0) { break; }
+ }
+ }
- uint[] _indices; // refer within the string for each character
+ curArg++;
+ }
- bool _calcIndices; // whether the indices have been calculated
+ if (curArg == _arguments.length) { // just append the rest and not care
+ i++;
+ result ~= fmt[i..$];
+ break; // exit for
+ }
+ }
+ else {
+ result ~= fmt[i];
+ }
+ }
- uint _capacity;
- Char _data[];
+ `;
}
// Standard string functions (for C)
@@ -1273,7 +380,7 @@ bool nextInt(string str, out ushort value) {
// Description: Will build and return a String object representing a slice of the current String.
// start: The position to start from.
// len: The length of the slice. Pass -1 to get the remaining string.
-string subString(string str, int start, int len = -1) {
+string substring(string str, int start, int len = -1) {
uint[] _indices = Unicode.calcIndices(str);
if (start >= _indices.length || len == 0) {
@@ -1323,6 +430,45 @@ string replace(string str, dchar find, dchar replace) {
return ret;
}
+int findReverse(string source, string search, uint start = uint.max) {
+ if (start == uint.max) {
+ start = source.length;
+ }
+
+ uint[] _indices = Unicode.calcIndices(source);
+ uint[] search_indices = Unicode.calcIndices(search);
+
+ bool found;
+
+ int o;
+ foreach_reverse(i, aPos; _indices[0..start]) {
+ found = true;
+ o=i-1;
+ foreach(bPos; search_indices) {
+ o++;
+ if(o >= _indices.length) {
+ found = false;
+ break;
+ }
+
+ dchar aChr, bChr;
+
+ aChr = Unicode.toUtf32Char(source[_indices[o]..$]);
+ bChr = Unicode.toUtf32Char(search[bPos..$]);
+
+ if(aChr != bChr) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
int find(string source, string search, uint start = 0) {
// look through string for term search
// in some, hopefully later on, efficient manner
@@ -1374,3 +520,576 @@ string times(string str, int amount) {
}
return ret;
}
+
+string format(string format, ...) {
+ Variadic vars = new Variadic(_arguments, _argptr);
+ return formatv(format, vars);
+}
+
+string formatv(string format, Variadic vars) {
+ string ret = "";
+ string specifier = "";
+ bool inFormat = false;
+ bool intoFormat = false;
+ foreach(chr; format) {
+ if (intoFormat && chr != '{') {
+ intoFormat = false;
+ inFormat = true;
+ }
+
+ if (inFormat) {
+ // look for format end
+ if (chr == '}') {
+ inFormat = false;
+
+ Variant var = vars.next();
+ Type type = var.type;
+ int width = 0;
+ int precision = 0;
+ int base = 10;
+ bool unsigned = false;
+ long value;
+ ulong uvalue;
+ float fvalue;
+ double dvalue;
+
+ bool formatNumber = false;
+ bool formatFloat = false;
+ bool formatDouble = false;
+
+ if (specifier.nextInt(width)) {
+ specifier = specifier.substring(toStr(width).length);
+ }
+
+ // interpret format specifier
+ if (specifier.length == 0) {
+ // None... just toString the argument
+ ret ~= var.toString();
+ }
+
+ switch(specifier) {
+ case "d":
+ base = 10;
+ formatNumber = true;
+ break;
+ case "x":
+ base = 16;
+ unsigned = true;
+ formatNumber = true;
+ break;
+ case "u":
+ base = 10;
+ unsigned = true;
+ formatNumber = true;
+ break;
+ default:
+ ret ~= var.toString();
+ break;
+ }
+
+ if (formatNumber) {
+ switch (type) {
+ case Type.Byte:
+ case Type.Ubyte:
+ case Type.Short:
+ case Type.Ushort:
+ case Type.Int:
+ case Type.Uint:
+ case Type.Long:
+ value = var.to!(long);
+ uvalue = var.to!(ulong);
+ break;
+ case Type.Ulong:
+ unsigned = true;
+ uvalue = var.to!(ulong);
+ break;
+ case Type.Float:
+ fvalue = var.to!(float);
+ formatFloat = true;
+ break;
+ case Type.Double:
+ dvalue = var.to!(double);
+ formatDouble = true;
+ break;
+ }
+
+ string result = "";
+ if (formatFloat) {
+ result = ftoa(fvalue, base);
+ }
+ else if (formatDouble) {
+ result = dtoa(dvalue, base);
+ }
+ else if (unsigned) {
+ result = utoa(uvalue, base);
+ }
+ else {
+ result = itoa(value, base);
+ }
+ while (result.length < width) {
+ result = "0" ~ result;
+ }
+ ret ~= result;
+ }
+ }
+ specifier ~= chr;
+ }
+ else {
+ // Go into a format specifier
+ if (chr == '{' && intoFormat == false) {
+ intoFormat = true;
+ continue;
+ }
+ intoFormat = false;
+ ret ~= chr;
+ }
+ }
+ return ret;
+}
+
+string lowercase(string str) {
+ string ret = "";
+ return "";
+}
+
+string uppercase(string str) {
+ string ret = "";
+ return "";
+}
+
+string charAt(string str, int idx) {
+ return "";
+}
+
+string insertAt(string str, string what, int idx) {
+ return "";
+}
+
+private:
+string itoa(long val, uint base = 10) {
+ int intlen;
+ long tmp = val;
+
+ bool negative;
+
+ if (tmp < 0) {
+ negative = true;
+ tmp = -tmp;
+ intlen = 2;
+ }
+ else {
+ negative = false;
+ intlen = 1;
+ }
+
+ while (tmp >= base) {
+ tmp /= base;
+ intlen++;
+ }
+
+ //allocate
+
+ string ret = new char[intlen];
+
+ intlen--;
+
+ if (negative) {
+ tmp = -val;
+ } else {
+ tmp = val;
+ }
+
+ do {
+ uint off = cast(uint)(tmp % base);
+ char replace;
+ if (off < 10) {
+ replace = cast(char)('0' + off);
+ }
+ else if (off < 36) {
+ off -= 10;
+ replace = cast(char)('a' + off);
+ }
+ ret[intlen] = replace;
+ tmp /= base;
+ intlen--;
+ } while (tmp != 0);
+
+
+ if (negative) {
+ ret[intlen] = '-';
+ }
+
+ return ret;
+}
+
+string utoa(ulong val, uint base = 10) {
+ int intlen;
+ ulong tmp = val;
+
+ intlen = 1;
+
+ while (tmp >= base) {
+ tmp /= base;
+ intlen++;
+ }
+
+ //allocate
+ tmp = val;
+
+ string ret = new char[intlen];
+
+ intlen--;
+
+ do {
+ uint off = cast(uint)(tmp % base);
+ char replace;
+ if (off < 10) {
+ replace = cast(char)('0' + off);
+ }
+ else if (off < 36) {
+ off -= 10;
+ replace = cast(char)('a' + off);
+ }
+ ret[intlen] = replace;
+ tmp /= base;
+ intlen--;
+ } while (tmp != 0);
+
+ return ret;
+}
+
+private union intFloat {
+ int l;
+ float f;
+}
+
+private union longDouble {
+ long l;
+ double f;
+}
+
+private union longReal {
+ struct inner {
+ short exp;
+ long frac;
+ }
+
+ inner l;
+ real f;
+}
+
+string ctoa(cfloat val, uint base = 10) {
+ if (val is cfloat.infinity) {
+ return "inf";
+ }
+ else if (val.re !<>= 0.0 && val.im !<>= 0.0) {
+ return "nan";
+ }
+
+ return ftoa(val.re, base) ~ " + " ~ ftoa(val.im, base) ~ "i";
+}
+
+string ctoa(cdouble val, uint base = 10) {
+ if (val is cdouble.infinity) {
+ return "inf";
+ }
+ else if (val.re !<>= 0.0 && val.im !<>= 0.0) {
+ return "nan";
+ }
+
+ return dtoa(val.re, base) ~ " + " ~ ftoa(val.im, base) ~ "i";
+}
+
+string ctoa(creal val, uint base = 10) {
+ if (val is creal.infinity) {
+ return "inf";
+ }
+ else if (val is creal.nan) {
+ return "nan";
+ }
+
+ return rtoa(val.re, base) ~ " + " ~ ftoa(val.im, base) ~ "i";
+}
+
+string ftoa(float val, uint base = 10) {
+ if (val == float.infinity) {
+ return "inf";
+ }
+ else if (val !<>= 0.0) {
+ return "nan";
+ }
+ else if (val == 0.0) {
+ return "0";
+ }
+
+ long mantissa;
+ long intPart;
+ long fracPart;
+
+ short exp;
+
+ intFloat iF;
+ iF.f = val;
+
+ // Conform to the IEEE standard
+ exp = ((iF.l >> 23) & 0xff) - 127;
+ mantissa = (iF.l & 0x7fffff) | 0x800000;
+ fracPart = 0;
+ intPart = 0;
+
+ if (exp >= 31) {
+ return "0";
+ }
+ else if (exp < -23) {
+ return "0";
+ }
+ else if (exp >= 23) {
+ intPart = mantissa << (exp - 23);
+ }
+ else if (exp >= 0) {
+ intPart = mantissa >> (23 - exp);
+ fracPart = (mantissa << (exp + 1)) & 0xffffff;
+ }
+ else { // exp < 0
+ fracPart = (mantissa & 0xffffff) >> (-(exp + 1));
+ }
+
+ string ret;
+ if (iF.l < 0) {
+ ret = "-";
+ }
+
+ ret ~= itoa(intPart, base);
+ ret ~= ".";
+ for (uint k; k < 7; k++) {
+ fracPart *= 10;
+ ret ~= cast(char)((fracPart >> 24) + '0');
+ fracPart &= 0xffffff;
+ }
+
+ // round last digit
+ bool roundUp = (ret[$-1] >= '5');
+ ret = ret[0..$-1];
+
+ while (roundUp) {
+ if (ret.length == 0) {
+ return "0";
+ }
+ else if (ret[$-1] == '.' || ret[$-1] == '9') {
+ ret = ret[0..$-1];
+ continue;
+ }
+ ret[$-1]++;
+ break;
+ }
+
+ // get rid of useless zeroes (and point if necessary)
+ foreach_reverse(uint i, chr; ret) {
+ if (chr != '0' && chr != '.') {
+ ret = ret[0..i+1];
+ break;
+ }
+ else if (chr == '.') {
+ ret = ret[0..i];
+ break;
+ }
+ }
+
+ return ret;
+}
+
+string dtoa(double val, uint base = 10, bool doIntPart = true) {
+ if (val is double.infinity) {
+ return "inf";
+ }
+ else if (val !<>= 0.0) {
+ return "nan";
+ }
+ else if (val == 0.0) {
+ return "0";
+ }
+
+ long mantissa;
+ long intPart;
+ long fracPart;
+
+ long exp;
+
+ longDouble iF;
+ iF.f = val;
+
+ // Conform to the IEEE standard
+ exp = ((iF.l >> 52) & 0x7ff);
+ if (exp == 0) {
+ return "0";
+ }
+ else if (exp == 0x7ff) {
+ return "inf";
+ }
+ exp -= 1023;
+
+ mantissa = (iF.l & 0xfffffffffffff) | 0x10000000000000;
+ fracPart = 0;
+ intPart = 0;
+