summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-05-04 16:56:01 +0200
committerTyge Løvset <[email protected]>2022-05-04 16:56:01 +0200
commit691681356bf19ba112e7d332c07c986089ac16e4 (patch)
treed0c9931055bfd1de74ad45a649adfd1f412d9a56 /include
parent93aa7a0e68a1c5bc65feed583db27686e813bb2a (diff)
downloadSTC-modified-691681356bf19ba112e7d332c07c986089ac16e4.tar.gz
STC-modified-691681356bf19ba112e7d332c07c986089ac16e4.zip
Added c_find_if, c_find_it macros: linear search in containers. Removed c_apply_cnt macro.
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h18
-rw-r--r--include/stc/cregex.h2
2 files changed, 15 insertions, 5 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 6e4d9dff..d3749cf1 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -204,12 +204,22 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, size_t slen, cons
for (size_t index = 0, _c_n = n; index < _c_n; ++index) \
{ _c_T *v = _c_arr + index; action; } \
} while (0)
-#define c_apply_cnt(v, action, C, ...) do { \
+#define c_pair(v) (v).first, (v).second
+
+#define c_find_it(it, C, cnt, pred) do { \
size_t index = 0; \
- c_foreach (_it, C, __VA_ARGS__) \
- { C##_value* v = _it.ref; action; ++index; } \
+ C##_iter _end = C##_end(&cnt); \
+ for (it = C##_begin(&cnt); it.ref != _end.ref; C##_next(&it)) \
+ if (pred) break; else ++index; \
+} while (0)
+
+#define c_find_if(vp, C, cnt, pred) do { \
+ size_t index = 0; \
+ C##_iter _it, _end = C##_end(&cnt); \
+ for (_it = C##_begin(&cnt); _it.ref != _end.ref; C##_next(&_it)) \
+ if (vp = _it.ref, pred) break; else ++index; \
+ if (_it.ref == _end.ref) vp = NULL; \
} while (0)
-#define c_pair(v) (v).first, (v).second
#define c_drop(C, ...) do { \
C* _c_arr[] = {__VA_ARGS__}; \
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index 7357d9d9..0a4508b7 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -31,7 +31,7 @@ THE SOFTWARE.
* This is a extended version of regexp9, supporting UTF8 input, common
* shorthand character classes, ++.
*/
-#include "csview.h"
+#include "forward.h" // csview
typedef enum {
creg_nomatch = -1,