#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2023 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_SUPPORT_TEXT_STRINGHELPER_H #define NUCLEX_SUPPORT_TEXT_STRINGHELPER_H #include "Nuclex/Support/Config.h" #include // for std::string namespace Nuclex { namespace Support { namespace Text { // ------------------------------------------------------------------------------------------- // /// Provides a few additional helper methods for dealing with strings class NUCLEX_SUPPORT_TYPE StringHelper { /// Removes any whitespace characters that follow other whitespace /// String in which duplicate whitespace will be collapsed /// Whether to also remove leading and trailing whitespace /// /// This method considers all whitespace characters defined by unicode. It will leave /// single whitespace characters intact, but consecutive whitespace characters will /// be replaced with a single ascii whitespace. A string consisting of only whitspace /// will result either in a single whitespace remaining or nothing if trim is enabled. /// public: NUCLEX_SUPPORT_API static void CollapseDuplicateWhitespace( std::string &utf8String, bool alsoTrim = true ); /// Removes any whitespace characters that follow other whitespace /// String in which duplicate whitespace will be collapsed /// Whether to also remove leading and trailing whitespace /// /// This method considers all whitespace characters defined by unicode. It will leave /// single whitespace characters intact, but consecutive whitespace characters will /// be replaced with a single ascii whitespace. A string consisting of only whitspace /// will result either in a single whitespace remaining or nothing if trim is enabled. /// public: NUCLEX_SUPPORT_API static void CollapseDuplicateWhitespace( std::wstring &wideString, bool alsoTrim = true ); /// Removes all occurrences of a substring from the master string /// /// String from which all occurrences of the specified substring will be removed /// /// /// Substring that will be removed from the master string /// /// /// This method is guaranteed to not remove occurrences recursively. For example, /// removing "" from the string "Testend>" will produce /// the string "Test" (i.e. it will only remove the substring where it /// was present initially, not where it was formed as an effect of the removal). /// public: NUCLEX_SUPPORT_API static void EraseSubstrings( std::string &utf8String, const std::string &victim ); /// Removes all occurrences of a substring from the master string /// /// String from which all occurrences of the specified substring will be removed /// /// /// Substring that will be removed from the master string /// /// /// This method is guaranteed to not remove occurrences recursively. For example, /// removing "" from the string "Testend>" will produce /// the string "Test" (i.e. it will only remove the substring where it /// was present initially, not where it was formed as an effect of the removal). /// public: NUCLEX_SUPPORT_API static void EraseSubstrings( std::wstring &wideString, const std::wstring &victim ); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Support::Text #endif // NUCLEX_SUPPORT_TEXT_STRINGHELPER_H