Subversion Repositories spk

Rev

Rev 8 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 10
Line 423... Line 423...
423
 
423
 
424
	if ( data[pos] == 0 ) return NULL;
424
	if ( data[pos] == 0 ) return NULL;
425
	return data + (pos + 1);
425
	return data + (pos + 1);
426
}
426
}
427
 
427
 
-
 
428
String *String::tokenise(const char *token, int *max) const
-
 
429
{
-
 
430
	if ( empty() ) {
-
 
431
		*max = 0;
-
 
432
		return NULL;
-
 
433
	}
428
 
434
 
-
 
435
	*max = this->countToken(token);
-
 
436
 
-
 
437
	if ( (*max) <= 0 ) {
-
 
438
		*max = 0;
-
 
439
		return NULL;
-
 
440
	}
-
 
441
 
-
 
442
	String *newstr = (*max == 1) ? new String : new String[*max];
-
 
443
 
-
 
444
	int whichtok = 0;
-
 
445
	// get first token
-
 
446
	std::string::size_type lastPos = 0;
-
 
447
	std::string::size_type pos     = this->_token_nextPos(token, 0);
-
 
448
 
-
 
449
	while (std::string::npos != pos || std::string::npos != lastPos)
-
 
450
	{
-
 
451
		// set token
-
 
452
		if ( *max == 1 ) *newstr = this->substr(lastPos, pos - lastPos);
-
 
453
		else			  newstr[whichtok] = this->substr(lastPos, pos - lastPos);
-
 
454
 
-
 
455
		// move to next token
-
 
456
		whichtok++;
-
 
457
		if ( whichtok >= *max )
-
 
458
			break;
-
 
459
 
-
 
460
		if ( pos >= this->length() )
-
 
461
			break;
-
 
462
 
-
 
463
		// skip past token
-
 
464
		size_t i = 0;
-
 
465
		size_t max = strlen(token);
-
 
466
		lastPos = pos;
-
 
467
		while ( (i < max) && (token[i] == this->at(lastPos)) ) {
-
 
468
			++i;
-
 
469
			++lastPos;
-
 
470
		}
-
 
471
 
-
 
472
		// get the next token
-
 
473
		pos = _token_nextPos(token, lastPos);
-
 
474
	}
-
 
475
 
-
 
476
	return newstr;
-
 
477
}
-
 
478
 
-
 
479
const String &String::remove(char c)
-
 
480
{
-
 
481
	std::string::size_type pos = this->find_first_of(c, 0);
-
 
482
	while(pos != std::string::npos) {
-
 
483
		this->erase(pos, 1);
-
 
484
		pos = this->find_first_of(c, 0);
-
 
485
	}
-
 
486
 
-
 
487
	return (*this);
-
 
488
}
-
 
489
 
-
 
490
String String::removeChar(char c) const
-
 
491
{
-
 
492
	String newStr = *this;
-
 
493
 
-
 
494
	std::string::size_type pos = newStr.find_first_of(c, 0);
-
 
495
	while(pos != std::string::npos) {
-
 
496
		newStr.erase(pos, 1);
-
 
497
		pos = newStr.find_first_of(c, 0);
-
 
498
	}
-
 
499
 
-
 
500
	return newStr;
-
 
501
}
429
 
502
 
430
}//NAMESPACE
503
}//NAMESPACE