1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include <adoc/cx_a_sub.hxx>
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <tokens/parseinc.hxx>
28 #include <x_parse.hxx>
29 #include <adoc/tk_docw.hxx>
30 
31 
32 namespace adoc {
33 
34 //************************	  Cx_LineStart		************************//
35 
Cx_LineStart(TkpContext & i_rFollowUpContext)36 Cx_LineStart::Cx_LineStart( TkpContext &	i_rFollowUpContext )
37 	: 	pDealer(0),
38 		pFollowUpContext(&i_rFollowUpContext)
39 {
40 }
41 
42 void
ReadCharChain(CharacterSource & io_rText)43 Cx_LineStart::ReadCharChain( CharacterSource & io_rText )
44 {
45 	uintt nCount = 0;
46 	for ( char cNext = io_rText.CurChar(); cNext == 32 OR cNext == 9; cNext = io_rText.MoveOn() )
47 	{
48 		if (cNext == 32)
49 			nCount++;
50 		else if (cNext == 9)
51 			nCount += 4;
52 	}
53 	io_rText.CutToken();
54 
55 	if (nCount < 50)
56 		pNewToken = new Tok_LineStart(UINT8(nCount));
57 	else
58 		pNewToken = new Tok_LineStart(0);
59 }
60 
61 bool
PassNewToken()62 Cx_LineStart::PassNewToken()
63 {
64 	if (pNewToken)
65 	{
66 		pNewToken.Release()->DealOut(*pDealer);
67 		return true;
68 	}
69 	return false;
70 }
71 
72 TkpContext &
FollowUpContext()73 Cx_LineStart::FollowUpContext()
74 {
75 	return *pFollowUpContext;
76 }
77 
78 
79 //************************	  Cx_CheckStar		************************//
80 
Cx_CheckStar(TkpContext & i_rFollowUpContext)81 Cx_CheckStar::Cx_CheckStar(	TkpContext &		i_rFollowUpContext )
82 	: 	pDealer(0),
83 		pFollowUpContext(&i_rFollowUpContext),
84 		pEnd_FollowUpContext(0),
85 		bCanBeEnd(false),
86 		bEndTokenFound(false)
87 {
88 }
89 
90 
91 void
ReadCharChain(CharacterSource & io_rText)92 Cx_CheckStar::ReadCharChain( CharacterSource & io_rText )
93 {
94 	bEndTokenFound = false;
95 	if (bCanBeEnd)
96 	{
97 		char cNext = jumpOver(io_rText,'*');
98 		if ( NULCH == cNext )
99 			throw X_Parser(X_Parser::x_UnexpectedEOF, "", String::Null_(), 0);
100 		if (cNext == '/')
101 		{
102 			io_rText.MoveOn();
103 			pNewToken = new Tok_EoDocu;
104 			bEndTokenFound = true;
105 		}
106 		else
107 		{
108 			pNewToken = new Tok_DocWord(io_rText.CutToken());
109 		}
110 	}
111 	else
112 	{
113 		jumpToWhite(io_rText);
114 		pNewToken = new Tok_DocWord(io_rText.CutToken());
115 	}
116 }
117 
118 bool
PassNewToken()119 Cx_CheckStar::PassNewToken()
120 {
121 	if (pNewToken)
122 	{
123 		pNewToken.Release()->DealOut(*pDealer);
124 		return true;
125 	}
126 	return false;
127 }
128 
129 TkpContext &
FollowUpContext()130 Cx_CheckStar::FollowUpContext()
131 {
132 	if (bEndTokenFound)
133 		return *pEnd_FollowUpContext;
134 	else
135 		return *pFollowUpContext;
136 }
137 
138 
139 //************************	  Cx_AtTagCompletion		************************//
140 
Cx_AtTagCompletion(TkpContext & i_rFollowUpContext)141 Cx_AtTagCompletion::Cx_AtTagCompletion( TkpContext &	i_rFollowUpContext )
142 	: 	pDealer(0),
143 		pFollowUpContext(&i_rFollowUpContext)
144 {
145 }
146 
147 void
ReadCharChain(CharacterSource & io_rText)148 Cx_AtTagCompletion::ReadCharChain( CharacterSource & io_rText )
149 {
150 	jumpToWhite(io_rText);
151 	csv_assert(fCur_TokenCreateFunction != 0);
152 	pNewToken = (*fCur_TokenCreateFunction)(io_rText.CutToken());
153 }
154 
155 bool
PassNewToken()156 Cx_AtTagCompletion::PassNewToken()
157 {
158 	if (pNewToken)
159 	{
160 		pNewToken.Release()->DealOut(*pDealer);
161 		return true;
162 	}
163 	return false;
164 }
165 
166 TkpContext &
FollowUpContext()167 Cx_AtTagCompletion::FollowUpContext()
168 {
169 	return *pFollowUpContext;
170 }
171 
172 
173 
174 
175 }   // namespace adoc
176 
177