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: 24 35 68.6 %
Date: 2015-05-21 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(&res, &res_len,
      57             :  *              from.getBuffer(), from.length(), &status),
      58             :  * but consumes more memory */
      59          31 : int intl_charFromString(const UnicodeString &from, char **res, size_t *res_len, UErrorCode *status)
      60             : {
      61          31 :         if (from.isBogus()) {
      62           0 :                 return FAILURE;
      63             :         }
      64             : 
      65             :         //the number of UTF-8 code units is not larger than that of UTF-16 code
      66             :         //units * 3 + 1 for the terminator
      67          31 :         int32_t capacity = from.length() * 3 + 1;
      68             : 
      69          31 :         if (from.isEmpty()) {
      70           0 :                 *res = (char*)emalloc(1);
      71           0 :                 **res = '\0';
      72           0 :                 *res_len = 0;
      73           0 :                 return SUCCESS;
      74             :         }
      75             : 
      76          31 :         *res = (char*)emalloc(capacity);
      77          31 :         *res_len = 0; //tbd
      78             : 
      79          31 :         const UChar *utf16buf = from.getBuffer();
      80             :         int32_t actual_len;
      81             :         u_strToUTF8WithSub(*res, capacity - 1, &actual_len, utf16buf, from.length(),
      82          31 :                 U_SENTINEL, NULL, status);
      83             : 
      84          31 :         if (U_FAILURE(*status)) {
      85           0 :                 efree(*res);
      86           0 :                 *res = NULL;
      87           0 :                 return FAILURE;
      88             :         }
      89          31 :         (*res)[actual_len] = '\0';
      90          31 :         *res_len = actual_len;
      91             : 
      92          31 :         return SUCCESS;
      93             : }
      94             : /* }}} */

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:58:56 +0000 (2 days ago)

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