Skip to content

Commit 0a7ae87

Browse files
committed
Added IntlCodePointBreakIterator.
Objects of this class can be instantiated with IntlBreakIterator::createCodePointInstance() The method does not take a locale, as it would not make sense in this context. This class has one additional method: long IntlCodePointIterator::getLastCodePoint() which returns either -1 or the last code point we moved over, if any (and discounting any movement before the last call to IntlBreakIterator::first() or IntlBreakIterator::last()).
1 parent cee3109 commit 0a7ae87

15 files changed

+736
-2
lines changed

ext/intl/breakiterator/breakiterator_class.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <unicode/brkiter.h>
2222
#include <unicode/rbbi.h>
23+
#include "codepointiterator_internal.h"
2324

2425
#include "breakiterator_iterators.h"
2526

@@ -30,14 +31,18 @@ extern "C" {
3031
#include "breakiterator_class.h"
3132
#include "breakiterator_methods.h"
3233
#include "rulebasedbreakiterator_methods.h"
34+
#include "codepointiterator_methods.h"
3335
#include <zend_exceptions.h>
3436
#include <zend_interfaces.h>
3537
#include <assert.h>
3638
}
3739

40+
using PHP::CodePointBreakIterator;
41+
3842
/* {{{ Global variables */
3943
zend_class_entry *BreakIterator_ce_ptr;
4044
zend_class_entry *RuleBasedBreakIterator_ce_ptr;
45+
zend_class_entry *CodePointBreakIterator_ce_ptr;
4146
zend_object_handlers BreakIterator_handlers;
4247
/* }}} */
4348

@@ -49,6 +54,8 @@ U_CFUNC void breakiterator_object_create(zval *object,
4954

5055
if (classId == RuleBasedBreakIterator::getStaticClassID()) {
5156
ce = RuleBasedBreakIterator_ce_ptr;
57+
} else if (classId == CodePointBreakIterator::getStaticClassID()) {
58+
ce = CodePointBreakIterator_ce_ptr;
5259
} else {
5360
ce = BreakIterator_ce_ptr;
5461
}
@@ -274,6 +281,7 @@ static const zend_function_entry BreakIterator_class_functions[] = {
274281
PHP_ME_MAPPING(createCharacterInstance, breakiter_create_character_instance, ainfo_biter_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
275282
PHP_ME_MAPPING(createSentenceInstance, breakiter_create_sentence_instance, ainfo_biter_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
276283
PHP_ME_MAPPING(createTitleInstance, breakiter_create_title_instance, ainfo_biter_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
284+
PHP_ME_MAPPING(createCodePointInstance, breakiter_create_code_point_instance, ainfo_biter_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
277285
PHP_ME_MAPPING(getText, breakiter_get_text, ainfo_biter_void, ZEND_ACC_PUBLIC)
278286
PHP_ME_MAPPING(setText, breakiter_set_text, ainfo_biter_setText, ZEND_ACC_PUBLIC)
279287
PHP_ME_MAPPING(first, breakiter_first, ainfo_biter_void, ZEND_ACC_PUBLIC)
@@ -305,6 +313,14 @@ static const zend_function_entry RuleBasedBreakIterator_class_functions[] = {
305313
};
306314
/* }}} */
307315

316+
/* {{{ CodePointBreakIterator_class_functions
317+
*/
318+
static const zend_function_entry CodePointBreakIterator_class_functions[] = {
319+
PHP_ME_MAPPING(getLastCodePoint, cpbi_get_last_code_point, ainfo_biter_void, ZEND_ACC_PUBLIC)
320+
PHP_FE_END
321+
};
322+
/* }}} */
323+
308324

309325
/* {{{ breakiterator_register_BreakIterator_class
310326
* Initialize 'BreakIterator' class
@@ -364,6 +380,12 @@ void breakiterator_register_BreakIterator_class(TSRMLS_D)
364380
INIT_CLASS_ENTRY(ce, "IntlRuleBasedBreakIterator",
365381
RuleBasedBreakIterator_class_functions);
366382
RuleBasedBreakIterator_ce_ptr = zend_register_internal_class_ex(&ce,
367-
BreakIterator_ce_ptr, NULL TSRMLS_CC);
383+
BreakIterator_ce_ptr, NULL TSRMLS_CC);
384+
385+
/* Create and register 'CodePointBreakIterator' class. */
386+
INIT_CLASS_ENTRY(ce, "IntlCodePointBreakIterator",
387+
CodePointBreakIterator_class_functions);
388+
CodePointBreakIterator_ce_ptr = zend_register_internal_class_ex(&ce,
389+
BreakIterator_ce_ptr, NULL TSRMLS_CC);
368390
}
369391
/* }}} */

ext/intl/breakiterator/breakiterator_methods.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#endif
2020

2121
#include <unicode/brkiter.h>
22+
#include "codepointiterator_internal.h"
2223

2324
#include "breakiterator_iterators.h"
2425

@@ -29,6 +30,8 @@ extern "C" {
2930
#include <zend_exceptions.h>
3031
}
3132

33+
using PHP::CodePointBreakIterator;
34+
3235
U_CFUNC PHP_METHOD(BreakIterator, __construct)
3336
{
3437
zend_throw_exception( NULL,
@@ -107,6 +110,21 @@ U_CFUNC PHP_FUNCTION(breakiter_create_title_instance)
107110
INTERNAL_FUNCTION_PARAM_PASSTHRU);
108111
}
109112

113+
U_CFUNC PHP_FUNCTION(breakiter_create_code_point_instance)
114+
{
115+
UErrorCode status = UErrorCode();
116+
intl_error_reset(NULL TSRMLS_CC);
117+
118+
if (zend_parse_parameters_none() == FAILURE) {
119+
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
120+
"breakiter_create_code_point_instance: bad arguments", 0 TSRMLS_CC);
121+
RETURN_NULL();
122+
}
123+
124+
CodePointBreakIterator *cpbi = new CodePointBreakIterator();
125+
breakiterator_object_create(return_value, cpbi TSRMLS_CC);
126+
}
127+
110128
U_CFUNC PHP_FUNCTION(breakiter_get_text)
111129
{
112130
BREAKITER_METHOD_INIT_VARS;

ext/intl/breakiterator/breakiterator_methods.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ PHP_FUNCTION(breakiter_create_sentence_instance);
3131

3232
PHP_FUNCTION(breakiter_create_title_instance);
3333

34+
PHP_FUNCTION(breakiter_create_code_point_instance);
35+
3436
PHP_FUNCTION(breakiter_get_text);
3537

3638
PHP_FUNCTION(breakiter_set_text);

0 commit comments

Comments
 (0)