1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sal/types.h>
24 #include <tools/stream.hxx>
28 enum class SVTOKENTYPE
{ Empty
, Comment
,
36 friend class SvTokenStream
;
37 sal_uInt64 nLine
, nColumn
;
45 SvStringHashEntry
* pHash
;
49 SvToken( const SvToken
& rObj
) = delete;
51 SvToken
& operator = ( const SvToken
& rObj
);
53 OString
GetTokenAsString() const;
55 void SetLine( sal_uInt64 nLineP
) { nLine
= nLineP
; }
56 sal_uInt64
GetLine() const { return nLine
; }
58 void SetColumn( sal_uInt64 nColumnP
) { nColumn
= nColumnP
; }
59 sal_uInt64
GetColumn() const { return nColumn
; }
61 bool IsComment() const { return nType
== SVTOKENTYPE::Comment
; }
62 bool IsInteger() const { return nType
== SVTOKENTYPE::Integer
; }
63 bool IsString() const { return nType
== SVTOKENTYPE::String
; }
64 bool IsBool() const { return nType
== SVTOKENTYPE::Bool
; }
65 bool IsIdentifierHash() const
66 { return nType
== SVTOKENTYPE::HashId
; }
67 bool IsIdentifier() const
69 return nType
== SVTOKENTYPE::Identifier
70 || nType
== SVTOKENTYPE::HashId
;
72 bool IsChar() const { return nType
== SVTOKENTYPE::Char
; }
73 bool IsEof() const { return nType
== SVTOKENTYPE::EndOfFile
; }
75 const OString
& GetString() const
77 return IsIdentifierHash()
81 sal_uInt64
GetNumber() const { return nLong
; }
82 bool GetBool() const { return bBool
; }
83 char GetChar() const { return cChar
; }
85 void SetHash( SvStringHashEntry
* pHashP
)
86 { pHash
= pHashP
; nType
= SVTOKENTYPE::HashId
; }
87 bool Is( SvStringHashEntry
const * pEntry
) const
88 { return IsIdentifierHash() && pHash
== pEntry
; }
91 inline SvToken::SvToken()
94 , nType( SVTOKENTYPE::Empty
)
100 sal_uInt64 nLine
, nColumn
;
102 char c
; // next character
103 static const sal_uInt16 nTabSize
= 4; // length of tabulator
108 std::unique_ptr
<SvFileStream
> pInStream
;
110 std::vector
<std::unique_ptr
<SvToken
> > aTokList
;
111 std::vector
<std::unique_ptr
<SvToken
> >::iterator pCurToken
;
118 char GetFastNextChar()
120 return (nBufPos
< aBufStr
.getLength())
125 void FillTokenList();
126 sal_uInt64
GetNumber();
127 bool MakeToken( SvToken
& );
128 bool IsEof() const { return pInStream
->eof(); }
131 sal_uInt32 n
= Tell();
137 // if end of line spare calculation
143 nColumn
+= aBufStr
[n
++] == '\t' ? nTabSize
: 1;
147 SvTokenStream( const OUString
& rFileName
);
150 const OUString
& GetFileName() const { return aFileName
; }
151 SvStream
& GetStream() { return *pInStream
; }
153 SvToken
& GetToken_PrevAll()
155 std::vector
<std::unique_ptr
<SvToken
> >::iterator pRetToken
= pCurToken
;
157 // current iterator always valid
158 if(pCurToken
!= aTokList
.begin())
161 return *(*pRetToken
);
164 SvToken
& GetToken_Next()
166 std::vector
<std::unique_ptr
<SvToken
> >::iterator pRetToken
= pCurToken
++;
168 if (pCurToken
== aTokList
.end())
169 pCurToken
= pRetToken
;
173 return *(*pRetToken
);
176 SvToken
& GetToken() const { return *(*pCurToken
); }
178 bool ReadIf( char cChar
)
180 if( GetToken().IsChar() && cChar
== GetToken().GetChar() )
189 void ReadIfDelimiter()
191 if( GetToken().IsChar()
192 && (';' == GetToken().GetChar()
193 || ',' == GetToken().GetChar()) )
199 sal_uInt32
Tell() const { return pCurToken
-aTokList
.begin(); }
201 void Seek( sal_uInt32 nPos
)
203 pCurToken
= aTokList
.begin() + nPos
;
209 pCurToken
= aTokList
.begin()+nMaxPos
;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */