summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2005-09-14 14:56:01 +0000
committerDerick Rethans <derick@php.net>2005-09-14 14:56:01 +0000
commit6e3d5a9e227416d294373760cca09f17c43b12dc (patch)
treeb2ebf9d362bcb36e5ac4238413328af0fe7f1658
parenteb0fb96526c8523f13b74981d39948f595b230f0 (diff)
downloadphp-git-6e3d5a9e227416d294373760cca09f17c43b12dc.tar.gz
- Rename icu_loc* to i18n_loc*
- Added i18n_strtotitle (name is not sure yet) - work in progress.
-rw-r--r--ext/unicode/locale.c66
-rw-r--r--ext/unicode/php_unicode.h5
-rw-r--r--ext/unicode/unicode.c5
3 files changed, 70 insertions, 6 deletions
diff --git a/ext/unicode/locale.c b/ext/unicode/locale.c
index ab0762c3b0..b69eec1327 100644
--- a/ext/unicode/locale.c
+++ b/ext/unicode/locale.c
@@ -19,6 +19,7 @@
#include "php_unicode.h"
#if HAVE_UNICODE
+#include "unicode/ubrk.h"
static void php_canonicalize_locale_id(char **target, int32_t *target_len, char *locale, UErrorCode *status)
{
@@ -39,7 +40,7 @@ static void php_canonicalize_locale_id(char **target, int32_t *target_len, char
*target_len = canonicalized_len;
}
-PHP_FUNCTION(icu_loc_get_default)
+PHP_FUNCTION(i18n_loc_get_default)
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
@@ -48,7 +49,7 @@ PHP_FUNCTION(icu_loc_get_default)
RETURN_STRING(UG(default_locale), 1);
}
-PHP_FUNCTION(icu_loc_set_default)
+PHP_FUNCTION(i18n_loc_set_default)
{
char *locale;
int locale_len;
@@ -79,6 +80,67 @@ PHP_FUNCTION(icu_loc_set_default)
RETURN_TRUE;
}
+/* {{{ php_strtotitle
+ */
+PHPAPI char *php_strtotitle(char *s, size_t len)
+{
+ s[0] = toupper(s[0]);
+ return s;
+}
+/* }}} */
+
+/* {{{ php_u_strtotitle
+ */
+PHPAPI UChar* php_u_strtotitle(UChar **s, int32_t *len, const char* locale)
+{
+ UChar *dest = NULL;
+ int32_t dest_len;
+ UErrorCode status = U_ZERO_ERROR;
+ UBreakIterator *brkiter;
+
+ dest_len = *len;
+ brkiter = ubrk_open(UBRK_TITLE, locale, *s, *len, &status);
+ while (1) {
+ status = U_ZERO_ERROR;
+ dest = eurealloc(dest, dest_len+1);
+ dest_len = u_strToTitle(dest, dest_len, *s, *len, NULL, locale, &status);
+ if (status != U_BUFFER_OVERFLOW_ERROR) {
+ break;
+ }
+ }
+ ubrk_close(brkiter);
+
+ if (U_SUCCESS(status)) {
+ efree(*s);
+ dest[dest_len] = 0;
+ *s = dest;
+ *len = dest_len;
+ } else {
+ efree(dest);
+ }
+
+ return *s;
+}
+/* }}} */
+
+
+/* {{{ proto string strtoupper(string str)
+ Makes a string uppercase */
+PHP_FUNCTION(i18n_strtotitle)
+{
+ zval **arg;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) {
+ WRONG_PARAM_COUNT;
+ }
+ if (Z_TYPE_PP(arg) != IS_STRING && Z_TYPE_PP(arg) != IS_UNICODE) {
+ convert_to_text_ex(arg);
+ }
+
+ RETVAL_ZVAL(*arg, 1, 0);
+ php_u_strtotitle(&Z_USTRVAL_P(return_value), &Z_USTRLEN_P(return_value), UG(default_locale));
+}
+/* }}} */
#endif /* HAVE_UNICODE */
diff --git a/ext/unicode/php_unicode.h b/ext/unicode/php_unicode.h
index 1bb148b2bd..b4e5684595 100644
--- a/ext/unicode/php_unicode.h
+++ b/ext/unicode/php_unicode.h
@@ -55,8 +55,9 @@ PHP_MINFO_FUNCTION(unicode);
#include "TSRM.h"
#endif
-PHP_FUNCTION(icu_loc_get_default);
-PHP_FUNCTION(icu_loc_set_default);
+PHP_FUNCTION(i18n_loc_get_default);
+PHP_FUNCTION(i18n_loc_set_default);
+PHP_FUNCTION(i18n_strtotitle);
extern php_stream_filter_factory php_unicode_filter_factory;
diff --git a/ext/unicode/unicode.c b/ext/unicode/unicode.c
index 40fa14c7a6..88759f4d23 100644
--- a/ext/unicode/unicode.c
+++ b/ext/unicode/unicode.c
@@ -102,10 +102,11 @@ static PHP_FUNCTION(unicode_encode)
}
/* {{{ unicode_functions[] */
function_entry unicode_functions[] = {
- PHP_FE(icu_loc_get_default, NULL)
- PHP_FE(icu_loc_set_default, NULL)
+ PHP_FE(i18n_loc_get_default, NULL)
+ PHP_FE(i18n_loc_set_default, NULL)
PHP_FE(unicode_decode, NULL)
PHP_FE(unicode_encode, NULL)
+ PHP_FE(i18n_strtotitle, NULL)
{ NULL, NULL, NULL }
};
/* }}} */