CVS update: php3/functions
| From: | jim | Date: | Sun, 11 Oct 1998 01:21:40 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1811@lists.php.net to get a copy of this message | ||
Date: Saturday October 10, 1998 @ 21:21
Author: jim
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv1707/functions
Modified Files:
string.c
Log Message:
Added optional third parameter to strpos() to specify offset to start searching from.
Index: php3/functions/string.c
diff -c php3/functions/string.c:1.144 php3/functions/string.c:1.145
*** php3/functions/string.c:1.144 Sun Oct 4 12:03:29 1998
--- php3/functions/string.c Sat Oct 10 21:21:39 1998
***************
*** 30,36 ****
*/
! /* $Id: string.c,v 1.144 1998/10/04 16:03:29 zeev Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 30,36 ----
*/
! /* $Id: string.c,v 1.145 1998/10/11 01:21:39 jim Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 516,543 ****
void php3_strpos(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *haystack, *needle;
char *found = NULL;
TLS_VARS;
! if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &haystack, &needle) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(haystack);
if (needle->type == IS_STRING) {
if (needle->value.str.len==0) {
php3_error(E_WARNING,"Empty delimiter");
RETURN_FALSE;
}
! found = strstr(haystack->value.str.val, needle->value.str.val);
} else {
convert_to_long(needle);
! found = strchr(haystack->value.str.val, (char) needle->value.lval);
}
if (found) {
! RETVAL_LONG(haystack->value.str.len - strlen(found));
} else {
RETVAL_FALSE;
}
--- 516,561 ----
void php3_strpos(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *haystack, *needle, *OFFSET;
! int offset = 0;
char *found = NULL;
TLS_VARS;
! switch(ARG_COUNT(ht)) {
! case 2:
! if (getParameters(ht, 2, &haystack, &needle) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
! break;
! case 3:
! if (getParameters(ht, 3, &haystack, &needle, &OFFSET) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
! convert_to_long(OFFSET);
! offset = OFFSET->value.lval;
! break;
! default:
WRONG_PARAM_COUNT;
}
convert_to_string(haystack);
+ if (offset > haystack->value.str.len) {
+ php3_error(E_WARNING,"offset not contained in string");
+ RETURN_FALSE;
+ }
if (needle->type == IS_STRING) {
if (needle->value.str.len==0) {
php3_error(E_WARNING,"Empty delimiter");
RETURN_FALSE;
}
! found = strstr(haystack->value.str.val+offset, needle->value.str.val);
} else {
convert_to_long(needle);
! found = strchr(haystack->value.str.val+offset, (char) needle->value.lval);
}
if (found) {
! RETVAL_LONG(found - haystack->value.str.val);
} else {
RETVAL_FALSE;
}
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net