7bc0d41996-10-09Fredrik Hübinette (Hubbe) #define BEGIN 32
85f1fb1996-10-15Fredrik Hübinette (Hubbe)  string strmult(string str, int num) { #if 1 num*=strlen(str); while(strlen(str) < num) str+=str; return str[0..num-1]; #endif #if 0 return sprintf("%~n",str,strlen(str)*num); #endif }
7bc0d41996-10-09Fredrik Hübinette (Hubbe) void create() {
85f1fb1996-10-15Fredrik Hübinette (Hubbe)  add_constant("strmult",strmult);
7bc0d41996-10-09Fredrik Hübinette (Hubbe)  master()->add_precompiled_program("/precompiled/string_buffer", class {
a2fd531996-10-11Fredrik Hübinette (Hubbe)  string *buffer=allocate(BEGIN); int ptr=0;
7bc0d41996-10-09Fredrik Hübinette (Hubbe)  static void fix() { string tmp=buffer*""; buffer=allocate(strlen(tmp)/128+BEGIN); buffer[0]=tmp; ptr=1; } string get_buffer() { if(ptr != 1) fix(); return buffer[0]; } void append(string s) { if(ptr==sizeof(buffer)) fix(); buffer[ptr++]=s; } mixed cast(string to) { if(to=="string") return get_buffer(); return 0; }
a2fd531996-10-11Fredrik Hübinette (Hubbe)  void flush()
7bc0d41996-10-09Fredrik Hübinette (Hubbe)  { buffer=allocate(BEGIN); ptr=0; } }); }