From 57ff3c9267f6d79aabf44c435ac886e2ecd8bbbe Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 10 Jan 2020 10:55:12 +0800 Subject: [PATCH] add __mg_get_extension and __mg_extract_integers --- src/include/misc.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/include/misc.h b/src/include/misc.h index f559842f..016610f7 100644 --- a/src/include/misc.h +++ b/src/include/misc.h @@ -72,8 +72,9 @@ struct timezone { #include #endif -/* Function definitions */ +#include // for strrchr +/* Function definitions */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -114,6 +115,20 @@ BOOL __mg_is_abs_path (const char* path); int __mg_path_joint (char* dst, int dst_size, const char* abs_path, const char* sub_path); +/* Since 4.2.0 */ +static inline +const char* __mg_get_extension (const char* filename) { + const char* ext; + ext = strrchr (filename, '.'); + if (ext) + return ext + 1; + return NULL; +} + +// Extract integers in pattern like "100x100" or "100,100", and returns +// the number of integers extracted successfully. +int __mg_extract_integers (const char* s, int c, int* ab, int max_nr); + /* Since 4.2.0 */ #ifndef __NOUNIX__ int __mg_create_anonymous_file (off_t size, const char* debug_name,