merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / tools / tkpchars.cxx
blobbefdad9d66328a3f961213e2198ceaa72192b3e8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tkpchars.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include <tools/tkpchars.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <cosv/bstream.hxx>
36 #include <cosv/x.hxx>
40 CharacterSource::CharacterSource()
41 : dpSource(new char[2]),
42 nSourceSize(0),
43 nCurPos(0),
44 nLastCut(0),
45 nLastTokenStart(0),
46 cCharAtLastCut(0)
48 dpSource[nSourceSize] = NULCH;
49 dpSource[nSourceSize+1] = NULCH;
52 CharacterSource::~CharacterSource()
54 delete [] dpSource;
57 void
58 CharacterSource::LoadText(csv::bstream & io_rSource)
60 if (dpSource != 0)
61 delete [] dpSource;
63 io_rSource.seek(0, csv::end);
64 nSourceSize = intt(io_rSource.position());
65 io_rSource.seek(0);
67 dpSource = new char[nSourceSize+1];
69 intt nCount = (intt) io_rSource.read(dpSource,nSourceSize);
70 if (nCount != nSourceSize)
71 throw csv::X_Default("IO-Error: Could not load file completely.");
73 dpSource[nSourceSize] = NULCH;
75 BeginSource();
78 /// KORR_FUTURE: So far, this works only when tokens do not cross inserted text boundaries.
79 void
80 CharacterSource::InsertTextAtCurPos( const char * i_sText2Insert )
82 if ( i_sText2Insert == 0 ? true : strlen(i_sText2Insert) == 0 )
83 return;
85 aSourcesStack.push( S_SourceState(
86 dpSource,
87 nSourceSize,
88 nCurPos,
89 nLastCut,
90 nLastTokenStart,
91 cCharAtLastCut ) );
93 nSourceSize = strlen(i_sText2Insert);
94 dpSource = new char[nSourceSize+1];
95 strcpy( dpSource, i_sText2Insert); // SAFE STRCPY (#100211# - checked)
97 BeginSource();
100 const char *
101 CharacterSource::CutToken()
103 dpSource[nLastCut] = cCharAtLastCut;
104 nLastTokenStart = nLastCut;
105 nLastCut = CurPos();
106 cCharAtLastCut = dpSource[nLastCut];
107 dpSource[nLastCut] = NULCH;
109 return &dpSource[nLastTokenStart];
112 void
113 CharacterSource::BeginSource()
115 nCurPos = 0;
116 nLastCut = 0;
117 nLastTokenStart = 0;
118 cCharAtLastCut = dpSource[nLastCut];
119 dpSource[nLastCut] = NULCH;
122 // KORR_FUTURE: So far, this works only when tokens do not cross inserted text boundaries.
123 char
124 CharacterSource::MoveOn_OverStack()
126 while ( aSourcesStack.size() > 0 AND nCurPos >= nSourceSize-1 )
128 S_SourceState & aState = aSourcesStack.top();
129 delete [] dpSource;
131 dpSource = aState.dpSource;
132 nSourceSize = aState.nSourceSize;
133 nCurPos = aState.nCurPos;
134 nLastCut = aState.nLastCut;
135 nLastTokenStart = aState.nLastTokenStart;
136 cCharAtLastCut = aState.cCharAtLastCut;
138 aSourcesStack.pop();
141 if ( nLastCut < nCurPos )
142 CutToken();
144 return CurChar();
147 CharacterSource::
148 S_SourceState::S_SourceState( DYN char * dpSource_,
149 intt nSourceSize_,
150 intt nCurPos_,
151 intt nLastCut_,
152 intt nLastTokenStart_,
153 char cCharAtLastCut_ )
154 : dpSource(dpSource_),
155 nSourceSize(nSourceSize_),
156 nCurPos(nCurPos_),
157 nLastCut(nLastCut_),
158 nLastTokenStart(nLastTokenStart_),
159 cCharAtLastCut(cCharAtLastCut_)