--- trunk/src/utils/Trim.hpp 2005/01/12 22:41:40 246 +++ branches/development/src/utils/Trim.hpp 2012/10/22 20:42:10 1808 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -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, 24107 (2008). + * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #ifndef UTILS_TRIM_HPP @@ -44,140 +44,153 @@ #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 - */ - template - void trimLeftIf(std::string& str, Predict isSpace) { - std::string::iterator i = str.begin(); + /** + * Remove all leading 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 + * + * @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, P pred) { + std::string::iterator i = str.begin(); - for (; i != str.end(); ++i) { - if (!isSpace(*i)) { - break; - } - } - - str.erase(str.begin(), i); + for (; i != str.end(); ++i) { + if (!pred(*i)) { + break; + } } + + str.erase(str.begin(), i); + } - /** - * Remove all trailing spaces in-place. The supplied predicate is used to determine which - * characters are considered spaces - * @param str An input sequence - */ - template - void trimRightIf(std::string& str, Predict isSpace) { - std::string::iterator i = str.end(); + /** + * 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, P pred) { + std::string::iterator i = str.end(); - for (; i != str.begin();) { - if (!isSpace(*(--i))) { - ++i; - break; - } - } - - str.erase(i, str.end()); + for (; i != str.begin();) { + if (!pred(*(--i))) { + ++i; + break; + } } + + str.erase(i, str.end()); + } - /** - *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 - */ - template - void trimIf(std::string& str, Predict isSpace) { - trimLeftIf(str, isSpace); - trimRightIf(str, isSpace); - } + /** + *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, 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 - */ - template - std::string trimLeftCopyIf(const std::string& input, Predict isSpace) { - std::string result(input); - trimLeftIf(result, isSpace); - return result; - } + /** + * 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 pred The unary predicate identifying spaces + */ + template + std::string trimLeftCopyIf(const std::string& input, P pred) { + std::string result(input); + trimLeftIf(result, pred); + return result; + } - /** - * Remove all trailing 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 - */ - template - std::string trimRightCopyIf(const std::string& input, Predict isSpace) { - std::string result(input); - trimRightIf(result, isSpace); - return result; - } + /** + * Remove all trailing 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 pred The unary predicate identifying spaces + */ + template + std::string trimRightCopyIf(const std::string& input, P pred) { + std::string result(input); + trimRightIf(result, pred); + return result; + } - /** - * Remove all leading and trailing 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 - */ - template - std::string trimCopyIf(const std::string& input, Predict isSpace) { - std::string result(input); - trimIf(result, isSpace); - return result; - } + /** + * Remove all leading and trailing 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 pred The unary predicate identifying spaces + */ + template + std::string trimCopyIf(const std::string& input, P pred) { + std::string result(input); + trimIf(result, pred); + return result; + } - /** - * Remove all leading spaces in-place. - * @param str An input sequence - */ - void trimLeft(std::string& str); + /** + * Remove all leading spaces in-place. + * @param str An input sequence + */ + void trimLeft(std::string& str); - /** - * Remove all trailing spaces in-place. - * @param str An input sequence - */ - void trimRight(std::string& str); + /** + * Remove all trailing spaces in-place. + * @param str An input sequence + */ + void trimRight(std::string& str); - /** - *Remove all leading and trailing spaces in-place - * @param str An input sequence - */ - void trim(std::string& str); + /** + *Remove all leading and trailing spaces in-place + * @param str An input sequence + */ + void trim(std::string& str); - /** - * Remove all leading spaces from the input. - * @return A trimmed copy of the input - * @param input An input sequence - */ - std::string trimLeftCopy(const std::string& input); + /** + * Remove all leading spaces from the input. + * @return A trimmed copy of the input + * @param input An input sequence + */ + std::string trimLeftCopy(const std::string& input); - /** - * Remove all trailing spaces from the input. - * @return A trimmed copy of the input - * @param input An input sequence - */ - std::string trimRightCopy(const std::string& input); + /** + * Remove all trailing spaces from the input. + * @return A trimmed copy of the input + * @param input An input sequence + */ + std::string trimRightCopy(const std::string& input); - /** - *Remove all leading and trailing spaces from the input. - * @return A trimmed copy of the input - * @param input An input sequence - */ - std::string trimCopy(const std::string& input); + /** + *Remove all leading and trailing spaces from the input. + * @return A trimmed copy of the input + * @param input An input sequence + */ + std::string trimCopy(const std::string& input); -}//end namespace oopse +}//end namespace OpenMD #endif //UTILS_TRIM_HPP