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 <tools/tkpchars.hxx>
22 :
23 : // NOT FULLY DECLARED SERVICES
24 : #include <cosv/bstream.hxx>
25 : #include <cosv/x.hxx>
26 :
27 :
28 :
29 3 : CharacterSource::CharacterSource()
30 3 : : dpSource(new char[2]),
31 : nSourceSize(0),
32 : nCurPos(0),
33 : nLastCut(0),
34 : nLastTokenStart(0),
35 3 : cCharAtLastCut(0)
36 : {
37 3 : dpSource[nSourceSize] = NULCH;
38 3 : dpSource[nSourceSize+1] = NULCH;
39 3 : }
40 :
41 3 : CharacterSource::~CharacterSource()
42 : {
43 3 : delete [] dpSource;
44 3 : }
45 :
46 : void
47 4137 : CharacterSource::LoadText(csv::bstream & io_rSource)
48 : {
49 4137 : if (dpSource != 0)
50 4137 : delete [] dpSource;
51 :
52 4137 : io_rSource.seek(0, csv::end);
53 4137 : nSourceSize = intt(io_rSource.position());
54 4137 : io_rSource.seek(0);
55 :
56 4137 : dpSource = new char[nSourceSize+1];
57 :
58 4137 : intt nCount = (intt) io_rSource.read(dpSource,nSourceSize);
59 4137 : if (nCount != nSourceSize)
60 0 : throw csv::X_Default("IO-Error: Could not load file completely.");
61 :
62 4137 : dpSource[nSourceSize] = NULCH;
63 :
64 4137 : BeginSource();
65 4137 : }
66 :
67 : const char *
68 1915863 : CharacterSource::CutToken()
69 : {
70 1915863 : dpSource[nLastCut] = cCharAtLastCut;
71 1915863 : nLastTokenStart = nLastCut;
72 1915863 : nLastCut = CurPos();
73 1915863 : cCharAtLastCut = dpSource[nLastCut];
74 1915863 : dpSource[nLastCut] = NULCH;
75 :
76 1915863 : return &dpSource[nLastTokenStart];
77 : }
78 :
79 : void
80 4137 : CharacterSource::BeginSource()
81 : {
82 4137 : nCurPos = 0;
83 4137 : nLastCut = 0;
84 4137 : nLastTokenStart = 0;
85 4137 : cCharAtLastCut = dpSource[nLastCut];
86 4137 : dpSource[nLastCut] = NULCH;
87 4140 : }
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|