Created
October 2, 2018 19:20
-
-
Save lopex/0c17f3c7d4e291790c8b8429bd109389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <onigmo.h> | |
#define SLEN(s) strlen(s) | |
static OnigRegion region; | |
int main() { | |
int r; | |
static regex_t* reg; | |
OnigErrorInfo einfo; | |
char buf[1000]; | |
int option = ONIG_OPTION_DEFAULT; // ONIG_OPTION_NEGATE_SINGLELINE; //; // ONIG_OPTION_NONE; | |
char*pattern = "\\=\\?"; | |
const char*str = "💌"; | |
printf("PATTERN: '%s'\n", pattern); | |
printf("STRING: '%s'\n", str); | |
r = onig_new(®, pattern, (pattern + SLEN(pattern)), ONIG_OPTION_IGNORECASE, ONIG_ENCODING_UTF8, ONIG_SYNTAX_RUBY, &einfo); | |
if (r) { | |
char s[ONIG_MAX_ERROR_MESSAGE_LEN]; | |
onig_error_code_to_str((UChar* )s, r, &einfo); | |
printf("COMPILE ERROR: %s\n", s); | |
return 0; | |
} | |
r = onig_search(reg, str, (str + SLEN(str)), str, (str + SLEN(str)), ®ion, ONIG_OPTION_NONE); | |
if (r < ONIG_MISMATCH) { | |
char s[ONIG_MAX_ERROR_MESSAGE_LEN]; | |
onig_error_code_to_str((UChar* )s, r); | |
printf("ERROR: %s\n", s); | |
return 0; | |
} | |
printf("MATCH: %d\n", r); | |
printf("REGISTERS: %d\n", region.num_regs); | |
int i; | |
for(i = 0; i < region.num_regs; i++) { | |
strncpy(buf, str + region.beg[i], region.end[i] - region.beg[i]); | |
buf[region.end[i] - region.beg[i]] = 0; | |
printf(" NR %d - (%d, %d) - '%s'\n", i, region.beg[i], region.end[i], buf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment