summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/regex1.c
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-12-20 23:31:51 +0100
committerTyge Lovset <[email protected]>2022-12-20 23:31:51 +0100
commit5f57d597cd27aef55adbcb3b452973b0c6e33667 (patch)
treedfd59c2fd0e36a6ef37912a9d0cc5a65970f1524 /misc/examples/regex1.c
parent1763be8c8cbbc0896477fcf924edd4180d1345a9 (diff)
downloadSTC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.tar.gz
STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.zip
Restructured folders: examples, benchmarks, tests into misc folder.
Diffstat (limited to 'misc/examples/regex1.c')
-rw-r--r--misc/examples/regex1.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/misc/examples/regex1.c b/misc/examples/regex1.c
new file mode 100644
index 00000000..7a22220d
--- /dev/null
+++ b/misc/examples/regex1.c
@@ -0,0 +1,30 @@
+#define i_extern
+#include <stc/cregex.h>
+
+int main(int argc, char* argv[])
+{
+ if (argc <= 1) {
+ printf("Usage: regex1 -i\n");
+ return 0;
+ }
+ c_auto (cstr, input)
+ c_auto (cregex, float_expr)
+ {
+ int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$", CREG_DEFAULT);
+ // Until "q" is given, ask for another number
+ if (res > 0) while (true)
+ {
+ printf("Enter a double precision number (q for quit): ");
+ cstr_getline(&input, stdin);
+
+ // Exit when the user inputs q
+ if (cstr_equals(&input, "q"))
+ break;
+
+ if (cregex_is_match(&float_expr, cstr_str(&input)))
+ printf("Input is a float\n");
+ else
+ printf("Invalid input : Not a float\n");
+ }
+ }
+}