Subversion Repositories spk

Rev

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

Rev 126 Rev 127
Line 533... Line 533...
533
	if (bCaseSensative) return (this->find(str, 0) == Utils::String::npos) ? false : true;
533
	if (bCaseSensative) return (this->find(str, 0) == Utils::String::npos) ? false : true;
534

534

535
	String thisLower = this->lower();
535
	String thisLower = this->lower();
536
	String strLower = str.lower();
536
	String strLower = str.lower();
537
	return (thisLower.find(strLower, 0) == Utils::String::npos) ? false : true;
537
	return (thisLower.find(strLower, 0) == Utils::String::npos) ? false : true;
-
 
538
}
-
 
539
bool String::containsAny(const String &str, bool bCaseSensative) const
-
 
540
{
-
 
541
	char *c = (char *)str.c_str();
-
 
542
	while (*c != 0)
-
 
543
	{
-
 
544
		char c1 = *c;
-
 
545
		if (contains(c1))
-
 
546
			return true;
-
 
547
		c++;
-
 
548
	}
-
 
549

-
 
550
	return false;
538
}
551
}
539
bool String::isin(const String &str, bool bCaseSensative) const
552
bool String::isin(const String &str, bool bCaseSensative) const
540
{
553
{
541
	return contains(str, bCaseSensative);
554
	return contains(str, bCaseSensative);
542
}
555
}
Line 562... Line 575...
562
			f = true;
575
			f = true;
563
			break;
576
			break;
564
		}
577
		}
565
	}
578
	}
566
	return f;
579
	return f;
567
}
580
}
568

581

569
String String::between(const String &before, const String &after) const
582
String String::between(const String &before, const String &after) const
570
{
583
{
571
	int pos = this->findPos(before);
584
	int pos = this->findPos(before);
572
	if ( pos >= 0 ) {
585
	if ( pos >= 0 ) {
Line 577... Line 590...
577

590

578
	return "";
591
	return "";
579
}
592
}
580

593

581
String String::mid(int start, int end) const
594
String String::mid(int start, int end) const
582
{
595
{
583
	return this->substr(start, end - start);
596
	return this->substr(start, end - start);
584
}
597
}
585
String String::left(long num) const
598
String String::left(long num) const
586
{
599
{
587
	if ( num < 0 )
600
	if ( num < 0 )
Line 591... Line 604...
591

604

592
	return this->substr(0, num);
605
	return this->substr(0, num);
593
}
606
}
594

607

595
String String::right(int num) const
608
String String::right(int num) const
596
{
609
{
597
	if ( num > 0 ) num -= (int)this->length();
610
	if ( num > 0 ) num -= (int)this->length();
598
	if ( num < -(int)this->length() ) num = -(int)this->length();
611
	if ( num < -(int)this->length() ) num = -(int)this->length();
599

612

600
	return this->substr(-num);
613
	return this->substr(-num);
601
}
614
}
Line 703... Line 716...
703

716

704

717

705
String *String::tokenise(const char *token, int *max) const
718
String *String::tokenise(const char *token, int *max) const
706
{
719
{
707
	if ( empty() ) {
720
	if ( empty() ) {
708
		*max = 0;
721
		*max = 0;
709
		return NULL;
722
		return NULL;
710
	}
723
	}
711
724
712
	*max = this->countToken(token);
725
	*max = this->countToken(token);
713

726

714
	if ( (*max) <= 0 ) {
727
	if ( (*max) <= 0 ) {
715
		*max = 0;
728
		*max = 0;
716
		return NULL;
729
		return NULL;
717
	}
730
	}
718
731
719
	String *newstr = (*max == 1) ? new String : new String[*max];
732
	String *newstr = (*max == 1) ? new String : new String[*max];
720

733

721
	int whichtok = 0;
734
	int whichtok = 0;
722
	// get first token
735
	// get first token
723
	Utils::String::size_type lastPos = 0;
736
	Utils::String::size_type lastPos = 0;
724
	Utils::String::size_type pos     = this->_token_nextPos(token, 0);
737
	Utils::String::size_type pos     = this->_token_nextPos(token, 0);
Line 749... Line 762...
749
		// get the next token
762
		// get the next token
750
		pos = _token_nextPos(token, lastPos);
763
		pos = _token_nextPos(token, lastPos);
751
	}
764
	}
752

765

753
	return newstr;
766
	return newstr;
754
}
767
}
755

