LCOV - code coverage report
Current view: top level - sw/source/core/undo - SwRewriter.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 23 29 79.3 %
Date: 2014-11-03 Functions: 6 7 85.7 %
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        1380 : bool operator == (const SwRewriteRule & a, const SwRewriteRule & b)
      26             : {
      27        1380 :     return a.first == b.first;
      28             : }
      29             : 
      30       64961 : SwRewriter::SwRewriter()
      31             : {
      32       64961 : }
      33             : 
      34           0 : SwRewriter::SwRewriter(const SwRewriter & rSrc)
      35           0 :     : mRules(rSrc.mRules)
      36             : {
      37           0 : }
      38             : 
      39       64961 : SwRewriter::~SwRewriter()
      40             : {
      41       64961 : }
      42             : 
      43       45049 : void SwRewriter::AddRule(SwUndoArg eWhat, const OUString & rWith)
      44             : {
      45       45049 :     SwRewriteRule aRule(eWhat, rWith);
      46             : 
      47       45049 :     vector<SwRewriteRule>::iterator aIt;
      48             : 
      49       45049 :     aIt = find(mRules.begin(), mRules.end(), aRule);
      50             : 
      51       45049 :     if (aIt != mRules.end())
      52           0 :         *aIt = aRule;
      53             :     else
      54       45049 :         mRules.push_back(aRule);
      55       45049 : }
      56             : 
      57       64957 : OUString SwRewriter::Apply(const OUString & rStr) const
      58             : {
      59       64957 :     OUString aResult = rStr;
      60             : 
      61      110000 :     for (std::vector<SwRewriteRule>::const_iterator aIt = mRules.begin(); aIt != mRules.end(); ++aIt)
      62             :     {
      63       45043 :         aResult = aResult.replaceAll(GetPlaceHolder(aIt->first), aIt->second);
      64             :     }
      65             : 
      66       64957 :     return aResult;
      67             : }
      68             : 
      69       49043 : OUString SwRewriter::GetPlaceHolder(SwUndoArg eId)
      70             : {
      71       49043 :     switch (eId)
      72             :     {
      73             :         case UndoArg1:
      74       43733 :             return OUString("$1");
      75             :         case UndoArg2:
      76        4852 :             return OUString("$2");
      77             :         case UndoArg3:
      78         458 :             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