Giter VIP home page Giter VIP logo

here's Introduction

Here

What is this?

Here or Libhere is a C-library which implements regular expressions in a simple and straightforward way.

"Here" is a sub-project from Hefesto project and it can be understood as Hefesto's Regular Expressions.

This library is not POSIX compliant because my main goal in this project is to keep the things simple and not bloated.

How to build here?

In order to build "here" you need to use Hefesto.

After you had Hefesto installed on your system just type hefesto. Being inside the libhere's src sub-directory. Something like:

root@moloko:~/here# cd src
root@moloko:~/here/src# hefesto

If all works a ".a" file will be within the src/lib sub-directory. Now you can use it to link the libhere against your projects.

How to use libhere within my code?

Basically libhere exposes for you functions for matching and replacing data.

If you need to match something, in general you should do:

(...)

#include <here.h>

(...)

here_search_program_ctx *search_program = NULL;
here_search_result_ctx *search_result = NULL;
char error_messages[4096];

(...)

search_program = here_compile(".*6655321.*", error_messages);

if (search_program == NULL) {
    //  If you don't want to know details about compilation errors
    //  just pass NULL instead of a message buffer to here_compile()
    //  function.
    printf("Regex compile ERROR: %s\n", error_messages);
    exit(1);
}

search_result = here_match_string(user_data_buffer, search_program);

if (here_matches(search_result)) {
    printf("Pattern found.\n");
    del_here_search_result_ctx(search_result);
}

del_here_search_program_ctx(search_program);

(...)

If you need to replace something you should do:

(...)

#include <here.h>

(...)

here_search_program_ctx *search_program = NULL;
here_search_result_ctx *search_result = NULL;
char *output = NULL;
size_t output_size = 0;
int replacements = 0;

(...)

search_program = here_compile("6655321", NULL);

if (search_program == NULL) {
    printf("The supplied regex has errors.\n");
    exit(1);
}

replacements = here_replace_string(user_data_buffer, search_program, "Alex", &output, &output_size);

if (replacements > 0) {
    printf("%d replacements had done -> %s\n", replacements, output);
}

del_here_search_program_ctx(search_program);

(...)

From here everything is simple! ;)

Enjoy!

here's People

Contributors

rafael-santiago avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.