768

756
const String &String::removeChar(const char *cs)
769
const String &String::removeChar(const char *cs)
757
{
770
{
758
	char *current = const_cast<char *>(cs);
771
	char *current = const_cast<char *>(cs);
759
	while ( current[0] != '\0' ) {
772
	while ( current[0] != '\0' ) {
Line 763... Line 776...
763

776

764
	return (*this);
777
	return (*this);
765
}
778
}
766

779

767
const String &String::removeChar(char c)
780
const String &String::removeChar(char c)
768
{
781
{
769
	Utils::String::size_type pos = this->find_first_of(c, 0);
782
	Utils::String::size_type pos = this->find_first_of(c, 0);
770
	while(pos != Utils::String::npos) {
783
	while(pos != Utils::String::npos) {
771
		this->erase(pos, 1);
784
		this->erase(pos, 1);
772
		pos = this->find_first_of(c, 0);
785
		pos = this->find_first_of(c, 0);
773
	}
786
	}
774
787
775
	return (*this);
788
	return (*this);
776
}
789
}
777

790

778
String String::remove(char c) const
791
String String::remove(char c) const
779
{
792
{
780
	String newStr = *this;
793
	String newStr = *this;
781

794

Line 784... Line 797...
784
		newStr.erase(pos, 1);
797
		newStr.erase(pos, 1);
785
		pos = newStr.find_first_of(c, 0);
798
		pos = newStr.find_first_of(c, 0);
786
	}
799
	}
787

800

788
	return newStr;
801
	return newStr;
789
}
802
}
790
803
791
bool String::_isCharNumber(char c) const
804
bool String::_isCharNumber(char c) const
792
{
805
{
793
	return (c >= '0' && c <= '9') ? true : false;
806
	return (c >= '0' && c <= '9') ? true : false;
794
}
807
}
795

808

796
bool String::isCharNumber(int c) const
809
bool String::isCharNumber(int c) const
797
{
810
{
798
	return _isCharNumber(this->at(c));
811
	return _isCharNumber(this->at(c));
799
}
812
}
800

813

801
bool String::isNumber(bool integer) const
814
bool String::isNumber(bool integer) const
802
{
815
{
Line 821... Line 834...
821
	else
834
	else
822
		this->clear();
835
		this->clear();
823
	return (*this);
836
	return (*this);
824
}
837
}
825
const String &String::removeEndSpace()
838
const String &String::removeEndSpace()
826
{
839
{
827
	Utils::String::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
840
	Utils::String::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
828
	if ( pos != Utils::String::npos ) {
841
	if ( pos != Utils::String::npos ) {
829
		this->erase(pos + 1);
842
		this->erase(pos + 1);
830
	}
843
	}
831
	else
844
	else
Line 936... Line 949...
936
				else
949
				else
937
					return COMPARE_NEWER;
950
					return COMPARE_NEWER;
938
			}
951
			}
939
			// failsale, we should never get here
952
			// failsale, we should never get here
940
			return COMPARE_SAME;
953
			return COMPARE_SAME;
941
		}
954
		}
942

955

943
		// one has more sections, most likly its the newer ones, ie, 1.00 v 1.00.1, 1.00.1 will be newer
956
		// one has more sections, most likly its the newer ones, ie, 1.00 v 1.00.1, 1.00.1 will be newer
944
		if ( sNum1.empty() )
957
		if ( sNum1.empty() )
