| 1 |
<html><head> |
|---|
| 2 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|---|
| 3 |
<meta content="text/javascript" http-equiv="content-script-type"> |
|---|
| 4 |
<title>minid.utils</title> |
|---|
| 5 |
<link rel="stylesheet" type="text/css" href="candydoc/style.css"> |
|---|
| 6 |
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="candydoc/ie56hack.css"><![endif]--> |
|---|
| 7 |
<script language="JavaScript" src="candydoc/util.js" type="text/javascript"></script> |
|---|
| 8 |
<script language="JavaScript" src="candydoc/tree.js" type="text/javascript"></script> |
|---|
| 9 |
<script language="JavaScript" src="candydoc/explorer.js" type="text/javascript"></script> |
|---|
| 10 |
</head><body> |
|---|
| 11 |
<div id="tabarea"></div><div id="explorerclient"></div> |
|---|
| 12 |
<div id="content"><script>explorer.initialize("minid.utils");</script> |
|---|
| 13 |
<table class="content"> |
|---|
| 14 |
<tr><td id="docbody"><h1>minid.utils</h1><!-- Generated by Ddoc from minid\utils.d --> |
|---|
| 15 |
This module holds a variety of utility functions used throughout MiniD. This |
|---|
| 16 |
module doesn't (and shouldn't) depend on the rest of the library in any way, |
|---|
| 17 |
and as such can't hold implementation-specific functionality. For that, look |
|---|
| 18 |
in the minid.misc module. |
|---|
| 19 |
<br><br> |
|---|
| 20 |
<b>License:</b><br><pre class="license">Copyright (c) 2008 Jarrett Billingsley |
|---|
| 21 |
<br><br> |
|---|
| 22 |
|
|---|
| 23 |
This software is provided 'as-is', without any express or implied warranty. |
|---|
| 24 |
In no event will the authors be held liable for any damages arising from the |
|---|
| 25 |
use of this software. |
|---|
| 26 |
<br><br> |
|---|
| 27 |
|
|---|
| 28 |
Permission is granted to anyone to use this software for any purpose, |
|---|
| 29 |
including commercial applications, and to alter it and redistribute it freely, |
|---|
| 30 |
subject to the following restrictions: |
|---|
| 31 |
<br><br> |
|---|
| 32 |
|
|---|
| 33 |
1. The origin of this software must not be misrepresented; you must not |
|---|
| 34 |
claim that you wrote the original software. If you use this software in a |
|---|
| 35 |
product, an acknowledgment in the product documentation would be |
|---|
| 36 |
appreciated but is not required. |
|---|
| 37 |
<br><br> |
|---|
| 38 |
|
|---|
| 39 |
2. Altered source versions must be plainly marked as such, and must not |
|---|
| 40 |
be misrepresented as being the original software. |
|---|
| 41 |
<br><br> |
|---|
| 42 |
|
|---|
| 43 |
3. This notice may not be removed or altered from any source distribution. |
|---|
| 44 |
</pre><br> |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
<script>explorer.outline.incSymbolLevel();</script> |
|---|
| 48 |
<dl> |
|---|
| 49 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 50 |
<dt><span class="decl">bool |
|---|
| 51 |
<span class="currsymbol">startsWith</span> |
|---|
| 52 |
<script>explorer.outline.addDecl('startsWith');</script> |
|---|
| 53 |
|
|---|
| 54 |
(T)(T[] <span class="funcparam">string</span>, T[] <span class="funcparam">pattern</span>); |
|---|
| 55 |
</span></dt> |
|---|
| 56 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
<dd>See if a string starts with another string. Useful. |
|---|
| 60 |
<br><br> |
|---|
| 61 |
|
|---|
| 62 |
</dd> |
|---|
| 63 |
|
|---|
| 64 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 65 |
<dt><span class="decl">bool |
|---|
| 66 |
<span class="currsymbol">endsWith</span> |
|---|
| 67 |
<script>explorer.outline.addDecl('endsWith');</script> |
|---|
| 68 |
|
|---|
| 69 |
(T)(T[] <span class="funcparam">string</span>, T[] <span class="funcparam">pattern</span>); |
|---|
| 70 |
</span></dt> |
|---|
| 71 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
<dd>See if a string ends with another string. Also useful. |
|---|
| 75 |
<br><br> |
|---|
| 76 |
|
|---|
| 77 |
</dd> |
|---|
| 78 |
|
|---|
| 79 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 80 |
<dt><span class="decl">bool |
|---|
| 81 |
<span class="currsymbol">contains</span> |
|---|
| 82 |
<script>explorer.outline.addDecl('contains');</script> |
|---|
| 83 |
|
|---|
| 84 |
(T)(T[] <span class="funcparam">arr</span>, T <span class="funcparam">elem</span>); |
|---|
| 85 |
</span></dt> |
|---|
| 86 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
<dd>See if an array |
|---|
| 90 |
<span class="currsymbol">contains</span> |
|---|
| 91 |
<script>explorer.outline.addDecl('contains');</script> |
|---|
| 92 |
|
|---|
| 93 |
an item. |
|---|
| 94 |
<br><br> |
|---|
| 95 |
|
|---|
| 96 |
</dd> |
|---|
| 97 |
|
|---|
| 98 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 99 |
<dt><span class="decl">int |
|---|
| 100 |
<span class="currsymbol">Compare3</span> |
|---|
| 101 |
<script>explorer.outline.addDecl('Compare3');</script> |
|---|
| 102 |
|
|---|
| 103 |
(T)(T <span class="funcparam">a</span>, T <span class="funcparam">b</span>); |
|---|
| 104 |
</span></dt> |
|---|
| 105 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
<dd>Compare two values, a and b, using < and >. Returns -1 if a < b, 1 if a > b, and 0 otherwise. |
|---|
| 109 |
<br><br> |
|---|
| 110 |
|
|---|
| 111 |
</dd> |
|---|
| 112 |
|
|---|
| 113 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 114 |
<dt><span class="decl">int |
|---|
| 115 |
<span class="currsymbol">scmp</span> |
|---|
| 116 |
<script>explorer.outline.addDecl('scmp');</script> |
|---|
| 117 |
|
|---|
| 118 |
(char[] <span class="funcparam">s1</span>, char[] <span class="funcparam">s2</span>); |
|---|
| 119 |
</span></dt> |
|---|
| 120 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
<dd>Compares char[] strings stupidly (just by character value, not lexicographically). |
|---|
| 124 |
<br><br> |
|---|
| 125 |
|
|---|
| 126 |
</dd> |
|---|
| 127 |
|
|---|
| 128 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 129 |
<dt><span class="decl">uint |
|---|
| 130 |
<span class="currsymbol">verify</span> |
|---|
| 131 |
<script>explorer.outline.addDecl('verify');</script> |
|---|
| 132 |
|
|---|
| 133 |
(char[] <span class="funcparam">s</span>); |
|---|
| 134 |
</span></dt> |
|---|
| 135 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
<dd>Verifies that the given UTF-8 string is well-formed and returns the length in codepoints. |
|---|
| 139 |
<br><br> |
|---|
| 140 |
|
|---|
| 141 |
</dd> |
|---|
| 142 |
|
|---|
| 143 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 144 |
<dt><span class="decl">char[] |
|---|
| 145 |
<span class="currsymbol">uniSlice</span> |
|---|
| 146 |
<script>explorer.outline.addDecl('uniSlice');</script> |
|---|
| 147 |
|
|---|
| 148 |
(char[] <span class="funcparam">s</span>, uint <span class="funcparam">lo</span>, uint <span class="funcparam">hi</span>); |
|---|
| 149 |
</span></dt> |
|---|
| 150 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
<dd>Slice a UTF-8 string using codepoint indices. |
|---|
| 154 |
<br><br> |
|---|
| 155 |
|
|---|
| 156 |
</dd> |
|---|
| 157 |
|
|---|
| 158 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 159 |
<dt><span class="decl">dchar |
|---|
| 160 |
<span class="currsymbol">uniCharAt</span> |
|---|
| 161 |
<script>explorer.outline.addDecl('uniCharAt');</script> |
|---|
| 162 |
|
|---|
| 163 |
(char[] <span class="funcparam">s</span>, uint <span class="funcparam">idx</span>); |
|---|
| 164 |
</span></dt> |
|---|
| 165 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
<dd>Get the character in a UTF-8 string at the given codepoint index. |
|---|
| 169 |
<br><br> |
|---|
| 170 |
|
|---|
| 171 |
</dd> |
|---|
| 172 |
|
|---|
| 173 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 174 |
<dt><span class="decl">uint |
|---|
| 175 |
<span class="currsymbol">uniCPIdxToByte</span> |
|---|
| 176 |
<script>explorer.outline.addDecl('uniCPIdxToByte');</script> |
|---|
| 177 |
|
|---|
| 178 |
(char[] <span class="funcparam">s</span>, uint <span class="funcparam">fake</span>); |
|---|
| 179 |
</span></dt> |
|---|
| 180 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
<dd>Convert a codepoint index into a UTF-8 string into a byte index. |
|---|
| 184 |
<br><br> |
|---|
| 185 |
|
|---|
| 186 |
</dd> |
|---|
| 187 |
|
|---|
| 188 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 189 |
<dt><span class="decl">template |
|---|
| 190 |
<span class="currsymbol">isStringType</span> |
|---|
| 191 |
<script>explorer.outline.addDecl('isStringType');</script> |
|---|
| 192 |
|
|---|
| 193 |
(T)</span></dt> |
|---|
| 194 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
<dd>Metafunction to see if a given type is one of char[], wchar[] or dchar[]. |
|---|
| 198 |
<br><br> |
|---|
| 199 |
|
|---|
| 200 |
</dd> |
|---|
| 201 |
|
|---|
| 202 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 203 |
<dt><span class="decl">template |
|---|
| 204 |
<span class="currsymbol">isArrayType</span> |
|---|
| 205 |
<script>explorer.outline.addDecl('isArrayType');</script> |
|---|
| 206 |
|
|---|
| 207 |
(T)</span></dt> |
|---|
| 208 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
<dd>Sees if a type is an array. |
|---|
| 212 |
<br><br> |
|---|
| 213 |
|
|---|
| 214 |
</dd> |
|---|
| 215 |
|
|---|
| 216 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 217 |
<dt><span class="decl">template |
|---|
| 218 |
<span class="currsymbol">isAAType</span> |
|---|
| 219 |
<script>explorer.outline.addDecl('isAAType');</script> |
|---|
| 220 |
|
|---|
| 221 |
(T)</span></dt> |
|---|
| 222 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
<dd>Sees if a type is an associative array. |
|---|
| 226 |
<br><br> |
|---|
| 227 |
|
|---|
| 228 |
</dd> |
|---|
| 229 |
|
|---|
| 230 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 231 |
<dt><span class="decl">template |
|---|
| 232 |
<span class="currsymbol">realType</span> |
|---|
| 233 |
<script>explorer.outline.addDecl('realType');</script> |
|---|
| 234 |
|
|---|
| 235 |
(T)</span></dt> |
|---|
| 236 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
<dd>Get to the bottom of any chain of typedefs! Returns the first non-typedef'ed type. |
|---|
| 240 |
<br><br> |
|---|
| 241 |
|
|---|
| 242 |
</dd> |
|---|
| 243 |
|
|---|
| 244 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 245 |
<dt><span class="decl">template |
|---|
| 246 |
<span class="currsymbol">FOURCC</span> |
|---|
| 247 |
<script>explorer.outline.addDecl('FOURCC');</script> |
|---|
| 248 |
|
|---|
| 249 |
(char[] name)</span></dt> |
|---|
| 250 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
<dd>Make a |
|---|
| 254 |
<span class="currsymbol">FOURCC</span> |
|---|
| 255 |
<script>explorer.outline.addDecl('FOURCC');</script> |
|---|
| 256 |
|
|---|
| 257 |
code out of a four-character string. This is I guess for little-endian platforms.. |
|---|
| 258 |
<br><br> |
|---|
| 259 |
|
|---|
| 260 |
</dd> |
|---|
| 261 |
|
|---|
| 262 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 263 |
<dt><span class="decl">template |
|---|
| 264 |
<span class="currsymbol">MakeVersion</span> |
|---|
| 265 |
<script>explorer.outline.addDecl('MakeVersion');</script> |
|---|
| 266 |
|
|---|
| 267 |
(uint major,uint minor)</span></dt> |
|---|
| 268 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
<dd>Make a version with the major number in the upper 16 bits and the minor in the lower 16 bits. |
|---|
| 272 |
<br><br> |
|---|
| 273 |
|
|---|
| 274 |
</dd> |
|---|
| 275 |
|
|---|
| 276 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 277 |
<dt><span class="decl">template |
|---|
| 278 |
<span class="currsymbol">NameOfFunc</span> |
|---|
| 279 |
<script>explorer.outline.addDecl('NameOfFunc');</script> |
|---|
| 280 |
|
|---|
| 281 |
(alias f)</span></dt> |
|---|
| 282 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
<dd>Gets the name of a function alias. |
|---|
| 286 |
<br><br> |
|---|
| 287 |
|
|---|
| 288 |
</dd> |
|---|
| 289 |
|
|---|
| 290 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 291 |
<dt><span class="decl">template |
|---|
| 292 |
<span class="currsymbol">QSort</span> |
|---|
| 293 |
<script>explorer.outline.addDecl('QSort');</script> |
|---|
| 294 |
|
|---|
| 295 |
(alias Pred,List...)</span></dt> |
|---|
| 296 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
<dd>Given a predicate template and a tuple, sorts the tuple. I'm not sure how quick it is, but it's probably fast enough |
|---|
| 300 |
for sorting most tuples, which hopefully won't be that long. The predicate template should take two parameters of the |
|---|
| 301 |
same type as the tuple's elements, and return <0 for A < B, 0 for A == B, and >0 for A > B (just like opCmp). |
|---|
| 302 |
<br><br> |
|---|
| 303 |
|
|---|
| 304 |
</dd> |
|---|
| 305 |
|
|---|
| 306 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 307 |
<dt><span class="decl">template |
|---|
| 308 |
<span class="currsymbol">isExpressionTuple</span> |
|---|
| 309 |
<script>explorer.outline.addDecl('isExpressionTuple');</script> |
|---|
| 310 |
|
|---|
| 311 |
(T...)</span></dt> |
|---|
| 312 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
<dd>A useful template that somehow is in Phobos but no Tango. Sees if a tuple is composed |
|---|
| 316 |
entirely of expressions or aliases. |
|---|
| 317 |
<br><br> |
|---|
| 318 |
|
|---|
| 319 |
</dd> |
|---|
| 320 |
|
|---|
| 321 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 322 |
<dt><span class="decl">template |
|---|
| 323 |
<span class="currsymbol">FieldNames</span> |
|---|
| 324 |
<script>explorer.outline.addDecl('FieldNames');</script> |
|---|
| 325 |
|
|---|
| 326 |
(S,int idx = 0)</span></dt> |
|---|
| 327 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
<dd>For a given struct, gets a tuple of the names of its fields. |
|---|
| 331 |
<br><br> |
|---|
| 332 |
I have absolutely no idea if what I'm doing here is in any way legal. I more or less discovered |
|---|
| 333 |
that the compiler gives access to this info in odd cases, and am just exploiting that. It would |
|---|
| 334 |
be fantastic if the compiler would just tell us these things, but alas, we have to rely on |
|---|
| 335 |
seemingly-buggy undefined behavior. Sigh. |
|---|
| 336 |
<br><br> |
|---|
| 337 |
|
|---|
| 338 |
</dd> |
|---|
| 339 |
|
|---|
| 340 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 341 |
<dt><span class="decl">template |
|---|
| 342 |
<span class="currsymbol">MinArgs</span> |
|---|
| 343 |
<script>explorer.outline.addDecl('MinArgs');</script> |
|---|
| 344 |
|
|---|
| 345 |
(alias func)</span></dt> |
|---|
| 346 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
<dd>Given an alias to a function, this will give the minimum legal number of arguments it can be called with. |
|---|
| 350 |
Even works for aliases to class methods. Note, however, that this isn't smart enough to detect the difference |
|---|
| 351 |
between, say, "void foo(int x, int y = 10)" and "void foo(int x) ... void foo(int x, int y)". There might |
|---|
| 352 |
be a difference, though, so be cautions. |
|---|
| 353 |
<br><br> |
|---|
| 354 |
|
|---|
| 355 |
</dd> |
|---|
| 356 |
|
|---|
| 357 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 358 |
<dt><span class="decl">template |
|---|
| 359 |
<span class="currsymbol">InitsOf</span> |
|---|
| 360 |
<script>explorer.outline.addDecl('InitsOf');</script> |
|---|
| 361 |
|
|---|
| 362 |
(T...)</span></dt> |
|---|
| 363 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
<dd>Given a type tuple, this will give an expression tuple of all the .init values for each type. |
|---|
| 367 |
<br><br> |
|---|
| 368 |
|
|---|
| 369 |
</dd> |
|---|
| 370 |
|
|---|
| 371 |
<script>explorer.outline.writeEnabled = true;</script> |
|---|
| 372 |
<dt><span class="decl">template |
|---|
| 373 |
<span class="currsymbol">NameOfType</span> |
|---|
| 374 |
<script>explorer.outline.addDecl('NameOfType');</script> |
|---|
| 375 |
|
|---|
| 376 |
(T)</span></dt> |
|---|
| 377 |
<script>explorer.outline.writeEnabled = false;</script> |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
<dd>Given a class or struct type, gets its name. This really only exists to mask potential oddities with the |
|---|
| 381 |
way the compiler reports this info (for example, DMD used to insert a space before struct names, but that |
|---|
| 382 |
no longer seems to happen..). |
|---|
| 383 |
<br><br> |
|---|
| 384 |
|
|---|
| 385 |
</dd> |
|---|
| 386 |
</dl> |
|---|
| 387 |
<script>explorer.outline.decSymbolLevel();</script> |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
</td></tr> |
|---|
| 391 |
<tr><td id="docfooter"> |
|---|
| 392 |
Page was generated with |
|---|
| 393 |
<img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> |
|---|
| 394 |
on Thu Jan 1 12:24:57 2009 |
|---|
| 395 |
|
|---|
| 396 |
</td></tr> |
|---|
| 397 |
</table> |
|---|
| 398 |
</div> |
|---|
| 399 |
<script> |
|---|
| 400 |
explorer.packageExplorer.addModuleFull("minid.alloc"); |
|---|
| 401 |
explorer.packageExplorer.addModuleFull("minid.api"); |
|---|
| 402 |
explorer.packageExplorer.addModuleFull("minid.ast"); |
|---|
| 403 |
explorer.packageExplorer.addModuleFull("minid.bind"); |
|---|
| 404 |
explorer.packageExplorer.addModuleFull("minid.commandline"); |
|---|
| 405 |
explorer.packageExplorer.addModuleFull("minid.compiler"); |
|---|
| 406 |
explorer.packageExplorer.addModuleFull("minid.ex"); |
|---|
| 407 |
explorer.packageExplorer.addModuleFull("minid.interpreter"); |
|---|
| 408 |
explorer.packageExplorer.addModuleFull("minid.serialization"); |
|---|
| 409 |
explorer.packageExplorer.addModuleFull("minid.types"); |
|---|
| 410 |
explorer.packageExplorer.addModuleFull("minid.utils"); |
|---|
| 411 |
explorer.packageExplorer.addModuleFull("minid.vm");</script> |
|---|
| 412 |
</body></html> |
|---|