Giter Club home page Giter Club logo

Comments (8)

kkos avatar kkos commented on July 24, 2024

I can't read the subject string.
If the subject string is "## in expression ##", the pattern match it.

kosako@VirtualBox:~/tmp$ gcc -Wall a.c -o a -lonig
kosako@VirtualBox:~/tmp$ ./a
match at 0
0: (0-3)
1: (0-2)
#include <stdio.h>
#include <string.h>
#include "oniguruma.h"

extern int main(int argc, char* argv[])
{
  int r;
  unsigned char *start, *range, *end;
  regex_t* reg;
  OnigErrorInfo einfo;
  OnigRegion *region;

  static UChar* pattern = (UChar* )"(?:^|\\G)(#{1,6})\\s*(?=[\\S[^#]])";
  static UChar* str     = (UChar* )"## in expression ##";
  //static UChar* str     = (UChar* )"##";

  r = onig_new(&reg, pattern, pattern + strlen((char* )pattern),
	ONIG_OPTION_DEFAULT, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
  if (r != ONIG_NORMAL) {
    char s[ONIG_MAX_ERROR_MESSAGE_LEN];
    onig_error_code_to_str(s, r, &einfo);
    fprintf(stderr, "ERROR: %s\n", s);
    return -1;
  }

  region = onig_region_new();

  end   = str + strlen((char* )str);
  start = str;
  range = end;
  r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE);
  if (r >= 0) {
    int i;

    fprintf(stderr, "match at %d\n", r);
    for (i = 0; i < region->num_regs; i++) {
      fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]);
    }
  }
  else if (r == ONIG_MISMATCH) {
    fprintf(stderr, "search fail\n");
  }
  else { /* error */
    char s[ONIG_MAX_ERROR_MESSAGE_LEN];
    onig_error_code_to_str(s, r);
    fprintf(stderr, "ERROR: %s\n", s);
    return -1;
  }

  onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
  onig_free(reg);
  onig_end();
  return 0;
}

from oniguruma.

gundermanc avatar gundermanc commented on July 24, 2024

Hi, thanks for the quick response.

The subject string is

"## This is *great* stuff"

but without the quotes.

I am running version 6.1.2 with ONIG_SYNTAX_DEFAULT and ONIG_OPTION_CAPTURE_GROUP and am unable to match, though the same pattern and subject string match on Atom Node Oniguruma and on www.rubular.com

Is there perhaps a difference of default options between the two?

from oniguruma.

kkos avatar kkos commented on July 24, 2024

ONIG_OPTION_CAPTURE_GROUP has no effect for the pattern because it doesn't include named group.
At least in my environment, the string and pattern matches for ONIG_OPTION_CAPTURE_GROUP.

  static UChar* pattern = (UChar* )"(?:^|\\G)(#{1,6})\\s*(?=[\\S[^#]])";
  static UChar* str = (UChar* )"## This is *great* stuff";

  r = onig_new(&reg, pattern, pattern + strlen((char* )pattern),
               ONIG_OPTION_CAPTURE_GROUP,
               ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);

from oniguruma.

gundermanc avatar gundermanc commented on July 24, 2024

Being that it matches for you and your example in UTF8, but not for me in UTF16LE, could this be an encoding specific issue? I'll try converting my code to UTF8 and see if that mitigates the issue. By the way, if I remove the nested negative character match [^#] from the regex, it starts matching.

Let me see if I can do a better job of isolating my repro.

from oniguruma.

k-takata avatar k-takata commented on July 24, 2024

Maybe the following change fixes the problem:
k-takata/Onigmo@609d0ea

from oniguruma.

gundermanc avatar gundermanc commented on July 24, 2024

That's a great suggestion, but it didn't seem to do the trick. This commit however looks related and appeared to fixe the bug for me: k-takata/Onigmo@b5fec0b

from oniguruma.

kkos avatar kkos commented on July 24, 2024

It is a bug for UTF-16.
I want to fix it, but I don't have the time now.

from oniguruma.

kkos avatar kkos commented on July 24, 2024

Thank you.
Fixed by PR #39.

from oniguruma.

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.