cloudflight
2023-12-26 5fa6947054206e2e781eadd4effdcdf52eda28c4
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
48
49
50
51
52
53
54
55
56
57
58
59
/*
 ******************************************************************************
 Project:      OWA EPANET
 Version:      2.2
 Module:       util/cstr_helper.c
 Description:  Provides C string helper functions
 Authors:      see AUTHORS
 Copyright:    see AUTHORS
 License:      see LICENSE
 Last Updated: 04/02/2019
 ******************************************************************************
*/
 
#include <stdlib.h>
#include <string.h>
 
#include "cstr_helper.h"
 
 
int cstr_duplicate(char **dest, const char *source)
// Duplicates source string
{
    size_t size = 1 + strlen(source);
    *dest = (char *) calloc(size, sizeof(char));
 
    if (*dest == NULL)
        return -1;
    else {
#ifdef _MSC_VER
        strncpy_s(*dest, size, source, size);
#else
        strncpy(*dest, source, size);
#endif
    }
    return 0;
}
 
 
bool cstr_isvalid(const char *element_id)
// Determines if invalid characters are present in an element id string
{
    const char *invalid_chars = " \";";
 
    // if invalid char is present a pointer to it is returned else NULL
    if (strpbrk(element_id, invalid_chars))
        return false;
    else
        return true;
}
 
 
bool cstr_isnullterm(const char *source)
// Determines if the string passed is null terminated or not
{
    if (strchr(source, '\0'))
        return true;
    else
        return false;
}