[php-i18n-commits] cvs commit: php4/ext/mbstring php_mb_function.h mbfunction.c

Back to archive index

Moriyoshi Koizumi moriy****@users*****
2002年 10月 1日 (火) 03:31:06 JST


moriyoshi    02/10/01 03:31:06

  Modified:    ext/mbstring php_mb_function.h mbfunction.c
  Log:
  added php_mb_mbchar_bytes_ex() and php_mb_strtok_r_ex()
  
  Revision  Changes    Path
  1.7       +3 -0      php4/ext/mbstring/php_mb_function.h
  
  Index: php_mb_function.h
  ===================================================================
  RCS file: /cvsroot/php-i18n/php4/ext/mbstring/php_mb_function.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- php_mb_function.h	30 May 2002 17:51:50 -0000	1.6
  +++ php_mb_function.h	30 Sep 2002 18:31:06 -0000	1.7
  @@ -326,6 +326,9 @@
   PHPAPI char *
   php_mb_convert_kana(const char *string_val, size_t string_len, php_mb_enc *encoding, int mode, size_t *return_len  TSRMLS_DC);
   
  +PHPAPI int php_mb_mbchar_bytes_ex(const char *s, const php_mb_enc *enc);
  +
  +PHPAPI char *php_mb_strtok_r_ex(char *s1, const char *s2, char **last, php_mb_enc *enc);
   
   /*
    * ZEND_MULTIBYTE support
  
  
  
  1.11      +74 -0     php4/ext/mbstring/mbfunction.c
  
  Index: mbfunction.c
  ===================================================================
  RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbfunction.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- mbfunction.c	9 Jun 2002 04:41:23 -0000	1.10
  +++ mbfunction.c	30 Sep 2002 18:31:06 -0000	1.11
  @@ -3142,7 +3142,81 @@
   	return result;
   }
   
  +/* {{{ PHPAPI php_mbstr_mbchar_bytes_ex(const char *s, const php_mb_enc *enc) */
   
  +PHPAPI int php_mb_mbchar_bytes_ex(const char *s, const php_mb_enc *enc)
  +{
  +	if ( enc != NULL ) {
  +		if( enc->type & PHP_MB_ENCTYPE_MBCS ) {
  +			if( enc->mblen_table != NULL ) {
  +				if ( *s != '\0' ) return enc->mblen_table[*(unsigned char *)s];
  +			}
  +		} else if ( enc->type & (PHP_MB_ENCTYPE_WCS2BE | PHP_MB_ENCTYPE_WCS2LE ) ) {
  +			return 2;
  +		} else if ( enc->type & (PHP_MB_ENCTYPE_WCS4BE | PHP_MB_ENCTYPE_WCS4LE ) ) {
  +			return 4;
  +		}
  +	}
  +	return 1;
  +}
  +/* }}} */
  +
  +/* {{{ php_mb_strtok_r_ex(char*, char*, char**, php_mb_enc *enc) */
  +PHPAPI char *php_mb_strtok_r_ex(char *s1, const char *s2, char **last, php_mb_enc *enc)
  +{
  +	register char *p1, *p2;
  +	char *retval = NULL;
  +	int nbytes;
  +
  +	if( s2 == NULL || last == NULL ) return NULL;
  +
  +	p1 = ( s1 ? s1 : *last );
  +	if( p1 == NULL ) return NULL;
  +
  +	retval = NULL;
  +	*last = NULL;
  +	while (*p1 != '\0') {
  +		nbytes = php_mb_mbchar_bytes_ex( p1, enc );
  +		if (nbytes == 1) {
  +			for (p2 = s2; *p2 != '\0' && *p1 == *p2; p2++);
  +
  +			if (*p1 != *p2) {
  +				retval = p1;
  +				break;
  +			} 
  +		} else {
  +			retval = p1;
  +			break;
  +		}
  +		while (--nbytes >= 0) {
  +			if( *(++p1) == '\0' ) goto out;
  +		} 
  +	}
  +
  +	while (*p1 != '\0') {
  +		nbytes = php_mb_mbchar_bytes_ex( p1, enc );
  +		if (nbytes == 1) {
  +			for (p2 = s2; *p2 != '\0'; p2++) {
  +				if (*p1 == *p2) {
  +					*p1 = '\0';
  +					*last = p1 + 1;
  +					goto out;
  +				}
  +			}
  +		}
  +		while (--nbytes >= 0) {
  +			if( *(++p1) == '\0' ) goto out;
  +		} 
  +	}
  +
  +out:
  +	return retval;
  +}
  +/* }}} */
  +
  +/*
  + * ZEND_MULTIBYTE support
  + */
   
   #ifdef ZEND_MULTIBYTE
   
  
  
  



php-i18n-commits メーリングリストの案内
Back to archive index