LTP GCOV extension - code coverage report
Current view: directory - TSRM - tsrm_strtok_r.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 21
Code covered: 100.0 % Executed lines: 21
Legend: not executed executed

       1                 : #include <stdio.h>
       2                 : 
       3                 : #include "tsrm_config_common.h"
       4                 : #include "tsrm_strtok_r.h"
       5                 : 
       6                 : static inline int in_character_class(char ch, const char *delim)
       7           14254 : {
       8           41093 :         while (*delim) {
       9           14254 :                 if (*delim == ch) {
      10            1669 :                         return 1;
      11                 :                 }
      12           12585 :                 delim++;
      13                 :         }
      14           12585 :         return 0;
      15                 : }
      16                 : 
      17                 : char *tsrm_strtok_r(char *s, const char *delim, char **last)
      18            1908 : {
      19                 :         char *token;
      20                 : 
      21            1908 :         if (s == NULL) {
      22            1669 :                 s = *last;
      23                 :         }
      24                 : 
      25            4055 :         while (*s && in_character_class(*s, delim)) {
      26             239 :                 s++;
      27                 :         }
      28            1908 :         if (!*s) {
      29             239 :                 return NULL;
      30                 :         }
      31                 : 
      32            1669 :         token = s;
      33                 : 
      34           14254 :         while (*s && !in_character_class(*s, delim)) {
      35           10916 :                 s++;
      36                 :         }
      37            1669 :         if (!*s) {
      38             239 :                 *last = s;
      39                 :         } else {
      40            1430 :                 *s = '\0';
      41            1430 :                 *last = s + 1;
      42                 :         }
      43            1669 :         return token;
      44                 : }
      45                 : 
      46                 : #if 0
      47                 : 
      48                 : main()
      49                 : {
      50                 :         char foo[] = "/foo/bar//\\barbara";
      51                 :         char *last;
      52                 :         char *token;
      53                 : 
      54                 :         token = tsrm_strtok_r(foo, "/\\", &last);
      55                 :         while (token) {
      56                 :                 printf ("Token = '%s'\n", token);
      57                 :                 token = tsrm_strtok_r(NULL, "/\\", &last);
      58                 :         }
      59                 :         
      60                 :         return 0;
      61                 : }
      62                 : 
      63                 : #endif

Generated by: LTP GCOV extension version 1.5