On Mon, Dec 09, 2013 at 12:37:13PM -0800, Steve Beattie wrote: It's too late to make it through expand_by_alternations(), so just a quick thought on these first two functions...
> +static void trim_trailing_slash(std::string& str)
> +{
> + for (std::string::reverse_iterator rit = str.rbegin();
> + rit != str.rend() && *rit == '/'; ++rit) {
> + /* yuck, reverse_iterators are ugly */
> + str.erase(--rit.base());
> + }
> +}
> +
> +static void write_replacement(const char separator, const char* value,
> + std::string& replacement, bool
> filter_leading_slash,
> + bool filter_trailing_slash)
> +{
> + const char *p = value;
> +
> + replacement.append(1, separator);
> +
> + if (filter_leading_slash)
> + while (*p == '/')
> + p++;
> +
> + replacement.append(p);
> + if (filter_trailing_slash)
> + trim_trailing_slash(replacement);
> +}
Yuck, reverse iterators _are_ ugly. :)
While trying to come up with something better using substr, I stumbled
over find_last_not_of() and find_first_not_of():
http://www.cplusplus.com/reference/string/string/find_first_not_of/
http://www.cplusplus.com/reference/string/string/find_last_not_of/
I think these two functions would make it easier to snip the results
(substr() maybe?) down to something less ugly than modifying a string in
the middle of a reverse iterator.
Thanks
signature.asc
Description: Digital signature
-- AppArmor mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
