1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tkpchars.cxx,v $
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 ************************************************************************/
32 #include <tools/tkpchars.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <cosv/bstream.hxx>
40 CharacterSource::CharacterSource()
41 : dpSource(new char[2]),
48 dpSource
[nSourceSize
] = NULCH
;
49 dpSource
[nSourceSize
+1] = NULCH
;
52 CharacterSource::~CharacterSource()
58 CharacterSource::LoadText(csv::bstream
& io_rSource
)
63 io_rSource
.seek(0, csv::end
);
64 nSourceSize
= intt(io_rSource
.position());
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
;
78 /// KORR_FUTURE: So far, this works only when tokens do not cross inserted text boundaries.
80 CharacterSource::InsertTextAtCurPos( const char * i_sText2Insert
)
82 if ( i_sText2Insert
== 0 ? true : strlen(i_sText2Insert
) == 0 )
85 aSourcesStack
.push( S_SourceState(
93 nSourceSize
= strlen(i_sText2Insert
);
94 dpSource
= new char[nSourceSize
+1];
95 strcpy( dpSource
, i_sText2Insert
); // SAFE STRCPY (#100211# - checked)
101 CharacterSource::CutToken()
103 dpSource
[nLastCut
] = cCharAtLastCut
;
104 nLastTokenStart
= nLastCut
;
106 cCharAtLastCut
= dpSource
[nLastCut
];
107 dpSource
[nLastCut
] = NULCH
;
109 return &dpSource
[nLastTokenStart
];
113 CharacterSource::BeginSource()
118 cCharAtLastCut
= dpSource
[nLastCut
];
119 dpSource
[nLastCut
] = NULCH
;
122 // KORR_FUTURE: So far, this works only when tokens do not cross inserted text boundaries.
124 CharacterSource::MoveOn_OverStack()
126 while ( aSourcesStack
.size() > 0 AND nCurPos
>= nSourceSize
-1 )
128 S_SourceState
& aState
= aSourcesStack
.top();
131 dpSource
= aState
.dpSource
;
132 nSourceSize
= aState
.nSourceSize
;
133 nCurPos
= aState
.nCurPos
;
134 nLastCut
= aState
.nLastCut
;
135 nLastTokenStart
= aState
.nLastTokenStart
;
136 cCharAtLastCut
= aState
.cCharAtLastCut
;
141 if ( nLastCut
< nCurPos
)
148 S_SourceState::S_SourceState( DYN
char * dpSource_
,
152 intt nLastTokenStart_
,
153 char cCharAtLastCut_
)
154 : dpSource(dpSource_
),
155 nSourceSize(nSourceSize_
),
158 nLastTokenStart(nLastTokenStart_
),
159 cCharAtLastCut(cCharAtLastCut_
)