bool Foam::regExp::matchGrouping ( const std::string& str, List<StringType>& groups ) const { if (preg_ && str.size()) { size_t nmatch = ngroups() + 1; regmatch_t pmatch[nmatch]; // Also verify that the entire string was matched. // pmatch[0] is the entire match // pmatch[1..] are the (...) sub-groups if ( regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0 && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(str.size())) ) { groups.setSize(ngroups()); label groupI = 0; for (size_t matchI = 1; matchI < nmatch; matchI++) { if (pmatch[matchI].rm_so != -1 && pmatch[matchI].rm_eo != -1) { groups[groupI] = str.substr ( pmatch[matchI].rm_so, pmatch[matchI].rm_eo - pmatch[matchI].rm_so ); } else { groups[groupI].clear(); } groupI++; } return true; } } groups.clear(); return false; }
GroupedDataFrame::GroupedDataFrame(DataFrame x): data_(check_grouped(x)), symbols(group_vars(data_)), groups(data_.attr("groups")), nvars_(symbols.size()) { int rows_in_groups = 0; int ng = ngroups(); List idx = indices(); for (int i = 0; i < ng; i++) rows_in_groups += Rf_length(idx[i]); if (data_.nrows() != rows_in_groups) { bad_arg(".data", "is a corrupt grouped_df, contains {rows} rows, and {group_rows} rows in groups", _["rows"] = data_.nrows(), _["group_rows"] = rows_in_groups); } }