Sign in to follow this  
Aperion

simple scriptstdstring.cpp patch

Recommended Posts

Hello all I have been working on the Rigs of Rods project using x86_64 on Kubuntu 9.04. I had to make a simple change to get Angelscript to compile. Sorry I don't have the exact error message but it complained that strstr (not found/defined/etc) below is the generated patch for the change
diff -U 3 -H -d -r -N -- sdk/add_on/scriptstdstring/scriptstdstring.cpp sdk-org/add_on/scriptstdstring/scriptstdstring.cpp
--- sdk/add_on/scriptstdstring/scriptstdstring.cpp	2009-05-03 10:13:56.502067157 -0700
+++ sdk-org/add_on/scriptstdstring/scriptstdstring.cpp	2009-05-03 10:18:33.990322811 -0700
@@ -455,7 +455,7 @@
 
 void RegisterStdString(asIScriptEngine * engine)
 {
-	if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY"))
+	if (string((asGetLibraryOptions()).find("AS_MAX_PORTABILITY") != string::npos)
 		RegisterStdString_Generic(engine);
 	else
 		RegisterStdString_Native(engine);



Share this post


Link to post
Share on other sites
I find it hard to believe that strstr() isn't available, as it is a standard C function. Rather than changing the code to use std::string::find(), could you help me determine what would be the correct header file to include for the strstr() function?

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
Yes. Thanks.

I'd still prefer if Aperion could confirm that adding #include <string.h> fixes the problem he had though.


I tried it multiple ways #include <cstring> works and #include <string.h> Would cstring be the more appropriate way for c++?

Share this post


Link to post
Share on other sites
I really can't say. But if #include <string.h> works then that's what I'll do. This is what I have in the other add-ons anyway, I guess I just forgot to add it to this one.

Share this post


Link to post
Share on other sites
According to the C++ standard, if you include cstring, then it takes all the functions and puts them in the std namespace without putting them in the root namespace. If you include string.h then it puts the functions in both the root namespace and the std namespace. In practice, pretty much every compiler puts the functions in both if you include cstring, with the one exception I know of being Borland's C++ compilers, which only puts the functions in the std namespace. This basically means that string.h is the right choice if you don't want to prefix everything with std::.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
According to the C++ standard, if you include cstring, then it takes all the functions and puts them in the std namespace without putting them in the root namespace. If you include string.h then it puts the functions in both the root namespace and the std namespace. In practice, pretty much every compiler puts the functions in both if you include cstring, with the one exception I know of being Borland's C++ compilers, which only puts the functions in the std namespace. This basically means that string.h is the right choice if you don't want to prefix everything with std::.


ok, thanks for the explanation

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this