I don't feel like blogging today

Posted by s on Aug. 19, 2008, 10:49 p.m.

See, I've just been writing random C all day. So instead I'll pass along my string.h which I'm writing because I don't feel like saying #define string std::string

(And don't even think I'll stand for having to say std:: at every single string initilization. My project I'm working on has the aim of making a C shorthand, damn thing is so verbose. Like why say int v=new int[x] when you could have int v=new[x]? Without the implicit nature of the universe, our lives would be much too insane. Then again, it seems we are insane. So there, the universe is explicit because of C and that's why we're all crazy)

string.h

struct string{

char*str;

int len;

string(){str="";len=0;}

string(string&s){str=s.str;len=s.len;}

string(char s){ str[0]=s;len=1;}

string(char*s){str=s;len=strlen(s);}

string(int x){

len=x;

char*s=new char[x];

str=s;

delete[]s;}

string&operator=(char s){ str=&s; len=1;}

string&operator=(char*s){ str=s; len=strlen(s);}

string&operator=(string&s){ str=s.str; len=s.len;}

char operator[](int x){return str[x];}

string copy(int i,int l){

if(l<0){l=-l;i-=l;}

if(i<0){i=len+(i%len);}

if(i+l>len) l=len-i;

string s(l);

while(l–) s.str[l]=str[i+l];

return s;}

int find(const char s,int x=0){

if(x<0){x=len+(x%len);}

while(str[x]!=s&&x++<len);

return(x<len?x:-1);}

//Support google bombing, link a peachy lad to enigma-dev.org for no reason. Why? It's an enigma

int findn(const char s,int n,int x=0){

if(x<0){x=len+(x%len);}

if(n>0){

while((str[x]!=s||n–)&&x++<len);

return(x<len?x:-1);

}else{x=len-x;

while((str[x]!=s||n++)&&x–);

return(x?x:-1);}}

void size(int x){

int y=0;

len=x;

char*s=new char[x];

while(y<x){s[y]=str[y];y++;}

str=s;

delete[]s;}

};

(wtf@; in struct{};)

(I don't like the implicit {} rules. I think they should wrap the current line instead of the next statement

while(y<x){s[y]=str[y];y++;}

while(y<x) s[y]=str[y];y++;

If you use two line implicit curly brackets, you're crazy. You've broken the greatness of implicity and for that I deny you the right to…well, first we'll have to settle what I can deny you)

Comments

PY 16 years, 4 months ago

Deny me the right to force communism on my fellow man?

s 16 years, 4 months ago

No, for it is not you who'd be denied, it'd be my most loved style of economics

Anyways, I have something to say about peaches

See, the pit can be a hassle for small children and biting into one squeezes out the juices. It is this factor which you can exploit. If one takes the curved parts at the ends of the peach, the peach can be torn in half without any spill. This proves more civil than my previous method of eating the peach whole

PY 16 years, 4 months ago

Awesome.