CVS update: php3/functions
| From: | sas | Date: | Sat, 19 Dec 1998 20:44:12 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-2881@lists.php.net to get a copy of this message | ||
Date: Saturday December 19, 1998 @ 15:44
Author: sas
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv19042/functions
Modified Files:
basic_functions.c php3_string.h string.c
Log Message:
added chunk_split()
especially useful for PR#967
Index: php3/functions/basic_functions.c
diff -c php3/functions/basic_functions.c:1.238 php3/functions/basic_functions.c:1.239
*** php3/functions/basic_functions.c:1.238 Sat Dec 19 07:47:58 1998
--- php3/functions/basic_functions.c Sat Dec 19 15:44:11 1998
***************
*** 141,146 ****
--- 141,147 ----
{"addslashes", php3_addslashes, NULL},
{"chop", php3_chop, NULL},
+ {"chunk_split", php3_chunk_split, NULL},
{"trim", php3_trim, NULL},
{"ltrim", php3_ltrim, NULL},
{"rtrim", php3_chop, NULL},
Index: php3/functions/php3_string.h
diff -c php3/functions/php3_string.h:1.24 php3/functions/php3_string.h:1.25
*** php3/functions/php3_string.h:1.24 Thu Dec 17 11:22:08 1998
--- php3/functions/php3_string.h Sat Dec 19 15:44:12 1998
***************
*** 29,35 ****
*/
! /* $Id: php3_string.h,v 1.24 1998/12/17 16:22:08 rasmus Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
--- 29,35 ----
*/
! /* $Id: php3_string.h,v 1.25 1998/12/19 20:44:12 sas Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
***************
*** 77,82 ****
--- 77,83 ----
extern void php3_chr_replace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_setlocale(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_stristr(INTERNAL_FUNCTION_PARAMETERS);
+ extern void php3_chunk_split(INTERNAL_FUNCTION_PARAMETERS);
#if HAVE_CRYPT
extern php3_module_entry crypt_module_entry;
Index: php3/functions/string.c
diff -c php3/functions/string.c:1.150 php3/functions/string.c:1.151
*** php3/functions/string.c:1.150 Thu Dec 17 11:45:55 1998
--- php3/functions/string.c Sat Dec 19 15:44:12 1998
***************
*** 30,36 ****
*/
! /* $Id: string.c,v 1.150 1998/12/17 16:45:55 rasmus Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 30,36 ----
*/
! /* $Id: string.c,v 1.151 1998/12/19 20:44:12 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 709,714 ****
--- 709,795 ----
}
}
/* }}} */
+
+ static char *
+ _php3_chunk_split(char *src, int srclen, char *end, int endlen, int chunklen)
+ {
+ char *dest;
+ char *p, *q;
+ int chunks; /* complete chunks! */
+ int restlen;
+
+ chunks = srclen / chunklen;
+ restlen = srclen - chunks * chunklen; /* srclen % chunklen */
+
+ dest = emalloc((srclen + (chunks + 1) * endlen + 1) * sizeof(char));
+
+ for(p = src, q = dest; p < (src + srclen - chunklen + 1); ) {
+ memcpy(q, p, chunklen);
+ q += chunklen;
+ memcpy(q, end, endlen);
+ q += endlen;
+ p += chunklen;
+ }
+
+ if(restlen) {
+ memcpy(q, p, restlen);
+ q += restlen;
+ memcpy(q, end, endlen);
+ q += endlen;
+ }
+
+ *q = '\0';
+
+ return(dest);
+ }
+
+ /* {{{ proto string chunk_split(string str [, int chunklen [, string ending]])
+ Return splitted line */
+ void php3_chunk_split(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *p_str, *p_chunklen, *p_ending;
+ int argc;
+ char *result;
+ char *end = "\r\n";
+ int endlen = 2;
+ int chunklen = 76;
+ TLS_VARS;
+
+ argc = ARG_COUNT(ht);
+
+ if(!((argc == 1 && getParameters(ht, 1, &p_str) != FAILURE) ||
+ (argc == 2 && getParameters(ht, 2, &p_str, &p_chunklen) != FAILURE) ||
+ (argc == 3 && getParameters(ht, 3, &p_str, &p_chunklen,
+ &p_ending) != FAILURE))) {
+ WRONG_PARAM_COUNT;
+ }
+
+ switch(argc) {
+ case 3:
+ convert_to_string(p_ending);
+ end = p_ending->value.str.val;
+ endlen = p_ending->value.str.len;
+ case 2:
+ convert_to_long(p_chunklen);
+ chunklen = p_chunklen->value.lval;
+ case 1:
+ convert_to_string(p_str);
+ }
+
+ if(chunklen == 0) {
+ php3_error(E_WARNING, "chunklen is 0");
+ RETURN_FALSE;
+ }
+
+ result = _php3_chunk_split(p_str->value.str.val, p_str->value.str.len,
+ end, endlen, chunklen);
+
+ if(result) {
+ RETVAL_STRING(result, 0);
+ } else {
+ RETURN_FALSE;
+ }
+ }
/* {{{ proto string substr(string str, int start [, int length])
Return part of a string */
--
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