Comments (4)
Hi @blitz-research , thanks for your kind words :)
Oh, I haven't mixed C and C++ in a few years, so I hadn't been aware of that issue - thanks for mentioning it :)
Yeah I would have to do that to avoid trouble with the name mangling right?
Or could I require the user to know that the library is written in C, and then do one of two:
- either put it in a C++ header with the
extern C { ... }
tag wrapped around the contents of the C-header - or put the
extern
-stuff before#include
'ing the C-header
What do you think? Would any of those options work for C++? I'm online from my phone right now, so no easy way to test it at the moment..
from tiny-regex-c.
Just add the #ifdefs to the existing re.h file. C compilers will ignore them because __cplusplus wont be defined, and c++ compilers will know not to mangle the names because of the extern"C".
Here's my re.h which builds fine with my c++ code. Would've done a pull request except I suck at git.
/*
*
* Mini regex-module inspired by Rob Pike's regex code described in:
*
* http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
*
*
*
* Supports:
* ---------
* '.' Dot, matches any character
* '^' Start anchor, matches beginning of string
* '$' End anchor, matches end of string
* '*' Asterisk, match zero or more (greedy)
* '+' Plus, match one or more (greedy)
* '?' Question, match zero or one (non-greedy)
* '[abc]' Character class, match if one of {'a', 'b', 'c'}
* '[^abc]' Inverted class, match if NOT one of {'a', 'b', 'c'} -- NOTE: feature is currently broken!
* '[a-zA-Z]' Character ranges, the character set of the ranges { a-z | A-Z }
* '\s' Whitespace, \t \f \r \n \v and spaces
* '\S' Non-whitespace
* '\w' Alphanumeric, [a-zA-Z0-9_]
* '\W' Non-alphanumeric
* '\d' Digits, [0-9]
* '\D' Non-digits
*
*
*/
#ifdef __cplusplus
extern "C"{
#endif
/* Typedef'd pointer to get abstract datatype. */
typedef struct regex_t* re_t;
/* Compile regex string pattern to a regex_t-array. */
re_t re_compile(const char* pattern);
/* Find matches of the compiled pattern inside text. */
int re_matchp(re_t pattern, const char* text);
/* Find matches of the txt pattern inside text (will compile automatically first). */
int re_match(const char* pattern, const char* text);
#ifdef __cplusplus
}
#endif
from tiny-regex-c.
...might also want to add an include guard, but it's such a small file it probably wouldn't be any faster!
from tiny-regex-c.
Yeah that is just the best solution :)
I've added the #ifdef
-guard in the header - try pulling
from tiny-regex-c.
Related Issues (20)
- Understand metacharacters and escape character HOT 4
- Prevent duplicate include errors HOT 3
- Two minor overflows in re_compile HOT 19
- Could not search for '.' HOT 1
- matchlen may be wrong HOT 5
- Incorrect results for repeat operators HOT 3
- I ported this to rust HOT 1
- Add Precompiled Regex Code Generator HOT 4
- Python random tests are failing but CI is passing
- regex compilation is making things slower? HOT 1
- support for non-greedy `*?` and `+?`
- Wrong match length? HOT 3
- Error on isdigit, isalpha, isspace with char > 127
- re_matchp succeeds only for the first string compared to a pattern HOT 1
- vcpkg installion windows - length is not changing in return
- support for {n,m},repeat N to M times? HOT 1
- Software vulnerabilities detected during code analysis with ESBMC-WR tool HOT 1
- fix pattern '[1-5-]+' against '123-'
- Do not support {n, m} feature. HOT 1
- Not only does [^blah] not work but the non-inverted [blah] doesn't work either HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tiny-regex-c.