I have a simple regex conversion method that I use to do some minor processing to HTML passed in as a std::string. The method looks like:
std::string ParseQuotedPrintableHtml( std::string const& html );
I want to design this method into some sort of small library that can be used across my whole code base. Since it’s just a single function, one might be tempted to just create a Utility class (or namespace) and stuff the function in there. I feel this is a bit of a naive design. Any suggestions on a good rule of thumb as to how to design functionality like this into a centralized and accessible location?
EDIT
I should also mention that there are several “helper” functions that this function calls (I also created these, and they are only useful to and used by this method). Ideally these would be “private” in a class, but if I keep this as a global function, those implementation methods will also be accessible in the global namespace (or whichever namespace I place them in).
I guess due to this, it’s best to create a utility class maybe?
class QuotedPrintableHtml
{
private:
void HelperMethod1() const;
void HelperMethod2() const;
std::string html_;
public:
QuotedPrintableHtml( std::string const& html ) : html_(html) {}
std::string Parse() const;
};
Perhaps something like this?
I wouldn’t advise creating a class: the utility functions don’t share some state so I would just create a namespace like
Utilitiesto collect those free functions. You can put all the helper functions you don’t want to share in an anonymous namespace inside your cpp file.