zeusdeux / re2

Automatically exported from code.google.com/p/re2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Extract Matched Subpieces Problem: string is ok, int fail #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. RE2 r("(123)|(456)|(789)");
2. string word1, word2, word3;
    int num1=0, num2=0, num3=0;
3. CHECK(RE2::PartialMatch("456", r, &word1, &word2, &word3));
    CHECK(word2, "456");
    // above is ok
    // --------------------------
    // blow is fail
    CHECK(RE2::PartialMatch("456", r, &num1, &num2, &num3));
    CHECK_EQ(num2, 456);

  I hope this message is useful, Thanks.

Original issue reported on code.google.com by yanlong...@gmail.com on 18 Nov 2011 at 3:32

GoogleCodeExporter commented 9 years ago
If you unpack into a number you must match the number. There are no matches for 
the (123) or (789) in the second example and so there is nothing to write into 
num1 or num3, and so RE2::PartialMatch fails. 

For strings we can at least set them to the empty string, which is why they are 
allowed.

Original comment by rsc@golang.org on 10 Jan 2014 at 1:16