[uClibc-cvs] CVS uClibc++/include

CVS User gkajmowi gkajmowi at codepoet.org
Sun Jan 2 04:14:16 UTC 2005


Update of /var/cvs/uClibc++/include
In directory nail:/tmp/cvs-serv12085/include

Modified Files:
	string 
Log Message:
Added find/rfind functions to string class

--- /var/cvs/uClibc++/include/string	2004/12/18 22:00:45	1.8
+++ /var/cvs/uClibc++/include/string	2005/01/02 04:14:15	1.9
@@ -446,17 +446,51 @@
 	}
 	allocator_type get_allocator() const{
 		return vector<Ch, A>::a;
-	};
+	}
+
+	size_type find (const basic_string& str, size_type pos = 0) const{
+		if(str.length() > length()){
+			return npos;
+		}
+		size_type max_string_start = length() - str.length();
+		for(size_type i = pos; i < max_string_start; ++i){
+			if(str == substr(i, str.length())){
+				return i;
+			}
+		}
 
-/*	size_type find (const basic_string& str, size_type pos = 0) const;
-	size_type find (const charT* s, size_type pos, size_type n) const;
-	size_type find (const charT* s, size_type pos = 0) const;
-	size_type find (charT c, size_type pos = 0) const;
-	size_type rfind(const basic_string& str, size_type pos = npos) const;
-	size_type rfind(const charT* s, size_type pos, size_type n) const;
-	size_type rfind(const charT* s, size_type pos = npos) const;
-	size_type rfind(charT c, size_type pos = npos) const;
-	size_type find_first_of(const basic_string& str, size_type pos = 0) const;
+		return npos;
+	}
+	size_type find (const Ch* s, size_type pos, size_type n) const{
+		return find(basic_string<Ch, Tr, A>(s,n),pos);
+	}
+	size_type find (const Ch* s, size_type pos = 0) const{
+		return find(basic_string<Ch, Tr, A>(s),pos);
+	}
+	size_type find (Ch c, size_type pos = 0) const{
+		return find(basic_string<Ch, Tr, A>(1,c),pos);
+	}
+	size_type rfind(const basic_string& str, size_type pos = npos) const{
+		if(pos >= length()){
+			pos = length();
+		}
+		for(size_type i = pos; i > 0; --i){
+			if(str == substr(i-1, str.length())){
+				return i-1;
+			}
+		}
+		return npos;
+	}
+	size_type rfind(const Ch* s, size_type pos, size_type n) const{
+		return rfind(basic_string<Ch, Tr, A>(s,n),pos);
+	}
+	size_type rfind(const Ch* s, size_type pos = npos) const{
+		return rfind(basic_string<Ch, Tr, A>(s),pos);
+	}
+	size_type rfind(Ch c, size_type pos = npos) const{
+		return rfind(basic_string<Ch, Tr, A>(1,c),pos);
+	}
+/*	size_type find_first_of(const basic_string& str, size_type pos = 0) const;
 	size_type find_first_of(const charT* s, size_type pos, size_type n) const;
 	size_type find_first_of(const charT* s, size_type pos = 0) const;
 	size_type find_first_of(charT c, size_type pos = 0) const;



More information about the uClibc-cvs mailing list