cppstring GTextUtils::MatchSubString(const cppstring & sFullName, const cppstring & sFormat, const cppstring & sSubName) { // MatchSubString determines whether sFullName matches sFormat (allowing sSubName to stand for a wildcard) // For example, if the format is "Run %n" and "%n" is the wildcard, then "Run 1" will match and return "1". cppstring sSubString; // Find the starting character of the wildcard string (assume 0 if wildcard isn't found) unsigned int nStartSub = sFormat.find(sSubName), nEndSub; if (nStartSub != cppstring::npos) { nEndSub = nStartSub + sSubName.length(); // Break the format into two chunks surrounding the wildcard cppstring sBeginFormat = sFormat.substr(0, nStartSub); cppstring sEndFormat = sFormat.substr(nEndSub, sFormat.length() - sSubName.length()); // Now match the beginning and ending formats and extract the wildcard string unsigned int nStartMatch = sFullName.find(sBeginFormat), nEndMatch; if (nStartMatch != cppstring::npos) { nStartMatch += sBeginFormat.length(); nEndMatch = sFullName.rfind(sEndFormat); if (nEndMatch != cppstring::npos) sSubString = sFullName.substr(nStartMatch, nEndMatch - nStartMatch); } } return sSubString; }