Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pcre.h"
- #include <stdio.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <errno.h>
- unsigned int filesize(const char *filename) {
- struct stat sb;
- if (stat(filename, &sb)) {
- printf("Stat error: %s\n", strerror(errno));
- return 0;
- }
- return sb.st_size;
- }
- int main() {
- char *regexp = "(?s)(?:\\pL+\\n){5000}";
- const char *error;
- int erroffset;
- pcre16 *re = pcre16_compile(
- (PCRE_SPTR16) regexp,
- PCRE_UTF16 | PCRE_UCP,
- &error,
- &erroffset,
- NULL
- );
- printf("PCRE version: %s\n", pcre16_version());
- if (!re) {
- printf("Compile error: %s\n", error);
- return 1;
- }
- char *filename = "utf16.txt";
- size_t size = filesize(filename);
- char *str = malloc(size + 1);
- FILE *fp = fopen(filename, "r");
- fread(str, sizeof(char), size, fp);
- fclose(fp);
- int match;
- int offsets[3];
- for (int i = 0; i<10; i++) {
- match = pcre16_exec(re, NULL, (PCRE_SPTR16) str, size, 0, 0, offsets, 3);
- printf(match == PCRE_ERROR_NOMATCH ? "No!\n" : "Yes!\n");
- }
- free(str);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement