All pastes #817316 Raw Edit

validator

public cpp v1 · immutable
#817316 ·published 2007-12-15 13:37 UTC
rendered paste body
#include <iostream>#include <string>#include <stack>using namespace std;int main(){	char str[] ="{ @111000; < qwe > ![<{asd! }";	cout<<"code: "<<str<<endl<<endl;	stack<char> tags;		char tgOpen[]  = "[<{";	char tgClose[] = "]>}";	char *ch;		bool comment = false;		for (int i=0; i<strlen(str); i++) {		if (str[i]=='!')			comment=!comment;				if (!comment) {			if ((ch = strchr(tgOpen, str[i]))!=NULL) {				cout<<*ch<<endl;				tags.push(*ch);			}						if ((ch = strchr(tgClose, str[i]))!=NULL) {				cout<<*ch<<endl;				if (!tags.empty()) {					if (tgOpen[ch-tgClose] != tags.top())						cout<<"tags error 1!"<<endl;					tags.pop();				} else {					cout<<"tags error 2!"<<endl;				}			}		}	}		if (!tags.empty()) {		cout<<"tags error 3!"<<endl;	}		cout<<"comment: "<<comment<<endl;	/*char* c = str;	while (*c) {		if (ch = *strchr(tgOpen, (char)*c)) {			cout << ch << endl;		}		c++;	}*/	return 0;}