[apparmor] [patch 4/5] parser: convert var expansion to use alternations
Seth Arnold
seth.arnold at canonical.com
Thu Dec 12 09:02:00 UTC 2013
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20131212/1356c914/attachment.pgp>
More information about the AppArmor
mailing list