945
			return COMPARE_NEWER;
958
			return COMPARE_NEWER;
946
		else if ( sNum2.empty() )
959
		else if ( sNum2.empty() )
Line 964... Line 977...
964
		{
977
		{
965
			while ( sNum1.length() < sNum2.length() )
978
			while ( sNum1.length() < sNum2.length() )
966
				sNum1 += "0";
979
				sNum1 += "0";
967
			while ( sNum2.length() < sNum1.length() )
980
			while ( sNum2.length() < sNum1.length() )
968
				sNum2 += "0";
981
				sNum2 += "0";
969
		}
982
		}
970
983
971
		// check the values of the current section
984
		// check the values of the current section
972
		int iNum1 = sNum1;
985
		int iNum1 = sNum1;
973
		int iNum2 = sNum2;
986
		int iNum2 = sNum2;
974

987

975
		if ( iNum1 > iNum2 )
988
		if ( iNum1 > iNum2 )
Line 979... Line 992...
979

992

980
		// now compare the "letter" version, only test if one has a letter
993
		// now compare the "letter" version, only test if one has a letter
981
		if ( cNum1 || cNum2 )
994
		if ( cNum1 || cNum2 )
982
		{
995
		{
983
			if ( !cNum1 )
996
			if ( !cNum1 )
984
				return COMPARE_NEWER;
997
				return COMPARE_NEWER;
985
			if ( !cNum2 )
998
			if ( !cNum2 )
986
				return COMPARE_OLDER;
999
				return COMPARE_OLDER;
987

1000

988
			if ( cNum2 > cNum1 )
1001
			if ( cNum2 > cNum1 )
989
				return COMPARE_NEWER;
1002
				return COMPARE_NEWER;
Line 994... Line 1007...
994
		// move to the next section
1007
		// move to the next section
995
		++section;
1008
		++section;
996
	}
1009
	}
997

1010

998
	return COMPARE_SAME;
1011
	return COMPARE_SAME;
-
 
1012
}
-
 
1013

-
 
1014
bool String::match(const Utils::String &pattern) const
-
 
1015
{
-
 
1016
	enum State {
-
 
1017
		Exact,      // exact match
-
 
1018
		Any,		// ?
-
 
1019
		AnyRepeat   // *
-
 
1020
	};
-
 
1021

-
 
1022
	const char *s = this->c_str();
-
 
1023
	const char *p = pattern.c_str();
-
 
1024
	const char *q = 0;
-
 
1025
	int state = 0;
-
 
1026

-
 
1027
	bool match = true;
-
 
1028
	while (match && *p) {
-
 
1029
		if (*p == '*') {
-
 
1030
			state = AnyRepeat;
-
 
1031
			q = p + 1;
-
 
1032
		}
-
 
1033
		else if (*p == '?') state = Any;
-
 
1034
		else state = Exact;
-
 
1035

-
 
1036
		if (*s == 0) break;
-
 
1037

-
 
1038
		switch (state) {
-
 
1039
		case Exact:
-
 
1040
			match = *s == *p;
-
 
1041
			s++;
-
 
1042
			p++;
-
 
1043
			break;
-
 
1044

-
 
1045
		case Any:
-
 
1046
			match = true;
-
 
1047
			s++;
-
 
1048
			p++;
-
 
1049
			break;
-
 
1050

-
 
1051
		case AnyRepeat:
-
 
1052
			match = true;
-
 
1053
			s++;
-
 
1054

-
 
1055
			if (*s == *q) p++;
-
 
1056
			break;
-
 
1057
		}
-
 
1058
	}
-
 
1059

-
 
1060
	if (state == AnyRepeat) return (*s == *q);
-
 
1061
	else if (state == Any) return (*s == *p);
-
 
1062
	else return match && (*s == *p);
999
}
1063
}
1000

1064

1001
}//NAMESPACE
1065
}//NAMESPACE
1002
 
1066