LCOV - code coverage report
Current view: top level - sw/source/core/undo - SwRewriter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 29 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <algorithm>
      21             : #include <SwRewriter.hxx>
      22             : 
      23             : using namespace std;
      24             : 
      25           0 : bool operator == (const SwRewriteRule & a, const SwRewriteRule & b)
      26             : {
      27           0 :     return a.first == b.first;
      28             : }
      29             : 
      30           0 : SwRewriter::SwRewriter()
      31             : {
      32           0 : }
      33             : 
      34           0 : SwRewriter::SwRewriter(const SwRewriter & rSrc)
      35           0 :     : mRules(rSrc.mRules)
      36             : {
      37           0 : }
      38             : 
      39           0 : SwRewriter::~SwRewriter()
      40             : {
      41           0 : }
      42             : 
      43           0 : void SwRewriter::AddRule(SwUndoArg eWhat, const OUString & rWith)
      44             : {
      45           0 :     SwRewriteRule aRule(eWhat, rWith);
      46             : 
      47           0 :     vector<SwRewriteRule>::iterator aIt;
      48             : 
      49           0 :     aIt = find(mRules.begin(), mRules.end(), aRule);
      50             : 
      51           0 :     if (aIt != mRules.end())
      52           0 :         *aIt = aRule;
      53             :     else
      54           0 :         mRules.push_back(aRule);
      55           0 : }
      56             : 
      57           0 : OUString SwRewriter::Apply(const OUString & rStr) const
      58             : {
      59           0 :     OUString aResult = rStr;
      60             : 
      61           0 :     for (std::vector<SwRewriteRule>::const_iterator aIt = mRules.begin(); aIt != mRules.end(); ++aIt)
      62             :     {
      63           0 :         aResult = aResult.replaceAll(GetPlaceHolder(aIt->first), aIt->second);
      64             :     }
      65             : 
      66           0 :     return aResult;
      67             : }
      68             : 
      69           0 : OUString SwRewriter::GetPlaceHolder(SwUndoArg eId)
      70             : {
      71           0 :     switch (eId)
      72             :     {
      73             :         case UndoArg1:
      74           0 :             return OUString("$1");
      75             :         case UndoArg2:
      76           0 :             return OUString("$2");
      77             :         case UndoArg3:
      78           0 :             return OUString("$3");
      79             :         default:
      80           0 :             break;
      81             :     }
      82           0 :     return OUString("$1");
      83             : }
      84             : 
      85             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10