I'm trying to use the Glib::Regex, but it keeps returning junk.
Here is a simplified version of the code:
void testGetPos(std::string fileName){
auto regEx = Glib::Regex::create(
"^sprite_[0-9]+__x(-?[0-9]+)_y(-?[0-9]+)\\.tif$",
Glib::REGEX_CASELESS
)
Glib::MatchInfo match;
if(!regEx->match(fileName, match)){
continue;
}
if(!match.matches()){
continue;
}
auto posX = match.fetch(1);
auto posY = match.fetch(2);
// ... Use posX and posY
}
int main(){
testGetPos("sprite_000__x-28_y-32.tif");
}
After this has run, posX and posY are filled with junk. However, using C functions on the wrapped objects:
void testGetPos(std::string fileName){
auto regEx = Glib::Regex::create(
"^sprite_[0-9]+__x(-?[0-9]+)_y(-?[0-9]+)\\.tif$",
Glib::REGEX_CASELESS
)
GMatchInfo *match = nullptr;
if(!g_regex_match(regEx->gobj(), fileName.c_str(), (GRegexMatchFlags)0, &match)){
if(match != nullptr){
g_match_info_free(match);
}
return;
}
auto posX = g_match_info_fetch(match, 1);
auto posY = g_match_info_fetch(match, 2);
// ... Use posX and posY
g_free(posX);
g_free(posY);
g_match_info_free(match);
}
int main(){
testGetPos("sprite_000__x-28_y-32.tif");
}
Works fine. Am I doing something wrong or is this broken.