LLVM OpenMP* Runtime Library
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
23extern "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
33struct 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
39typedef 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
49void __kmp_str_buf_clear(kmp_str_buf_t *buffer);
50void __kmp_str_buf_reserve(kmp_str_buf_t *buffer, size_t size);
51void __kmp_str_buf_detach(kmp_str_buf_t *buffer);
52void __kmp_str_buf_free(kmp_str_buf_t *buffer);
53void __kmp_str_buf_cat(kmp_str_buf_t *buffer, char const *str, size_t len);
54void __kmp_str_buf_catbuf(kmp_str_buf_t *dest, const kmp_str_buf_t *src);
55int __kmp_str_buf_vprint(kmp_str_buf_t *buffer, char const *format,
56 va_list args);
57int __kmp_str_buf_print(kmp_str_buf_t *buffer, char const *format, ...);
58void __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*/
68struct kmp_str_fname {
69 char *path;
70 char *dir;
71 char *base;
72}; // struct kmp_str_fname
73typedef struct kmp_str_fname kmp_str_fname_t;
74void __kmp_str_fname_init(kmp_str_fname_t *fname, char const *path);
75void __kmp_str_fname_free(kmp_str_fname_t *fname);
76// Compares file name with specified pattern. If pattern is NULL, any fname
77// matched.
78int __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*/
93struct 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
101typedef struct kmp_str_loc kmp_str_loc_t;
102kmp_str_loc_t __kmp_str_loc_init(char const *psource, bool init_fname);
103void __kmp_str_loc_numbers(char const *Psource, int *Line, int *Col);
104void __kmp_str_loc_free(kmp_str_loc_t *loc);
105
106int __kmp_str_eqf(char const *lhs, char const *rhs);
107char *__kmp_str_format(char const *format, ...);
108void __kmp_str_free(char **str);
109int __kmp_str_match(char const *target, int len, char const *data);
110bool __kmp_str_contains(char const *target, int len, char const *data);
111int __kmp_str_match_false(char const *data);
112int __kmp_str_match_true(char const *data);
113void __kmp_str_replace(char *str, char search_for, char replace_with);
114void __kmp_str_split(char *str, char delim, char **head, char **tail);
115char *__kmp_str_token(char *str, char const *delim, char **buf);
116int __kmp_basic_str_to_int(char const *str, size_t maxlen = SIZE_MAX);
117int __kmp_str_to_int(char const *str, char sentinel);
118
119void __kmp_str_to_size(char const *str, size_t *out, size_t dfactor,
120 char const **error);
121void __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 //