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 - intl_convertcpp.cpp (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 23 29 79.3 %
Date: 2015-08-29 Functions: 2 2 100.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             : /* $Id$ */
      18             : 
      19             : #include "intl_cppshims.h"
      20             : 
      21             : #include "intl_convertcpp.h"
      22             : #include <unicode/ustring.h>
      23             : extern "C" {
      24             : #include <php.h>
      25             : }
      26             : 
      27             : /* {{{ intl_stringFromChar */
      28         491 : int intl_stringFromChar(UnicodeString &ret, char *str, size_t str_len, UErrorCode *status)
      29             : {
      30         491 :         if(str_len > INT32_MAX) {
      31           0 :                 *status = U_BUFFER_OVERFLOW_ERROR;
      32           0 :                 ret.setToBogus();
      33           0 :                 return FAILURE;
      34             :         }
      35             :         //the number of UTF-16 code units is not larger than that of UTF-8 code
      36             :         //units, + 1 for the terminator
      37         491 :         int32_t capacity = (int32_t)str_len + 1;
      38             : 
      39             :         //no check necessary -- if NULL will fail ahead
      40         491 :         UChar   *utf16 = ret.getBuffer(capacity);
      41         491 :         int32_t utf16_len = 0;
      42         491 :         *status = U_ZERO_ERROR;
      43             :         u_strFromUTF8WithSub(utf16, ret.getCapacity(), &utf16_len,
      44             :                 str, str_len, U_SENTINEL /* no substitution */, NULL,
      45         491 :                 status);
      46         491 :         ret.releaseBuffer(utf16_len);
      47         491 :         if (U_FAILURE(*status)) {
      48           5 :                 ret.setToBogus();
      49           5 :                 return FAILURE;
      50             :         }
      51         486 :         return SUCCESS;
      52             : }
      53             : /* }}} */
      54             : 
      55             : /* {{{ intl_charFromString
      56             :  * faster than doing intl_convert_utf16_to_utf8(
      57             :  *              from.getBuffer(), from.length(), &status),
      58             :  * but consumes more memory */
      59          31 : zend_string* intl_charFromString(const UnicodeString &from, UErrorCode *status)
      60             : {
      61             :         zend_string *u8res;
      62             : 
      63          31 :         if (from.isBogus()) {
      64           0 :                 return NULL;
      65             :         }
      66             : 
      67             :         //the number of UTF-8 code units is not larger than that of UTF-16 code
      68             :         //units * 3
      69          31 :         int32_t capacity = from.length() * 3;
      70             : 
      71          31 :         if (from.isEmpty()) {
      72           0 :                 return ZSTR_EMPTY_ALLOC();
      73             :         }
      74             : 
      75          62 :         u8res = zend_string_alloc(capacity, 0);
      76             : 
      77          31 :         const UChar *utf16buf = from.getBuffer();
      78             :         int32_t actual_len;
      79             :         u_strToUTF8WithSub(ZSTR_VAL(u8res), capacity, &actual_len, utf16buf, from.length(),
      80          31 :                 U_SENTINEL, NULL, status);
      81             : 
      82          31 :         if (U_FAILURE(*status)) {
      83             :                 zend_string_free(u8res);
      84           0 :                 return NULL;
      85             :         }
      86          31 :         ZSTR_VAL(u8res)[actual_len] = '\0';
      87          31 :         ZSTR_LEN(u8res) = actual_len;
      88             : 
      89          31 :         return u8res;
      90             : }
      91             : /* }}} */

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:15 +0000 (2 days ago)

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