1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
bool RaidString::find_tag( string tag_name ) {
string str = r_str;
string tag = "<", check; // _start finds "<" , _end finds ">"
int _start, _end, _offset; // after _start. _offset = start of search
for( _offset = 0; _offset < str.length(); _offset = _end )
{
_start = str.find("<", _offset); // search for start of a tag
_end = str.find(">", _start); // find the end of a tag
check = ""; // reset check
int str_chk = // check if tag is a
str.compare( _start + 1, 1, "/"); // end tag </xxx>
if( str_chk != 0 ) // As long as str_chk isnt true
{ // put body between _start & _end into check
check.insert(0, str, _start+1, _end-_start-1);
str_chk = check.compare(tag_name); // compare with sent tag_name
if(str_chk == 0) // If they are the same make a
{ // pointer to it and return
int tag_tmp1, tag_tmp2;
// Sets tag_end, tagp_end(pointer to), tag_start,
// tagp_start(pointer to) to proper settings and
// updates them.
tag.insert(1, check); // add check to tag after 1
tag.insert(tag.size(), ">");// add a > after check to tag
tag_tmp1 = _start; // make same address
tagp_start = &tag_tmp1; // set pointer properly
tag_start = tag;
tag_end = tag;
tag_end.insert(1, "/"); // add a / after <
tag_tmp2 = str.find(tag_end,_offset); // search for </xx>
tagp_end = &tag_tmp2; // set pointer </xx>
int data = 0;
int p = *tagp_start + tag_start.length();
for(p = p; p < *tagp_end; p++)
{ data++; };
data_length = data;
return true; // Found a match!
}
else if( _end >= str.length() ){ // eof & no match: return false
return false;
};
};
};
};
|