LCOV - code coverage report
Current view: top level - libreoffice/autodoc/source/parser_i/tokens - tkpstam2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 63 79.4 %
Date: 2012-12-27 Functions: 11 12 91.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 <precomp.h>
      21             : #include <tokens/tkpstam2.hxx>
      22             : 
      23             : // NOT FULLY DECLARED SERVICES
      24             : #include <tokens/stmstar2.hxx>
      25             : #include <tools/tkpchars.hxx>
      26             : 
      27             : 
      28             : const intt  C_nStatuslistResizeValue = 32;
      29             : const intt  C_nTopStatus = 0;
      30             : 
      31           6 : StateMachin2::StateMachin2( intt            in_nStatusSize,
      32             :                             intt            in_nInitial_StatusListSize )
      33           6 :     :   pStati(new StmStatu2*[in_nInitial_StatusListSize]),
      34             :         nCurrentStatus(C_nTopStatus),
      35             :         nPeekedStatus(C_nTopStatus),
      36             :         nStatusSize(in_nStatusSize),
      37             :         nNrofStati(0),
      38           6 :         nStatiSpace(in_nInitial_StatusListSize)
      39             : {
      40             :     csv_assert(in_nStatusSize > 0);
      41             :     csv_assert(in_nInitial_StatusListSize > 0);
      42             : 
      43           6 :     memset(pStati, 0, sizeof(StmStatu2*) * nStatiSpace);
      44           6 : }
      45             : 
      46             : intt
      47        1578 : StateMachin2::AddStatus(StmStatu2 * let_dpStatus)
      48             : {
      49        1578 :     if (nNrofStati == nStatiSpace)
      50             :     {
      51           0 :         ResizeStati();
      52             :     }
      53        1578 :     pStati[nNrofStati] = let_dpStatus;
      54        1578 :     return nNrofStati++;
      55             : }
      56             : 
      57             : void
      58         360 : StateMachin2::AddToken( const char *        in_sToken,
      59             :                         UINT16              in_nTokenId,
      60             :                         const INT16 *       in_aBranches,
      61             :                         INT16               in_nBoundsStatus )
      62             : {
      63         360 :     if (csv::no_str(in_sToken))
      64         360 :         return;
      65             : 
      66         360 :     nCurrentStatus = 0;
      67         360 :     nPeekedStatus = 0;
      68             : 
      69        2229 :     for ( const char * pChar = in_sToken;
      70             :           *pChar != NULCH;
      71             :           ++pChar )
      72             :     {
      73        1869 :         Peek(*pChar);
      74        1869 :         StmStatu2 & rPst = Status(nPeekedStatus);
      75        1869 :         if ( rPst.IsADefault() OR rPst.AsBounds() != 0 )
      76             :         {
      77        1476 :             nPeekedStatus = AddStatus( new StmArrayStatu2(nStatusSize, in_aBranches, 0, false ) );
      78        1476 :             CurrentStatus().SetBranch( *pChar, nPeekedStatus );
      79             :         }
      80        1869 :         nCurrentStatus = nPeekedStatus;
      81             :     }   // end for
      82         360 :     StmArrayStatu2 & rLastStatus = CurrentStatus();
      83         360 :     rLastStatus.SetTokenId(in_nTokenId);
      84       46440 :     for (intt i = 0; i < nStatusSize; i++)
      85             :     {
      86       46080 :         if (Status(rLastStatus.NextBy(i)).AsBounds() != 0)
      87       33609 :             rLastStatus.SetBranch(i,in_nBoundsStatus);
      88             :     }   // end for
      89             : }
      90             : 
      91           6 : StateMachin2::~StateMachin2()
      92             : {
      93        1584 :     for (intt i = 0; i < nNrofStati; i++)
      94             :     {
      95        1578 :         delete pStati[i];
      96             :     }
      97           6 :     delete [] pStati;
      98           6 : }
      99             : 
     100             : StmBoundsStatu2 &
     101     1928026 : StateMachin2::GetCharChain( UINT16 &           o_nTokenId,
     102             :                             CharacterSource &  io_rText )
     103             : {
     104     1928026 :     nCurrentStatus = C_nTopStatus;
     105     1928026 :     Peek(io_rText.CurChar());
     106    10086928 :     while (BoundsStatus() == 0)
     107             :     {
     108     6230877 :         nCurrentStatus = nPeekedStatus;
     109     6230877 :         Peek(io_rText.MoveOn());
     110             :     }
     111     1928025 :     o_nTokenId = CurrentStatus().TokenId();
     112             : 
     113     1928025 :     return *BoundsStatus();
     114             : }
     115             : 
     116             : void
     117           0 : StateMachin2::ResizeStati()
     118             : {
     119           0 :     intt nNewSize = nStatiSpace + C_nStatuslistResizeValue;
     120           0 :     intt i = 0;
     121           0 :     StatusList pNewStati = new StmStatu2*[nNewSize];
     122             : 
     123           0 :     for ( ; i < nNrofStati; i++)
     124             :     {
     125           0 :         pNewStati[i] = pStati[i];
     126             :     }
     127           0 :     memset( pNewStati+i,
     128             :             0,
     129           0 :             (nNewSize-i) * sizeof(StmStatu2*) );
     130             : 
     131           0 :     delete [] pStati;
     132           0 :     pStati = pNewStati;
     133           0 :     nStatiSpace = nNewSize;
     134           0 : }
     135             : 
     136             : StmStatu2 &
     137    20225509 : StateMachin2::Status(intt in_nStatusNr) const
     138             : {
     139             :     csv_assert( csv::in_range(intt(0), in_nStatusNr, intt(nNrofStati)) );
     140    20225509 :     return *pStati[in_nStatusNr];
     141             : }
     142             : 
     143             : StmArrayStatu2 &
     144    10090633 : StateMachin2::CurrentStatus() const
     145             : {
     146    10090633 :     StmArrayStatu2 * pCurSt = Status(nCurrentStatus).AsArray();
     147             :     if (pCurSt == 0)
     148             :     {
     149             :         csv_assert(false);
     150             :     }
     151    10090633 :     return *pCurSt;
     152             : }
     153             : 
     154             : StmBoundsStatu2 *
     155    10086927 : StateMachin2::BoundsStatus() const
     156             : {
     157    10086927 :     return Status(nPeekedStatus).AsBounds();
     158             : }
     159             : 
     160             : void
     161     8160772 : StateMachin2::Peek(intt in_nBranch)
     162             : {
     163     8160772 :     StmArrayStatu2 & rSt = CurrentStatus();
     164     8160772 :     nPeekedStatus = rSt.NextBy(in_nBranch);
     165     8160774 : }
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10