2 * kmp_str.h -- String manipulation routines.
5 //===----------------------------------------------------------------------===//
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
11 //===----------------------------------------------------------------------===//
26 #define strdup _strdup
29 /* some macros to replace ctype.h functions */
30 #define TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) + 'a' - 'A') : (c))
33 char *str
; // Pointer to buffer content, read only.
34 unsigned int size
; // Do not change this field!
35 int used
; // Number of characters printed to buffer, read only.
36 char bulk
[512]; // Do not use this field!
37 }; // struct kmp_str_buf
38 typedef struct kmp_str_buf kmp_str_buf_t
;
40 #define __kmp_str_buf_init(b) \
42 (b)->str = (b)->bulk; \
43 (b)->size = sizeof((b)->bulk); \
48 void __kmp_str_buf_clear(kmp_str_buf_t
*buffer
);
49 void __kmp_str_buf_reserve(kmp_str_buf_t
*buffer
, size_t size
);
50 void __kmp_str_buf_detach(kmp_str_buf_t
*buffer
);
51 void __kmp_str_buf_free(kmp_str_buf_t
*buffer
);
52 void __kmp_str_buf_cat(kmp_str_buf_t
*buffer
, char const *str
, size_t len
);
53 void __kmp_str_buf_catbuf(kmp_str_buf_t
*dest
, const kmp_str_buf_t
*src
);
54 int __kmp_str_buf_vprint(kmp_str_buf_t
*buffer
, char const *format
,
56 int __kmp_str_buf_print(kmp_str_buf_t
*buffer
, char const *format
, ...);
57 void __kmp_str_buf_print_size(kmp_str_buf_t
*buffer
, size_t size
);
62 kmp_str_fname_t fname = __kmp_str_fname_init( path );
63 // Use fname.path (copy of original path ), fname.dir, fname.base.
64 // Note fname.dir concatenated with fname.base gives exact copy of path.
65 __kmp_str_fname_free( & fname );
67 struct kmp_str_fname
{
71 }; // struct kmp_str_fname
72 typedef struct kmp_str_fname kmp_str_fname_t
;
73 void __kmp_str_fname_init(kmp_str_fname_t
*fname
, char const *path
);
74 void __kmp_str_fname_free(kmp_str_fname_t
*fname
);
75 // Compares file name with specified pattern. If pattern is NULL, any fname
77 int __kmp_str_fname_match(kmp_str_fname_t
const *fname
, char const *pattern
);
79 /* The compiler provides source locations in string form
80 ";file;func;line;col;;". It is not convenient for manipulation. This
81 structure keeps source location in more convenient form.
84 kmp_str_loc_t loc = __kmp_str_loc_init(ident->psource, false);
85 // use loc.file, loc.func, loc.line, loc.col.
86 // loc.fname is available if second argument of __kmp_str_loc_init is true.
87 __kmp_str_loc_free( & loc );
89 If psource is NULL or does not follow format above, file and/or func may be
93 char *_bulk
; // Do not use thid field.
94 kmp_str_fname_t fname
; // Will be initialized if init_fname is true.
99 }; // struct kmp_str_loc
100 typedef struct kmp_str_loc kmp_str_loc_t
;
101 kmp_str_loc_t
__kmp_str_loc_init(char const *psource
, bool init_fname
);
102 void __kmp_str_loc_numbers(char const *Psource
, int *Line
, int *Col
);
103 void __kmp_str_loc_free(kmp_str_loc_t
*loc
);
105 int __kmp_str_eqf(char const *lhs
, char const *rhs
);
106 char *__kmp_str_format(char const *format
, ...);
107 void __kmp_str_free(char **str
);
108 int __kmp_str_match(char const *target
, int len
, char const *data
);
109 bool __kmp_str_contains(char const *target
, int len
, char const *data
);
110 int __kmp_str_match_false(char const *data
);
111 int __kmp_str_match_true(char const *data
);
112 void __kmp_str_replace(char *str
, char search_for
, char replace_with
);
113 void __kmp_str_split(char *str
, char delim
, char **head
, char **tail
);
114 char *__kmp_str_token(char *str
, char const *delim
, char **buf
);
115 int __kmp_basic_str_to_int(char const *str
);
116 int __kmp_str_to_int(char const *str
, char sentinel
);
118 void __kmp_str_to_size(char const *str
, size_t *out
, size_t dfactor
,
120 void __kmp_str_to_uint(char const *str
, kmp_uint64
*out
, char const **error
);
124 #endif // __cplusplus