Import various string methods by default
[delight/dlt-lib.git] / dlt / core.dlt
blob3f576a29cbe621871c28d64c3ef20c93aed0d13e
1 module dlt.core
3 public import std.string:
4         atoi, atof
5         find, ifind, irfind
6         split, splitlines
7         count, replace
8         stripl, stripr, strip
9         tolower, toupper
11 private const(char)[] null_error(ClassInfo ci):
12         return "Expected " ~ ci.name ~ " but got null!"
14 # Asserts that o is not null and then returns it.
15 # Use this if you're sure o can't be null, but the static type checker
16 # doesn't realise.
17 T notnull(T)(T? o):
18         if T oo = o:
19                 return oo
20         else:
21                 static if is(T == class):
22                         assert 0 else null_error(T.classinfo)
23                 else:
24                         assert 0 else "Unexpected null pointer"
26 # Call o.toString(). If o is null, return "(null)".
27 string str(Object? o):
28         if Object oo  = o:
29                 return oo.toString()
30         else:
31                 return "(null)"
33 # dlt._externals assigns to this
34 void function(int level, string src, string msg, ...) __log
36 # If the top-level main throws this, the message will be printed to stderr
37 # and the program terminates with the given exit code.
38 class SystemExit extends Exception:
39         int exitCode
40         this(string msg, int exitCode = 1):
41                 this.exitCode = exitCode
42                 super(msg)
44 class IllegalArgumentException extends Exception:
45         this(string msg):
46                 super(msg)