diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2013-08-18 12:03:34 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-08-20 11:37:58 +0100 |
commit | e47d90690c8fab3ec8b7fd7c1b79372251770f9d (patch) | |
tree | d6df7861da788f1a412ed32c0368c45e7030498f /sw | |
parent | e1a9a348a519a69f898c9c1e6d87a5837b8267f9 (diff) |
String to OUString, better location for class method
Change-Id: Ifde0d45e35fed94d4ef6cb93b2feda172fd6608b
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/SwRewriter.hxx | 10 | ||||
-rw-r--r-- | sw/source/core/undo/SwRewriter.cxx | 52 | ||||
-rw-r--r-- | sw/source/core/undo/undel.cxx | 36 |
3 files changed, 60 insertions, 38 deletions
diff --git a/sw/inc/SwRewriter.hxx b/sw/inc/SwRewriter.hxx index bb535083ada0..ecf28ce13b5f 100644 --- a/sw/inc/SwRewriter.hxx +++ b/sw/inc/SwRewriter.hxx @@ -21,7 +21,7 @@ #define _SW_REWRITER_HXX #include <vector> -#include <tools/string.hxx> +#include <rtl/ustring.hxx> #include <swdllapi.h> enum SwUndoArg @@ -31,7 +31,7 @@ enum SwUndoArg UndoArg3 }; -typedef std::pair<SwUndoArg, String> SwRewriteRule; +typedef std::pair<SwUndoArg, OUString> SwRewriteRule; class SW_DLLPUBLIC SwRewriter { @@ -42,9 +42,11 @@ public: SwRewriter(const SwRewriter & rSrc); ~SwRewriter(); - void AddRule(SwUndoArg eWhat, const String & rWith); + void AddRule(SwUndoArg eWhat, const OUString & rWith); - String Apply(const String & rStr) const; + OUString Apply(const OUString & rStr) const; + + static OUString GetPlaceHolder(SwUndoArg eId); }; #endif // _SW_REWRITER_HXX diff --git a/sw/source/core/undo/SwRewriter.cxx b/sw/source/core/undo/SwRewriter.cxx index 60d094d3b29d..3d1b584f2f2c 100644 --- a/sw/source/core/undo/SwRewriter.cxx +++ b/sw/source/core/undo/SwRewriter.cxx @@ -41,7 +41,7 @@ SwRewriter::~SwRewriter() { } -void SwRewriter::AddRule(SwUndoArg eWhat, const String & rWith) +void SwRewriter::AddRule(SwUndoArg eWhat, const OUString & rWith) { SwRewriteRule aRule(eWhat, rWith); @@ -55,4 +55,54 @@ void SwRewriter::AddRule(SwUndoArg eWhat, const String & rWith) mRules.push_back(aRule); } +namespace +{ + +const char UNDO_ARG1[] = "$1"; +const char UNDO_ARG2[] = "$2"; +const char UNDO_ARG3[] = "$3"; + +} + +OUString SwRewriter::Apply(const OUString & rStr) const +{ + OUString aResult = rStr; + std::vector<SwRewriteRule>::const_iterator aIt; + + for (aIt = mRules.begin(); aIt != mRules.end(); ++aIt) + { + switch (aIt->first) + { + case UndoArg1: + default: + aResult = aResult.replaceAll(UNDO_ARG1, aIt->second); + break; + case UndoArg2: + aResult = aResult.replaceAll(UNDO_ARG2, aIt->second); + break; + case UndoArg3: + aResult = aResult.replaceAll(UNDO_ARG3, aIt->second); + break; + } + } + + return aResult; +} + +OUString SwRewriter::GetPlaceHolder(SwUndoArg eId) +{ + switch (eId) + { + case UndoArg1: + return OUString(UNDO_ARG1); + case UndoArg2: + return OUString(UNDO_ARG2); + case UndoArg3: + return OUString(UNDO_ARG3); + default: + break; + } + return OUString(UNDO_ARG1); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx index 2fbe933c3cb0..c6ac06c8b979 100644 --- a/sw/source/core/undo/undel.cxx +++ b/sw/source/core/undo/undel.cxx @@ -552,10 +552,6 @@ static bool lcl_IsSpecialCharacter(sal_Unicode nChar) return false; } -const char UNDO_ARG1[] = "$1"; -const char UNDO_ARG2[] = "$2"; -const char UNDO_ARG3[] = "$3"; - static String lcl_DenotedPortion(String rStr, xub_StrLen nStart, xub_StrLen nEnd) { @@ -579,8 +575,7 @@ static String lcl_DenotedPortion(String rStr, xub_StrLen nStart, case CH_TXTATR_INWORD: case CH_TXTATR_BREAKWORD: - aResult = OUString(UNDO_ARG2); - + aResult = SwRewriter::GetPlaceHolder(UndoArg2); break; } @@ -638,7 +633,7 @@ String DenoteSpecialCharacters(const String & rStr) aResult += lcl_DenotedPortion(rStr, nStart, rStr.Len()); } else - aResult = OUString(UNDO_ARG2); + aResult = SwRewriter::GetPlaceHolder(UndoArg2); return aResult; } @@ -686,7 +681,7 @@ SwRewriter SwUndoDelete::GetRewriter() const } else { - aStr = OUString(UNDO_ARG2); + aStr = SwRewriter::GetPlaceHolder(UndoArg2); } } @@ -1082,29 +1077,4 @@ void SwUndoDelete::SetTableName(const String & rName) sTableName = rName; } -String SwRewriter::Apply(const String & rStr) const -{ - OUString aResult = rStr; - std::vector<SwRewriteRule>::const_iterator aIt; - - for (aIt = mRules.begin(); aIt != mRules.end(); ++aIt) - { - switch (aIt->first) - { - case UndoArg1: - default: - aResult = aResult.replaceAll(UNDO_ARG1, aIt->second); - break; - case UndoArg2: - aResult = aResult.replaceAll(UNDO_ARG2, aIt->second); - break; - case UndoArg3: - aResult = aResult.replaceAll(UNDO_ARG3, aIt->second); - break; - } - } - - return aResult; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |