Subversion Repositories spk

Rev

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

Rev 34 Rev 39
Line 264... Line 264...
264
		pos = _token_nextPos(token, lastPos);
264
		pos = _token_nextPos(token, lastPos);
265
	}
265
	}
266
	return newstr;
266
	return newstr;
267
}
267
}
268
 
268
 
-
 
269
String String::remToken(const char *token, int from) const
-
 
270
{
-
 
271
	std::string newstr;
-
 
272
 
-
 
273
	int whichtok = 1;
-
 
274
	std::string::size_type lastPos = 0;
-
 
275
	std::string::size_type pos     = _token_nextPos(token, 0);
-
 
276
 
-
 
277
	while (std::string::npos != pos || std::string::npos != lastPos)
-
 
278
	{
-
 
279
		if ( whichtok != from )
-
 
280
		{
-
 
281
			if ( newstr != "" ) newstr = newstr + token;
-
 
282
			newstr = newstr + this->substr(lastPos, pos - lastPos);
-
 
283
		}
-
 
284
 
-
 
285
		// Found a token, add it to the vector.
-
 
286
		whichtok++;
-
 
287
 
-
 
288
		if ( pos >= this->length() )
-
 
289
			break;
-
 
290
 
-
 
291
		// skip past token
-
 
292
		size_t i = 0;
-
 
293
		size_t max = strlen(token);
-
 
294
		lastPos = pos;
-
 
295
		while ( (i < max) && (token[i] == this->at(lastPos)) )
-
 
296
		{
-
 
297
			++i;
-
 
298
			++lastPos;
-
 
299
		}
-
 
300
 
-
 
301
		// get the next token
-
 
302
		pos = _token_nextPos(token, lastPos);
-
 
303
	}
-
 
304
	return newstr;
-
 
305
}
-
 
306
 
-
 
307
String String::word(int word) const
-
 
308
{
-
 
309
	return this->token(" ", word);
-
 
310
}
-
 
311
String String::words(int from, int to) const
-
 
312
{
-
 
313
	return this->tokens(" ", from, to);
-
 
314
}
269
int String::countToken(const char *token) const
315
int String::countToken(const char *token) const
270
{
316
{
271
	if ( this->empty() )
317
	if ( this->empty() )
272
		return 0;
318
		return 0;
273
 
319
 
Line 357... Line 403...
357
			return true;
403
			return true;
358
	}
404
	}
359
	return false;
405
	return false;
360
}
406
}
361
 
407
 
-
 
408
int String::findPos(const String &find, int iStartPos) const
-
 
409
{
-
 
410
	std::string::size_type pos = this->find(find, iStartPos);
-
 
411
	if ( pos == std::string::npos ) return -1;
-
 
412
	return pos;
-
 
413
}
-
 
414
 
362
bool String::isin(char c, bool bCaseSensative) const
415
bool String::isin(char c, bool bCaseSensative) const
363
{
416
{
364
	bool f = false;
417
	bool f = false;
365
	for ( unsigned int i = 0; i < this->length(); i++ )
418
	for ( unsigned int i = 0; i < this->length(); i++ )
366
	{
419
	{
367
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
420
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
Line 369... Line 422...
369
			f = true;
422
			f = true;
370
			break;
423
			break;
371
		}
424
		}
372
	}
425
	}
373
	return f;
426
	return f;
374
}
427
}
375
 
428
 
-
 
429
String String::mid(int start, int end) const
-
 
430
{
-
 
431
	return this->substr(start, end - start);
-
 
432
}
376
String String::left(long num) const
433
String String::left(long num) const
377
{
434
{
378
	if ( num < 0 )
435
	if ( num < 0 )
379
		num = (long)this->length() + num;
436
		num = (long)this->length() + num;
380
	if ( num > (long)this->length() )
437
	if ( num > (long)this->length() )
Line 387... Line 444...
387
{
444
{
388
	if ( num > 0 ) num -= (int)this->length();
445
	if ( num > 0 ) num -= (int)this->length();
389
	if ( num < -(int)this->length() ) num = -(int)this->length();
446
	if ( num < -(int)this->length() ) num = -(int)this->length();
390
 
447
 
391
	return this->substr(-num);
448
	return this->substr(-num);
-
 
449
}
-
 
450
 
-
 
451
const String &String::readToEndOfLine(FILE *id, int *line, bool upper)
-
 
452
{
-
 
453
	(*this) == "";
-
 
454
	char c = fgetc ( id );
-
 
455
	if ( c == -1 )
-
 
456
		return (*this);
-
 
457
 
-
 
458
	while ( (c != 13) && (!feof(id)) && (c != '\n') )
-
 
459
	{
-
 
460
		(*this) += c;
-
 
461
		c = fgetc ( id );
-
 
462
	}
-
 
463
 
-
 
464
	if ( line )
-
 
465
		++(*line);
-
 
466
 
-
 
467
//	if ( upper )
-
 
468
	//	ToUpper ();
-
 
469
 
-
 
470
	return (*this);
392
}
471
}
393
 
472
 
394
char *String::readToEndOfLine(char *data)
473
char *String::readToEndOfLine(char *data)
395
{
474
{
396
	return (char *)this->readToEndOfLine((unsigned char *)data);
475
	return (char *)this->readToEndOfLine((unsigned char *)data);
Line 447... Line 526...
447
			if ( newstr != "" ) newstr = newstr + token;
526
			if ( newstr != "" ) newstr = newstr + token;
448
			newstr = newstr + this->substr(lastPos, pos - lastPos);
527
			newstr = newstr + this->substr(lastPos, pos - lastPos);
449
		}
528
		}
450
 
529
 
451
		// Found a token, add it to the vector.
530
		// Found a token, add it to the vector.
452
		whichtok++;
531
		whichtok++;
453
 
532
 
454
		if ( pos >= this->length() )
533
		if ( pos >= this->length() )
455
			break;
534
			break;
456
 
535
 
457
		// skip past token
536
		// skip past token
458
		size_t i = 0;
537
		size_t i = 0;
459
		size_t max = strlen(token);
538
		size_t max = strlen(token);
460
		lastPos = pos;
539
		lastPos = pos;
461
		while ( (i < max) && (token[i] == this->at(lastPos)) )
540
		while ( (i < max) && (token[i] == this->at(lastPos)) )
462
		{
541
		{
463
			++i;
542
			++i;
464
			++lastPos;
543
			++lastPos;
465
		}
544
		}
Line 520... Line 599...
520
	}
599
	}
521
 
600
 
522
	return newstr;
601
	return newstr;
523
}
602
}
524
 
603
 
525
const String &String::remove(char c)
604
const String &String::removeChar(char c)
526
{
605
{
527
	std::string::size_type pos = this->find_first_of(c, 0);
606
	std::string::size_type pos = this->find_first_of(c, 0);
528
	while(pos != std::string::npos) {
607
	while(pos != std::string::npos) {
529
		this->erase(pos, 1);
608
		this->erase(pos, 1);
530
		pos = this->find_first_of(c, 0);
609
		pos = this->find_first_of(c, 0);
531
	}
610
	}
532
 
611
 
533
	return (*this);
612
	return (*this);
534
}
613
}
535
 
614
 
536
String String::removeChar(char c) const
615
String String::remove(char c) const
537
{
616
{
538
	String newStr = *this;
617
	String newStr = *this;
539
 
618
 
540
	std::string::size_type pos = newStr.find_first_of(c, 0);
619
	std::string::size_type pos = newStr.find_first_of(c, 0);
541
	while(pos != std::string::npos) {
620
	while(pos != std::string::npos) {
Line 570... Line 649...
570
	return true;
649
	return true;
571
}
650
}
572
 
651
 
573
const String &String::removeFirstSpace()
652
const String &String::removeFirstSpace()
574
{
653
{
575
	std::string::size_type pos = this->find_first_not_of(" ", 0);
654
	std::string::size_type pos = this->find_first_not_of(" \t\f\v\n\r", 0);
576
	if ( pos != std::string::npos ) {
655
	if ( pos != std::string::npos ) {
577
		this->erase(0, pos);
656
		this->erase(0, pos);
-
 
657
	}
-
 
658
	return (*this);
-
 
659
}
-
 
660
const String &String::removeEndSpace()
-
 
661
{
-
 
662
	std::string::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
-
 
663
	if ( pos != std::string::npos ) {
-
 
664
		this->erase(pos + 1);
578
	}
665
	}
579
	return (*this);
666
	return (*this);
580
}
667
}
581
 
668
 
582
const String &String::truncate(int iNum)
669
const String &String::truncate(int iNum)