PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/intl/breakiterator - breakiterator_class.cpp (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 92 119 77.3 %
Date: 2014-12-13 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | This source file is subject to version 3.01 of the PHP license,      |
       6             :    | that is bundled with this package in the file LICENSE, and is        |
       7             :    | available through the world-wide-web at the following url:           |
       8             :    | http://www.php.net/license/3_01.txt                                  |
       9             :    | If you did not receive a copy of the PHP license and are unable to   |
      10             :    | obtain it through the world-wide-web, please send a note to          |
      11             :    | license@php.net so we can mail you a copy immediately.               |
      12             :    +----------------------------------------------------------------------+
      13             :    | Authors: Gustavo Lopes <cataphract@php.net>                          |
      14             :    +----------------------------------------------------------------------+
      15             : */
      16             : 
      17             : #ifdef HAVE_CONFIG_H
      18             : #include "config.h"
      19             : #endif
      20             : 
      21             : #include <unicode/brkiter.h>
      22             : #include <unicode/rbbi.h>
      23             : #include "codepointiterator_internal.h"
      24             : 
      25             : #include "breakiterator_iterators.h"
      26             : 
      27             : #include <typeinfo>
      28             : 
      29             : extern "C" {
      30             : #define USE_BREAKITERATOR_POINTER 1
      31             : #include "breakiterator_class.h"
      32             : #include "breakiterator_methods.h"
      33             : #include "rulebasedbreakiterator_methods.h"
      34             : #include "codepointiterator_methods.h"
      35             : #include <zend_exceptions.h>
      36             : #include <zend_interfaces.h>
      37             : #include <assert.h>
      38             : }
      39             : 
      40             : using PHP::CodePointBreakIterator;
      41             : 
      42             : /* {{{ Global variables */
      43             : zend_class_entry *BreakIterator_ce_ptr;
      44             : zend_class_entry *RuleBasedBreakIterator_ce_ptr;
      45             : zend_class_entry *CodePointBreakIterator_ce_ptr;
      46             : zend_object_handlers BreakIterator_handlers;
      47             : /* }}} */
      48             : 
      49          40 : U_CFUNC void breakiterator_object_create(zval *object,
      50             :                                                                                  BreakIterator *biter, int brand_new TSRMLS_DC)
      51             : {
      52          40 :         UClassID classId = biter->getDynamicClassID();
      53             :         zend_class_entry *ce;
      54             : 
      55          40 :         if (classId == RuleBasedBreakIterator::getStaticClassID()) {
      56          35 :                 ce = RuleBasedBreakIterator_ce_ptr;
      57           5 :         } else if (classId == CodePointBreakIterator::getStaticClassID()) {
      58           5 :                 ce = CodePointBreakIterator_ce_ptr;
      59             :         } else {
      60           0 :                 ce = BreakIterator_ce_ptr;
      61             :         }
      62             : 
      63          40 :         if (brand_new) {
      64          29 :                 object_init_ex(object, ce);
      65             :         }
      66          40 :         breakiterator_object_construct(object, biter TSRMLS_CC);
      67          40 : }
      68             : 
      69          40 : U_CFUNC void breakiterator_object_construct(zval *object,
      70             :                                                                                         BreakIterator *biter TSRMLS_DC)
      71             : {
      72             :         BreakIterator_object *bio;
      73             : 
      74          40 :         BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; //populate to from object
      75             :         assert(bio->biter == NULL);
      76          40 :         bio->biter = biter;
      77          40 : }
      78             : 
      79             : /* {{{ compare handler for BreakIterator */
      80          14 : static int BreakIterator_compare_objects(zval *object1,
      81             :                                                                                  zval *object2 TSRMLS_DC)
      82             : {
      83             :         BreakIterator_object    *bio1,
      84             :                                                         *bio2;
      85             : 
      86          14 :         bio1 = Z_INTL_BREAKITERATOR_P(object1);
      87          14 :         bio2 = Z_INTL_BREAKITERATOR_P(object2);
      88             : 
      89          14 :         if (bio1->biter == NULL || bio2->biter == NULL) {
      90           0 :                 return bio1->biter == bio2->biter ? 0 : 1;
      91             :         }
      92             : 
      93          14 :         return *bio1->biter == *bio2->biter ? 0 : 1;
      94             : }
      95             : /* }}} */
      96             : 
      97             : /* {{{ clone handler for BreakIterator */
      98           3 : static zend_object *BreakIterator_clone_obj(zval *object TSRMLS_DC)
      99             : {
     100             :         BreakIterator_object    *bio_orig,
     101             :                                                         *bio_new;
     102             :         zend_object                             *ret_val;
     103             : 
     104           3 :         bio_orig = Z_INTL_BREAKITERATOR_P(object);
     105           3 :         intl_errors_reset(INTL_DATA_ERROR_P(bio_orig) TSRMLS_CC);
     106             : 
     107           3 :         ret_val = BreakIterator_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
     108           3 :         bio_new  = php_intl_breakiterator_fetch_object(ret_val);
     109             : 
     110           3 :         zend_objects_clone_members(&bio_new->zo, &bio_orig->zo TSRMLS_CC);
     111             : 
     112           3 :         if (bio_orig->biter != NULL) {
     113             :                 BreakIterator *new_biter;
     114             : 
     115           3 :                 new_biter = bio_orig->biter->clone();
     116           3 :                 if (!new_biter) {
     117             :                         zend_string *err_msg;
     118             :                         intl_errors_set_code(BREAKITER_ERROR_P(bio_orig),
     119           0 :                                 U_MEMORY_ALLOCATION_ERROR TSRMLS_CC);
     120             :                         intl_errors_set_custom_msg(BREAKITER_ERROR_P(bio_orig),
     121           0 :                                 "Could not clone BreakIterator", 0 TSRMLS_CC);
     122           0 :                         err_msg = intl_error_get_message(BREAKITER_ERROR_P(bio_orig) TSRMLS_CC);
     123           0 :                         zend_throw_exception(NULL, err_msg->val, 0 TSRMLS_CC);
     124             :                         zend_string_free(err_msg);
     125             :                 } else {
     126           3 :                         bio_new->biter = new_biter;
     127           3 :                         ZVAL_COPY(&bio_new->text, &bio_orig->text);
     128             :                 }
     129             :         } else {
     130           0 :                 zend_throw_exception(NULL, "Cannot clone unconstructed BreakIterator", 0 TSRMLS_CC);
     131             :         }
     132             : 
     133           3 :         return ret_val;
     134             : }
     135             : /* }}} */
     136             : 
     137             : /* {{{ get_debug_info handler for BreakIterator */
     138           0 : static HashTable *BreakIterator_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
     139             : {
     140             :         zval val;
     141             :         HashTable *debug_info;
     142             :         BreakIterator_object    *bio;
     143             :         const BreakIterator             *biter;
     144             : 
     145           0 :         *is_temp = 1;
     146             : 
     147           0 :         ALLOC_HASHTABLE(debug_info);
     148           0 :         zend_hash_init(debug_info, 8, NULL, ZVAL_PTR_DTOR, 0);
     149             : 
     150           0 :         bio  = Z_INTL_BREAKITERATOR_P(object);
     151           0 :         biter = bio->biter;
     152             : 
     153           0 :         if (biter == NULL) {
     154           0 :                 ZVAL_FALSE(&val);
     155           0 :                 zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &val);
     156           0 :                 return debug_info;
     157             :         }
     158           0 :         ZVAL_TRUE(&val);
     159           0 :         zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &val);
     160             : 
     161           0 :         if (Z_ISUNDEF(bio->text)) {
     162           0 :                 ZVAL_NULL(&val);
     163           0 :                 zend_hash_str_update(debug_info, "text", sizeof("text") - 1, &val);
     164             :         } else {
     165           0 :                 Z_TRY_ADDREF(bio->text);
     166           0 :                 zend_hash_str_update(debug_info, "text", sizeof("text") - 1, &bio->text);
     167             :         }
     168             : 
     169           0 :         ZVAL_STRING(&val, const_cast<char*>(typeid(*biter).name()));
     170           0 :         zend_hash_str_update(debug_info, "type", sizeof("type") - 1, &bio->text);
     171             : 
     172           0 :         return debug_info;
     173             : }
     174             : /* }}} */
     175             : 
     176             : /* {{{ void breakiterator_object_init(BreakIterator_object* to)
     177             :  * Initialize internals of BreakIterator_object not specific to zend standard objects.
     178             :  */
     179          44 : static void breakiterator_object_init(BreakIterator_object *bio TSRMLS_DC)
     180             : {
     181          44 :         intl_error_init(BREAKITER_ERROR_P(bio) TSRMLS_CC);
     182          44 :         bio->biter = NULL;
     183          44 :         ZVAL_UNDEF(&bio->text);
     184          44 : }
     185             : /* }}} */
     186             : 
     187             : /* {{{ BreakIterator_objects_dtor */
     188          43 : static void BreakIterator_objects_dtor(zend_object *object TSRMLS_DC)
     189             : {
     190          43 :         zend_objects_destroy_object(object TSRMLS_CC);
     191          43 : }
     192             : /* }}} */
     193             : 
     194             : /* {{{ BreakIterator_objects_free */
     195          44 : static void BreakIterator_objects_free(zend_object *object TSRMLS_DC)
     196             : {
     197          44 :         BreakIterator_object* bio = php_intl_breakiterator_fetch_object(object);
     198             : 
     199          44 :         zval_ptr_dtor(&bio->text);
     200          44 :         if (bio->biter) {
     201          43 :                 delete bio->biter;
     202          43 :                 bio->biter = NULL;
     203             :         }
     204          44 :         intl_error_reset(BREAKITER_ERROR_P(bio) TSRMLS_CC);
     205             : 
     206          44 :         zend_object_std_dtor(&bio->zo TSRMLS_CC);
     207          44 : }
     208             : /* }}} */
     209             : 
     210             : /* {{{ BreakIterator_object_create */
     211          44 : static zend_object *BreakIterator_object_create(zend_class_entry *ce TSRMLS_DC)
     212             : {
     213             :         BreakIterator_object*   intern;
     214             : 
     215          44 :         intern = (BreakIterator_object*)ecalloc(1, sizeof(BreakIterator_object) + sizeof(zval) * (ce->default_properties_count - 1));
     216             : 
     217          44 :         zend_object_std_init(&intern->zo, ce TSRMLS_CC);
     218          44 :     object_properties_init((zend_object*) intern, ce);
     219          44 :         breakiterator_object_init(intern TSRMLS_CC);
     220             : 
     221          44 :         intern->zo.handlers = &BreakIterator_handlers;
     222             : 
     223          44 :         return &intern->zo;
     224             : }
     225             : /* }}} */
     226             : 
     227             : /* {{{ BreakIterator/RuleBasedBreakIterator methods arguments info */
     228             : 
     229             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_void, 0, 0, 0)
     230             : ZEND_END_ARG_INFO()
     231             : 
     232             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_locale, 0, 0, 0)
     233             :         ZEND_ARG_INFO(0, locale)
     234             : ZEND_END_ARG_INFO()
     235             : 
     236             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_setText, 0, 0, 1)
     237             :         ZEND_ARG_INFO(0, text)
     238             : ZEND_END_ARG_INFO()
     239             : 
     240             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_next, 0, 0, 0)
     241             :         ZEND_ARG_INFO(0, offset)
     242             : ZEND_END_ARG_INFO()
     243             : 
     244             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_offset, 0, 0, 1)
     245             :         ZEND_ARG_INFO(0, offset)
     246             : ZEND_END_ARG_INFO()
     247             : 
     248             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_get_locale, 0, 0, 1)
     249             :         ZEND_ARG_INFO(0, locale_type)
     250             : ZEND_END_ARG_INFO()
     251             : 
     252             : ZEND_BEGIN_ARG_INFO_EX(ainfo_biter_getPartsIterator, 0, 0, 0)
     253             :         ZEND_ARG_INFO(0, key_type)
     254             : ZEND_END_ARG_INFO()
     255             : 
     256             : ZEND_BEGIN_ARG_INFO_EX(ainfo_rbbi___construct, 0, 0, 1)
     257             :         ZEND_ARG_INFO(0, rules)
     258             :         ZEND_ARG_INFO(0, areCompiled)
     259             : ZEND_END_ARG_INFO()
     260             : 
     261             : /* }}} */
     262             : 
     263             : /* {{{ BreakIterator_class_functions
     264             :  * Every 'BreakIterator' class method has an entry in this table
     265             :  */
     266             : static const zend_function_entry BreakIterator_class_functions[] = {
     267             :         PHP_ME(BreakIterator,                                   __construct,                                                    ainfo_biter_void,                                       ZEND_ACC_PRIVATE)
     268             :         PHP_ME_MAPPING(createWordInstance,              breakiter_create_word_instance,                 ainfo_biter_locale,                                     ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
     269             :         PHP_ME_MAPPING(createLineInstance,              breakiter_create_line_instance,                 ainfo_biter_locale,                                     ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
     270             :         PHP_ME_MAPPING(createCharacterInstance, breakiter_create_character_instance,    ainfo_biter_locale,                                     ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
     271             :         PHP_ME_MAPPING(createSentenceInstance,  breakiter_create_sentence_instance,             ainfo_biter_locale,                                     ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
     272             :         PHP_ME_MAPPING(createTitleInstance,             breakiter_create_title_instance,                ainfo_biter_locale,                                     ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
     273             :         PHP_ME_MAPPING(createCodePointInstance, breakiter_create_code_point_instance,   ainfo_biter_void,                                       ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
     274             :         PHP_ME_MAPPING(getText,                                 breakiter_get_text,                                             ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     275             :         PHP_ME_MAPPING(setText,                                 breakiter_set_text,                                             ainfo_biter_setText,                            ZEND_ACC_PUBLIC)
     276             :         PHP_ME_MAPPING(first,                                   breakiter_first,                                                ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     277             :         PHP_ME_MAPPING(last,                                    breakiter_last,                                                 ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     278             :         PHP_ME_MAPPING(previous,                                breakiter_previous,                                             ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     279             :         PHP_ME_MAPPING(next,                                    breakiter_next,                                                 ainfo_biter_next,                                       ZEND_ACC_PUBLIC)
     280             :         PHP_ME_MAPPING(current,                                 breakiter_current,                                              ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     281             :         PHP_ME_MAPPING(following,                               breakiter_following,                                    ainfo_biter_offset,                                     ZEND_ACC_PUBLIC)
     282             :         PHP_ME_MAPPING(preceding,                               breakiter_preceding,                                    ainfo_biter_offset,                                     ZEND_ACC_PUBLIC)
     283             :         PHP_ME_MAPPING(isBoundary,                              breakiter_is_boundary,                                  ainfo_biter_offset,                                     ZEND_ACC_PUBLIC)
     284             :         PHP_ME_MAPPING(getLocale,                               breakiter_get_locale,                                   ainfo_biter_get_locale,                         ZEND_ACC_PUBLIC)
     285             :         PHP_ME_MAPPING(getPartsIterator,                breakiter_get_parts_iterator,                   ainfo_biter_getPartsIterator,           ZEND_ACC_PUBLIC)
     286             : 
     287             :         PHP_ME_MAPPING(getErrorCode,                    breakiter_get_error_code,                               ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     288             :         PHP_ME_MAPPING(getErrorMessage,                 breakiter_get_error_message,                    ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     289             :         PHP_FE_END
     290             : };
     291             : /* }}} */
     292             : 
     293             : /* {{{ RuleBasedBreakIterator_class_functions
     294             :  */
     295             : static const zend_function_entry RuleBasedBreakIterator_class_functions[] = {
     296             :         PHP_ME(IntlRuleBasedBreakIterator,              __construct,                                                    ainfo_rbbi___construct,                         ZEND_ACC_PUBLIC)
     297             :         PHP_ME_MAPPING(getRules,                                rbbi_get_rules,                                                 ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     298             :         PHP_ME_MAPPING(getRuleStatus,                   rbbi_get_rule_status,                                   ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     299             :         PHP_ME_MAPPING(getRuleStatusVec,                rbbi_get_rule_status_vec,                               ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     300             : #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48
     301             :         PHP_ME_MAPPING(getBinaryRules,                  rbbi_get_binary_rules,                                  ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     302             : #endif
     303             :         PHP_FE_END
     304             : };
     305             : /* }}} */
     306             : 
     307             : /* {{{ CodePointBreakIterator_class_functions
     308             :  */
     309             : static const zend_function_entry CodePointBreakIterator_class_functions[] = {
     310             :         PHP_ME_MAPPING(getLastCodePoint,                cpbi_get_last_code_point,                               ainfo_biter_void,                                       ZEND_ACC_PUBLIC)
     311             :         PHP_FE_END
     312             : };
     313             : /* }}} */
     314             : 
     315             : 
     316             : /* {{{ breakiterator_register_BreakIterator_class
     317             :  * Initialize 'BreakIterator' class
     318             :  */
     319       20622 : U_CFUNC void breakiterator_register_BreakIterator_class(TSRMLS_D)
     320             : {
     321             :         zend_class_entry ce;
     322             : 
     323             :         /* Create and register 'BreakIterator' class. */
     324       20622 :         INIT_CLASS_ENTRY(ce, "IntlBreakIterator", BreakIterator_class_functions);
     325       20622 :         ce.create_object = BreakIterator_object_create;
     326       20622 :         ce.get_iterator = _breakiterator_get_iterator;
     327       20622 :         BreakIterator_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
     328             : 
     329             :         memcpy(&BreakIterator_handlers, zend_get_std_object_handlers(),
     330       20622 :                 sizeof BreakIterator_handlers);
     331       20622 :         BreakIterator_handlers.offset = XtOffsetOf(BreakIterator_object, zo);
     332       20622 :         BreakIterator_handlers.compare_objects = BreakIterator_compare_objects;
     333       20622 :         BreakIterator_handlers.clone_obj = BreakIterator_clone_obj;
     334       20622 :         BreakIterator_handlers.get_debug_info = BreakIterator_get_debug_info;
     335       20622 :         BreakIterator_handlers.dtor_obj = BreakIterator_objects_dtor;
     336       20622 :         BreakIterator_handlers.free_obj = BreakIterator_objects_free;
     337             : 
     338             :         zend_class_implements(BreakIterator_ce_ptr TSRMLS_CC, 1,
     339       20622 :                         zend_ce_traversable);
     340             : 
     341             :         zend_declare_class_constant_long(BreakIterator_ce_ptr,
     342       20622 :                 "DONE", sizeof("DONE") - 1, BreakIterator::DONE TSRMLS_CC );
     343             : 
     344             :         /* Declare constants that are defined in the C header */
     345             : #define BREAKITER_DECL_LONG_CONST(name) \
     346             :         zend_declare_class_constant_long(BreakIterator_ce_ptr, #name, \
     347             :                 sizeof(#name) - 1, UBRK_ ## name TSRMLS_CC)
     348             : 
     349       20622 :         BREAKITER_DECL_LONG_CONST(WORD_NONE);
     350       20622 :         BREAKITER_DECL_LONG_CONST(WORD_NONE_LIMIT);
     351       20622 :         BREAKITER_DECL_LONG_CONST(WORD_NUMBER);
     352       20622 :         BREAKITER_DECL_LONG_CONST(WORD_NUMBER_LIMIT);
     353       20622 :         BREAKITER_DECL_LONG_CONST(WORD_LETTER);
     354       20622 :         BREAKITER_DECL_LONG_CONST(WORD_LETTER_LIMIT);
     355       20622 :         BREAKITER_DECL_LONG_CONST(WORD_KANA);
     356       20622 :         BREAKITER_DECL_LONG_CONST(WORD_KANA_LIMIT);
     357       20622 :         BREAKITER_DECL_LONG_CONST(WORD_IDEO);
     358       20622 :         BREAKITER_DECL_LONG_CONST(WORD_IDEO_LIMIT);
     359             : 
     360       20622 :         BREAKITER_DECL_LONG_CONST(LINE_SOFT);
     361       20622 :         BREAKITER_DECL_LONG_CONST(LINE_SOFT_LIMIT);
     362       20622 :         BREAKITER_DECL_LONG_CONST(LINE_HARD);
     363       20622 :         BREAKITER_DECL_LONG_CONST(LINE_HARD_LIMIT);
     364             : 
     365       20622 :         BREAKITER_DECL_LONG_CONST(SENTENCE_TERM);
     366       20622 :         BREAKITER_DECL_LONG_CONST(SENTENCE_TERM_LIMIT);
     367       20622 :         BREAKITER_DECL_LONG_CONST(SENTENCE_SEP);
     368       20622 :         BREAKITER_DECL_LONG_CONST(SENTENCE_SEP_LIMIT);
     369             : 
     370             : #undef BREAKITER_DECL_LONG_CONST
     371             : 
     372             : 
     373             :         /* Create and register 'RuleBasedBreakIterator' class. */
     374       20622 :         INIT_CLASS_ENTRY(ce, "IntlRuleBasedBreakIterator",
     375             :                         RuleBasedBreakIterator_class_functions);
     376             :         RuleBasedBreakIterator_ce_ptr = zend_register_internal_class_ex(&ce,
     377       20622 :                         BreakIterator_ce_ptr TSRMLS_CC);
     378             : 
     379             :         /* Create and register 'CodePointBreakIterator' class. */
     380       20622 :         INIT_CLASS_ENTRY(ce, "IntlCodePointBreakIterator",
     381             :                         CodePointBreakIterator_class_functions);
     382             :         CodePointBreakIterator_ce_ptr = zend_register_internal_class_ex(&ce,
     383       20622 :                         BreakIterator_ce_ptr TSRMLS_CC);
     384       20622 : }
     385             : /* }}} */

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:14 +0000 (5 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.