Changeset 344

Show
Ignore:
Timestamp:
05/29/08 08:03:39 (6 months ago)
Author:
FeepingCreature
Message:
  • No debugging symbols, please
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/dsss.conf

    r309 r344  
    22[tools] 
    33type=library 
    4 buildflags=-g -O 
     4# buildflags=-g -O 
     5buildflags=-O 
    56[tools/unittests.d] 
    67target=tools_test 
    7 buildflags=-full -unittest -g -O -debug 
     8# buildflags=-full -unittest -g -O -debug 
     9buildflags=-full -unittest -O 
  • trunk/tools/tools/base.d

    r336 r344  
    308308 
    309309void function() yield=&slowyield; 
    310  
    311310 
    312311void remove(T)(inout T[] array, T key, bool all=true) { 
     
    790789  while (true) { 
    791790    auto oldstate=*stp; 
     791    if (!(*stp in states)) { 
     792      logln("Invalid state reached: ", *stp, " not in ", states, "!"); 
     793      asm { int 3; } 
     794    } 
    792795    states[*stp](*stp); 
    793796    if (oldstate!=*stp) continue; 
     
    844847} 
    845848 
    846 Stuple!(string, string) splitOff(string source, string sep) { 
     849Stuple!(string, string) splitAt(string source, string sep) { 
    847850  return stuple(source[0..source.find(sep)], source[source.find(sep)+sep.length..$]); 
    848851} 
     
    10211024_eval eval; 
    10221025 
     1026struct _BoolSet(string OP, T...) { 
     1027  T values; 
     1028  int opEquals(U)(U other) { 
     1029    bool res = other == values[0]; 
     1030    foreach (value; values[1..$]) 
     1031      res = mixin("res "~OP~" value"); 
     1032    return res; 
     1033  } 
     1034} 
     1035 
     1036template BoolSet(string OP) { 
     1037  _BoolSet!(OP, T) BoolSet(T...)(T t) { 
     1038    _BoolSet!(OP, T) res = void; 
     1039    foreach (i, v; t) res.values[i] = v; 
     1040    return res; 
     1041  } 
     1042} 
     1043 
     1044alias BoolSet!("||") OrSet; alias BoolSet!("&&") AndSet; 
     1045mixin(Operator!("or", "return OrSet(lhs, rhs); ")); 
     1046 
    10231047import tools.log: logln; 
    10241048unittest { 
     
    10371061  mustEqual("PtupleBasicTest", a==2, b==5f, true); 
    10381062  mustEqual("ExTest", ex!("a, b, c -> d -> a(b, c) == d")((int a, int b) { return a == b; }, 2, 3)(false), true); 
     1063  mustEqual("BoolSetTestOr", 2 /or/ 3 == 3, true); 
     1064  mustEqual("BoolSetTestAnd", AndSet(2, 3) == 3, false); 
    10391065} 
    10401066 
     
    10441070} 
    10451071 
    1046 // lower-inclusive, upper-exclusive. 
    1047 struct between { int from, to; bool opIn_r(int i) { return (i < to) && (i !< from); } } 
    1048  
    10491072R delegate(T) toDg(R, T...)(R function(T) fn) { return fn /fix/ stuple(); } 
     1073 
     1074string between(string text, string from, string to) { 
     1075  int pos1; 
     1076  if (from.length) pos1 = text.find(from); 
     1077  else pos1 = 0; 
     1078  if (pos1 == -1) return null; 
     1079  text = text[pos1 + from.length .. $]; 
     1080  int pos2; 
     1081  if (to.length) pos2 = text.find(to); 
     1082  else pos2 = text.length; 
     1083  if (pos2 == -1) return null; 
     1084  return text[0 .. pos2]; 
     1085} 
     1086 
     1087string[] betweens(string text, string from, string to) { 
     1088  string[] res; 
     1089  while (true) { 
     1090    auto pos1 = text.find(from); if (pos1 == -1) break; 
     1091    text = text[pos1 + from.length .. $]; 
     1092    auto pos2 = text.find(to); if (pos2 == -1) break; 
     1093    res ~= text[0 .. pos2]; 
     1094    text = text[pos2 + to.length .. $]; 
     1095  } 
     1096  return res; 
     1097} 
     1098 
     1099void glomp_parse(string text, void delegate(string pre, ref string post)[string] words, void delegate(string) rest) { 
     1100  while (true) { 
     1101    void delegate(string, ref string) dg; int min = int.max; string match; 
     1102    foreach (key, value; words) { 
     1103      auto pos = text.find(key); 
     1104      if (pos == -1) continue; 
     1105      if (pos < min) { 
     1106        min = pos; 
     1107        dg = value; 
     1108        match = key; 
     1109      } 
     1110    } 
     1111    if (dg) { 
     1112      auto pre = text[0 .. min]; 
     1113      text = text[min + match.length .. $]; 
     1114      // logln("Found at ", min, ", pre ", pre, ", text ", text); 
     1115      dg(pre, text); 
     1116    } else { 
     1117      rest(text); 
     1118      break; 
     1119    } 
     1120  } 
     1121}