File: gb_find_dot.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (47 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//------------------------------------------------------------------------------
// gb_find_dot:  find the first two occurences of '.' in a string
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// s has the form 'plus.times.double' for a semiring, or 'plus.single' for a
// binary operator, or 'abs.int8' for a unary operator.  In all such cases, one
// or two dots ('.') must be found.  If no dots are found, position [0] and [1]
// are both -1.  If one dot is found, s [position [0]] == '.', and position [1]
// is -1.  If two dots are found, s [position [0]] == '.' is the first dot, and
// s [position [1]] == '.' is the second.

#include "gb_interface.h"

void gb_find_dot            // find 1st and 2nd dot ('.') in a string
(
    int32_t position [2],   // positions of one or two dots
    const char *s           // null-terminated string to search
)
{

    position [0] = -1 ;
    position [1] = -1 ;

    for (int32_t k = 0 ; s [k] != '\0' ; k++)
    {
        if (s [k] == '.')
        {
            if (position [0] == -1)
            { 
                // first dot has been found
                position [0] = k ;
            }
            else
            { 
                // 2nd dot has been found; the search is done
                position [1] = k ;
                return ;
            }
        }
    }
}