xref: /trunk/main/autodoc/source/parser/adoc/cx_a_sub.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include <adoc/cx_a_sub.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <tokens/parseinc.hxx>
34 #include <x_parse.hxx>
35 #include <adoc/tk_docw.hxx>
36 
37 
38 namespace adoc {
39 
40 //************************    Cx_LineStart      ************************//
41 
42 Cx_LineStart::Cx_LineStart( TkpContext &    i_rFollowUpContext )
43     :   pDealer(0),
44         pFollowUpContext(&i_rFollowUpContext)
45 {
46 }
47 
48 void
49 Cx_LineStart::ReadCharChain( CharacterSource & io_rText )
50 {
51     uintt nCount = 0;
52     for ( char cNext = io_rText.CurChar(); cNext == 32 OR cNext == 9; cNext = io_rText.MoveOn() )
53     {
54         if (cNext == 32)
55             nCount++;
56         else if (cNext == 9)
57             nCount += 4;
58     }
59     io_rText.CutToken();
60 
61     if (nCount < 50)
62         pNewToken = new Tok_LineStart(UINT8(nCount));
63     else
64         pNewToken = new Tok_LineStart(0);
65 }
66 
67 bool
68 Cx_LineStart::PassNewToken()
69 {
70     if (pNewToken)
71     {
72         pNewToken.Release()->DealOut(*pDealer);
73         return true;
74     }
75     return false;
76 }
77 
78 TkpContext &
79 Cx_LineStart::FollowUpContext()
80 {
81     return *pFollowUpContext;
82 }
83 
84 
85 //************************    Cx_CheckStar      ************************//
86 
87 Cx_CheckStar::Cx_CheckStar( TkpContext &        i_rFollowUpContext )
88     :   pDealer(0),
89         pFollowUpContext(&i_rFollowUpContext),
90         pEnd_FollowUpContext(0),
91         bCanBeEnd(false),
92         bEndTokenFound(false)
93 {
94 }
95 
96 
97 void
98 Cx_CheckStar::ReadCharChain( CharacterSource & io_rText )
99 {
100     bEndTokenFound = false;
101     if (bCanBeEnd)
102     {
103         char cNext = jumpOver(io_rText,'*');
104         if ( NULCH == cNext )
105             throw X_Parser(X_Parser::x_UnexpectedEOF, "", String::Null_(), 0);
106         if (cNext == '/')
107         {
108             io_rText.MoveOn();
109             pNewToken = new Tok_EoDocu;
110             bEndTokenFound = true;
111         }
112         else
113         {
114             pNewToken = new Tok_DocWord(io_rText.CutToken());
115         }
116     }
117     else
118     {
119         jumpToWhite(io_rText);
120         pNewToken = new Tok_DocWord(io_rText.CutToken());
121     }
122 }
123 
124 bool
125 Cx_CheckStar::PassNewToken()
126 {
127     if (pNewToken)
128     {
129         pNewToken.Release()->DealOut(*pDealer);
130         return true;
131     }
132     return false;
133 }
134 
135 TkpContext &
136 Cx_CheckStar::FollowUpContext()
137 {
138     if (bEndTokenFound)
139         return *pEnd_FollowUpContext;
140     else
141         return *pFollowUpContext;
142 }
143 
144 
145 //************************    Cx_AtTagCompletion        ************************//
146 
147 Cx_AtTagCompletion::Cx_AtTagCompletion( TkpContext &    i_rFollowUpContext )
148     :   pDealer(0),
149         pFollowUpContext(&i_rFollowUpContext)
150 {
151 }
152 
153 void
154 Cx_AtTagCompletion::ReadCharChain( CharacterSource & io_rText )
155 {
156     jumpToWhite(io_rText);
157     csv_assert(fCur_TokenCreateFunction != 0);
158     pNewToken = (*fCur_TokenCreateFunction)(io_rText.CutToken());
159 }
160 
161 bool
162 Cx_AtTagCompletion::PassNewToken()
163 {
164     if (pNewToken)
165     {
166         pNewToken.Release()->DealOut(*pDealer);
167         return true;
168     }
169     return false;
170 }
171 
172 TkpContext &
173 Cx_AtTagCompletion::FollowUpContext()
174 {
175     return *pFollowUpContext;
176 }
177 
178 
179 
180 
181 }   // namespace adoc
182 
183