LCOV - code coverage report
Current view: top level - src/regex - util.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 36 11.1 %
Date: 2016-12-21 02:12:01 Functions: 1 5 20.0 %

          Line data    Source code
       1             : /***************************************************************************//**
       2             : 
       3             :   @file         util.c
       4             : 
       5             :   @author       Stephen Brennan
       6             : 
       7             :   @date         Created Sunday, 29 May 2016
       8             : 
       9             :   @brief        Regex handling utilities.
      10             : 
      11             :   @copyright    Copyright (c) 2016, Stephen Brennan.  Released under the
      12             :                 Revised BSD License.  See LICENSE.txt for details.
      13             : 
      14             : *******************************************************************************/
      15             : 
      16             : #include <string.h>
      17             : 
      18             : #include "libstephen/re.h"
      19             : #include "libstephen/re_internals.h"
      20             : 
      21           0 : Captures recap(const char *s, const size_t *l, size_t n)
      22             : {
      23             :   Captures c;
      24           0 :   c.n = n/2;
      25           0 :   c.cap = calloc(c.n, sizeof(char *));
      26           0 :   for (size_t i = 0; i < n / 2; i++) {
      27           0 :     size_t start = l[i*2];
      28           0 :     size_t end = l[i*2 + 1];
      29           0 :     size_t length = end - start + 1;
      30           0 :     c.cap[i] = malloc(end - start + 1);
      31           0 :     strncpy(c.cap[i], s + start, length);
      32           0 :     c.cap[i][length-1] = '\0';
      33             :   }
      34           0 :   return c;
      35             : }
      36             : 
      37           0 : void recapfree(Captures c)
      38             : {
      39           0 :   for (size_t i = 0; i < c.n; i++) {
      40           0 :     free(c.cap[i]);
      41             :   }
      42           0 :   free(c.cap);
      43           0 : }
      44             : 
      45           0 : WCaptures recapw(const wchar_t *s, const size_t *l, size_t n)
      46             : {
      47             :   WCaptures c;
      48           0 :   c.n = n/2;
      49           0 :   c.cap = calloc(c.n, sizeof(wchar_t *));
      50           0 :   for (size_t i = 0; i < n / 2; i++) {
      51           0 :     size_t start = l[i*2];
      52           0 :     size_t end = l[i*2 + 1];
      53           0 :     size_t length = end - start + 1;
      54           0 :     c.cap[i] = malloc((end - start + 1) * sizeof(wchar_t));
      55           0 :     wcsncpy(c.cap[i], s + start, length);
      56           0 :     c.cap[i][length-1] = '\0';
      57             :   }
      58           0 :   return c;
      59             : }
      60             : 
      61           0 : void recapwfree(WCaptures c)
      62             : {
      63           0 :   for (size_t i = 0; i < c.n; i++) {
      64           0 :     free(c.cap[i]);
      65             :   }
      66           0 :   free(c.cap);
      67           0 : }
      68             : 
      69         837 : wchar_t InputIdx(struct Input in, size_t idx)
      70             : {
      71         837 :   if (in.str) {
      72         479 :     return (wchar_t)in.str[idx];
      73             :   } else {
      74         358 :     return in.wstr[idx];
      75             :   }
      76             : }

Generated by: LCOV version 1.11