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 31 74.2 %
Date: 2014-08-04 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       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         493 : int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCode *status)
      29             : {
      30             :         //the number of UTF-16 code units is not larger than that of UTF-8 code
      31             :         //units, + 1 for the terminator
      32         493 :         int32_t capacity = str_len + 1;
      33             : 
      34             :         //no check necessary -- if NULL will fail ahead
      35         493 :         UChar   *utf16 = ret.getBuffer(capacity);
      36         493 :         int32_t utf16_len = 0;
      37         493 :         *status = U_ZERO_ERROR;
      38             :         u_strFromUTF8WithSub(utf16, ret.getCapacity(), &utf16_len,
      39             :                 str, str_len, U_SENTINEL /* no substitution */, NULL,
      40         493 :                 status);
      41         493 :         ret.releaseBuffer(utf16_len);
      42         493 :         if (U_FAILURE(*status)) {
      43           5 :                 ret.setToBogus();
      44           5 :                 return FAILURE;
      45             :         }
      46         488 :         return SUCCESS;
      47             : }
      48             : /* }}} */
      49             : 
      50             : /* {{{ intl_charFromString
      51             :  * faster than doing intl_convert_utf16_to_utf8(&res, &res_len,
      52             :  *              from.getBuffer(), from.length(), &status),
      53             :  * but consumes more memory */
      54          31 : int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status)
      55             : {
      56          31 :         if (from.isBogus()) {
      57           0 :                 return FAILURE;
      58             :         }
      59             : 
      60             :         //the number of UTF-8 code units is not larger than that of UTF-16 code
      61             :         //units * 3 + 1 for the terminator
      62          31 :         int32_t capacity = from.length() * 3 + 1;
      63             : 
      64          31 :         if (from.isEmpty()) {
      65           0 :                 *res = (char*)emalloc(1);
      66           0 :                 **res = '\0';
      67           0 :                 *res_len = 0;
      68           0 :                 return SUCCESS;
      69             :         }
      70             : 
      71          31 :         *res = (char*)emalloc(capacity);
      72          31 :         *res_len = 0; //tbd
      73             : 
      74          31 :         const UChar *utf16buf = from.getBuffer();
      75             :         int32_t actual_len;
      76             :         u_strToUTF8WithSub(*res, capacity - 1, &actual_len, utf16buf, from.length(),
      77          31 :                 U_SENTINEL, NULL, status);
      78             : 
      79          31 :         if (U_FAILURE(*status)) {
      80           0 :                 efree(*res);
      81           0 :                 *res = NULL;
      82           0 :                 return FAILURE;
      83             :         }
      84          31 :         (*res)[actual_len] = '\0';
      85          31 :         *res_len = (int)actual_len;
      86             :         
      87          31 :         return SUCCESS;
      88             : }
      89             : /* }}} */

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:05 +0000 (18 days ago)

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