#ifndef __GLG4StringUtil_hh__ #define __GLG4StringUtil_hh__ // Miscellaneous string utilities derived from BSD-licensed stlplus library // Copyright 2004, Andy Rushton // Revision History: // Renamed to prevent linker collision - (SS) // 13 Nov 2014: Matt Strait - Fixed shadowed variable warnings #include #include //////////////////////////////////////////////////////////////////////////////// // Perl-inspired split/join functions //////////////////////////////////////////////////////////////////////////////// // splits the string at every occurrence of splitter and adds it as a separate string to the return value // the splitter is removed // a string with no splitter in it will give a single-vector string // an empty string gives an empty vector std::vector util_split (const std::string& str, const std::string& splitter = "\n"); // the reverse of the above // joins the string vector to create a single string with the joiner inserted between the joins // Note: the joiner will not be added at the beginning or the end // However, there are optional fields to add such prefix and suffix strings std::string util_join (const std::vector&, const std::string& joiner = "\n", const std::string& prefix = "", const std::string& suffix = ""); // trim whitespace around a string std::string util_trim_left(const std::string& val); std::string util_trim_right(const std::string& val); std::string util_trim(const std::string& val); // strips leading and trailing characters from s. This function by // Glenn Horton-Smith. std::string util_strip(const std::string &s, const std::string &stripchars); // strip spaces, tabs, and quotation marks std::string util_strip_default(const std::string &s); #endif