--- trunk/src/utils/Trim.hpp 2005/04/15 22:04:00 507 +++ branches/development/src/utils/Trim.hpp 2013/02/20 15:39:39 1850 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,6 +28,15 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #ifndef UTILS_TRIM_HPP @@ -44,25 +44,33 @@ #include #include +#include "utils/Predicate.hpp" /** * @file Trim.hpp * Defines trim algorithms. Trim algorithms are used to remove trailing and leading spaces from a string. */ -namespace oopse { +namespace OpenMD { /** * Remove all leading spaces in-place. The supplied predicate is used to determine which * characters are considered spaces * @param str An input sequence - * @param IsSpace An unary predicate identifying spaces + * @param pred The unary predicate identifying spaces + * + * @code + * std::string str = " acb trimLeftIf test case" + * trimLeftIf(str, pred() || isFromRange('a', 'c')); + * std::cout << str << std::endl; //print "trimLeft test case" + * + * @endcode */ - template - void trimLeftIf(std::string& str, Predict isSpace) { + template + void trimLeftIf(std::string& str, P pred) { std::string::iterator i = str.begin(); for (; i != str.end(); ++i) { - if (!isSpace(*i)) { + if (!pred(*i)) { break; } } @@ -74,13 +82,14 @@ namespace oopse { * Remove all trailing spaces in-place. The supplied predicate is used to determine which * characters are considered spaces * @param str An input sequence + * @param pred The unary predicate identifying spaces */ - template - void trimRightIf(std::string& str, Predict isSpace) { + template + void trimRightIf(std::string& str, P pred) { std::string::iterator i = str.end(); for (; i != str.begin();) { - if (!isSpace(*(--i))) { + if (!pred(*(--i))) { ++i; break; } @@ -93,23 +102,25 @@ namespace oopse { *Remove all leading and trailing spaces in-place. The supplied predicate is used to determine * which characters are considered spaces * @param str An input sequence + * @param pred The unary predicate identifying spaces */ - template - void trimIf(std::string& str, Predict isSpace) { - trimLeftIf(str, isSpace); - trimRightIf(str, isSpace); + template + void trimIf(std::string& str, P pred) { + trimLeftIf(str, pred); + trimRightIf(str, pred); } /** * Remove all leading spaces from the input. The supplied predicate is used to determine * which characters are considered spaces * @return A trimmed copy of the input - * @param input An input sequence + * @param input An input sequence + * @param pred The unary predicate identifying spaces */ - template - std::string trimLeftCopyIf(const std::string& input, Predict isSpace) { + template + std::string trimLeftCopyIf(const std::string& input, P pred) { std::string result(input); - trimLeftIf(result, isSpace); + trimLeftIf(result, pred); return result; } @@ -118,11 +129,12 @@ namespace oopse { * which characters are considered spaces * @return A trimmed copy of the input * @param input An input sequence + * @param pred The unary predicate identifying spaces */ - template - std::string trimRightCopyIf(const std::string& input, Predict isSpace) { + template + std::string trimRightCopyIf(const std::string& input, P pred) { std::string result(input); - trimRightIf(result, isSpace); + trimRightIf(result, pred); return result; } @@ -131,11 +143,12 @@ namespace oopse { * determine which characters are considered spaces * @return A trimmed copy of the input * @param input An input sequence + * @param pred The unary predicate identifying spaces */ - template - std::string trimCopyIf(const std::string& input, Predict isSpace) { + template + std::string trimCopyIf(const std::string& input, P pred) { std::string result(input); - trimIf(result, isSpace); + trimIf(result, pred); return result; } @@ -179,5 +192,5 @@ namespace oopse { */ std::string trimCopy(const std::string& input); -}//end namespace oopse +}//end namespace OpenMD #endif //UTILS_TRIM_HPP