LLVM OpenMP* Runtime Library
Toggle main menu visibility
Loading...
Searching...
No Matches
src
kmp_str.h
1
/*
2
* kmp_str.h -- String manipulation routines.
3
*/
4
5
//===----------------------------------------------------------------------===//
6
//
7
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8
// See https://llvm.org/LICENSE.txt for license information.
9
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef KMP_STR_H
14
#define KMP_STR_H
15
16
#include <limits.h>
17
#include <stdarg.h>
18
#include <string.h>
19
20
#include "kmp_os.h"
21
22
#ifdef __cplusplus
23
extern
"C"
{
24
#endif
// __cplusplus
25
26
#if KMP_OS_WINDOWS
27
#define strdup _strdup
28
#endif
29
30
/* some macros to replace ctype.h functions */
31
#define TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) + 'a' - 'A') : (c))
32
33
struct
kmp_str_buf {
34
char
*str;
// Pointer to buffer content, read only.
35
unsigned
int
size;
// Do not change this field!
36
int
used;
// Number of characters printed to buffer, read only.
37
char
bulk[512];
// Do not use this field!
38
};
// struct kmp_str_buf
39
typedef
struct
kmp_str_buf kmp_str_buf_t;
40
41
#define __kmp_str_buf_init(b) \
42
{ \
43
(b)->str = (b)->bulk; \
44
(b)->size = sizeof((b)->bulk); \
45
(b)->used = 0; \
46
(b)->bulk[0] = 0; \
47
}
48
49
void
__kmp_str_buf_clear(kmp_str_buf_t *buffer);
50
void
__kmp_str_buf_reserve(kmp_str_buf_t *buffer,
size_t
size);
51
void
__kmp_str_buf_detach(kmp_str_buf_t *buffer);
52
void
__kmp_str_buf_free(kmp_str_buf_t *buffer);
53
void
__kmp_str_buf_cat(kmp_str_buf_t *buffer,
char
const
*str,
size_t
len);
54
void
__kmp_str_buf_catbuf(kmp_str_buf_t *dest,
const
kmp_str_buf_t *src);
55
int
__kmp_str_buf_vprint(kmp_str_buf_t *buffer,
char
const
*format,
56
va_list args);
57
int
__kmp_str_buf_print(kmp_str_buf_t *buffer,
char
const
*format, ...);
58
void
__kmp_str_buf_print_size(kmp_str_buf_t *buffer,
size_t
size);
59
60
/* File name parser.
61
Usage:
62
63
kmp_str_fname_t fname = __kmp_str_fname_init( path );
64
// Use fname.path (copy of original path ), fname.dir, fname.base.
65
// Note fname.dir concatenated with fname.base gives exact copy of path.
66
__kmp_str_fname_free( & fname );
67
*/
68
struct
kmp_str_fname {
69
char
*path;
70
char
*dir;
71
char
*base;
72
};
// struct kmp_str_fname
73
typedef
struct
kmp_str_fname kmp_str_fname_t;
74
void
__kmp_str_fname_init(kmp_str_fname_t *fname,
char
const
*path);
75
void
__kmp_str_fname_free(kmp_str_fname_t *fname);
76
// Compares file name with specified pattern. If pattern is NULL, any fname
77
// matched.
78
int
__kmp_str_fname_match(kmp_str_fname_t
const
*fname,
char
const
*pattern);
79
80
/* The compiler provides source locations in string form
81
";file;func;line;col;;". It is not convenient for manipulation. This
82
structure keeps source location in more convenient form.
83
Usage:
84
85
kmp_str_loc_t loc = __kmp_str_loc_init(ident->psource, false);
86
// use loc.file, loc.func, loc.line, loc.col.
87
// loc.fname is available if second argument of __kmp_str_loc_init is true.
88
__kmp_str_loc_free( & loc );
89
90
If psource is NULL or does not follow format above, file and/or func may be
91
NULL pointers.
92
*/
93
struct
kmp_str_loc {
94
char
*_bulk;
// Do not use thid field.
95
kmp_str_fname_t fname;
// Will be initialized if init_fname is true.
96
char
*file;
97
char
*func;
98
int
line;
99
int
col;
100
};
// struct kmp_str_loc
101
typedef
struct
kmp_str_loc kmp_str_loc_t;
102
kmp_str_loc_t __kmp_str_loc_init(
char
const
*psource,
bool
init_fname);
103
void
__kmp_str_loc_numbers(
char
const
*Psource,
int
*Line,
int
*Col);
104
void
__kmp_str_loc_free(kmp_str_loc_t *loc);
105
106
int
__kmp_str_eqf(
char
const
*lhs,
char
const
*rhs);
107
char
*__kmp_str_format(
char
const
*format, ...);
108
void
__kmp_str_free(
char
**str);
109
int
__kmp_str_match(
char
const
*target,
int
len,
char
const
*data);
110
bool
__kmp_str_contains(
char
const
*target,
int
len,
char
const
*data);
111
int
__kmp_str_match_false(
char
const
*data);
112
int
__kmp_str_match_true(
char
const
*data);
113
void
__kmp_str_replace(
char
*str,
char
search_for,
char
replace_with);
114
void
__kmp_str_split(
char
*str,
char
delim,
char
**head,
char
**tail);
115
char
*__kmp_str_token(
char
*str,
char
const
*delim,
char
**buf);
116
int
__kmp_basic_str_to_int(
char
const
*str,
size_t
maxlen = SIZE_MAX);
117
int
__kmp_str_to_int(
char
const
*str,
char
sentinel);
118
119
void
__kmp_str_to_size(
char
const
*str,
size_t
*out,
size_t
dfactor,
120
char
const
**error);
121
void
__kmp_str_to_uint(
char
const
*str, kmp_uint64 *out,
char
const
**error);
122
123
#ifdef __cplusplus
124
}
// extern "C"
125
#endif
// __cplusplus
126
127
#endif
// KMP_STR_H
128
129
// end of file //
Generated by
1.17.0