Giter Club home page Giter Club logo

Comments (4)

kokke avatar kokke commented on July 28, 2024

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:

  1. either put it in a C++ header with the extern C { ... } tag wrapped around the contents of the C-header
  2. 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.

blitz-research avatar blitz-research commented on July 28, 2024

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.

blitz-research avatar blitz-research commented on July 28, 2024

...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.

kokke avatar kokke commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.