LCOV - code coverage report
Current view: top level - src/support - int2str.c (source / functions) Hit Total Coverage
Test: [build process] commit ef510b1f346f4c9f9d86eaceace5ca54961a1dbc Lines: 13 20 65.0 %
Date: 2022-07-17 01:01:28 Functions: 1 2 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 24 16.7 %

           Branch data     Line data    Source code
       1                 :            : // This file is a part of Julia. License is MIT: https://julialang.org/license
       2                 :            : 
       3                 :            : #include <stdlib.h>
       4                 :            : #include "dtypes.h"
       5                 :            : #include "utils.h"
       6                 :            : 
       7                 :            : #ifdef __cplusplus
       8                 :            : extern "C" {
       9                 :            : #endif
      10                 :            : 
      11                 :      61998 : char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base)
      12                 :            : {
      13                 :      61998 :     int i = len-1;
      14                 :      61998 :     uint64_t b = (uint64_t)base;
      15                 :            :     char ch;
      16                 :      61998 :     dest[i--] = '\0';
      17         [ +  - ]:     206680 :     while (i >= 0) {
      18                 :     206680 :         ch = (char)(num % b);
      19         [ +  - ]:     206680 :         if (ch < 10)
      20                 :     206680 :             ch += '0';
      21                 :            :         else
      22                 :          0 :             ch = ch-10+'a';
      23                 :     206680 :         dest[i--] = ch;
      24                 :     206680 :         num /= b;
      25         [ +  + ]:     206680 :         if (num == 0)
      26                 :      61998 :             break;
      27                 :            :     }
      28                 :      61998 :     return &dest[i+1];
      29                 :            : }
      30                 :            : 
      31                 :          0 : int isdigit_base(char c, int base)
      32                 :            : {
      33         [ #  # ]:          0 :     if (base < 11)
      34   [ #  #  #  # ]:          0 :         return (c >= '0' && c < '0'+base);
      35   [ #  #  #  # ]:          0 :     return ((c >= '0' && c <= '9') ||
      36   [ #  #  #  #  :          0 :             (c >= 'a' && c < 'a'+base-10) ||
                   #  # ]
      37         [ #  # ]:          0 :             (c >= 'A' && c < 'A'+base-10));
      38                 :            : }
      39                 :            : 
      40                 :            : /* assumes valid base, returns 1 on error, 0 if OK */
      41                 :            : /*
      42                 :            : int str2int(char *str, size_t len, int64_t *res, uint32_t base)
      43                 :            : {
      44                 :            :     int64_t result, place;
      45                 :            :     char digit;
      46                 :            :     int i;
      47                 :            : 
      48                 :            :     place = 1; result = 0;
      49                 :            :     for(i=len-1; i>=0; i--) {
      50                 :            :         digit = str[i];
      51                 :            :         if (!isdigit_base(digit, base))
      52                 :            :             return 1;
      53                 :            :         if (digit <= '9')
      54                 :            :             digit -= '0';
      55                 :            :         else if (digit >= 'a')
      56                 :            :             digit = digit-'a'+10;
      57                 :            :         else if (digit >= 'A')
      58                 :            :             digit = digit-'A'+10;
      59                 :            :         result += digit * place;
      60                 :            :         place *= base;
      61                 :            :     }
      62                 :            :     *res = result;
      63                 :            :     return 0;
      64                 :            : }
      65                 :            : */
      66                 :            : 
      67                 :            : #ifdef __cplusplus
      68                 :            : }
      69                 :            : #endif

Generated by: LCOV version 1.14