DCL 3.7.4
Loading...
Searching...
No Matches
DocSyntax.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4#include <windows.h>
5#endif
6
7#include <dcl/IniFile.h>
8
9#include "DocSyntax.h"
10
11#if __DCL_HAVE_THIS_FILE__
12#undef __THIS_FILE__
13static const char_t __THIS_FILE__[] = __T("src2html/DocSyntax.cpp");
14#endif
15
16__DCL_BEGIN_NAMESPACE
17
18DocSyntax:: DocSyntax(const String& strLanguageTitle, const String& strExtensions)
19{
20 __strLanguageTitle = strLanguageTitle;
21 strExtensions.split(' ', __listFileExtensions);
22}
23
25{
26 /*
27 debug
28 for(StringArray::Iterator it = __listReservedWords.begin();
29 it != __listReservedWords.end(); it++
30 ) {
31 TRACE1(L"|%ls|\n", (*it).cstr());
32 }
33 */
34}
35
36bool DocSyntax::load(const wchar_t* pszFileName)
37{
38 try {
39 IniFile file(pszFileName);
40
41 __strDelimeters = file.getString(__strLanguageTitle, L"DELIMITER");
42 __strQuotations = file.getString(__strLanguageTitle, L"QUOTATION");
43 __strLineComment = file.getString(__strLanguageTitle, L"LINECOMMENT");
44 __strCommentOn = file.getString(__strLanguageTitle, L"COMMENTON");
45 __strCommentOff = file.getString(__strLanguageTitle, L"COMMENTOFF");
46 __strEscapeChars = file.getString(__strLanguageTitle, L"ESCAPE");
47 String strTemp = file.getString(__strLanguageTitle, L"CASE_SENSITIVE");
48 if (!strTemp.compareNoCase(L"true"))
49 __bCaseSensitive = true;
50 else
51 __bCaseSensitive = false;
52
53 __nTabWidth = file.getInteger(__strLanguageTitle, L"TAB_WIDTH", 0);
54 strTemp = file.getString(__strLanguageTitle, L"RESERVED_WORD");
55 strTemp.split(' ', __listReservedWords);
56
57 file.close();
58 }
59 catch (Exception* _e) {
60 __DCL_TRACE1(L"Syntax File Load Error : %ls\n", _e->toStringAll().data());
61 _e->destroy();
62 return false;
63 }
64 return true;
65}
66
67bool DocSyntax::isValidExtension(const wchar_t* pszFileExt) const
68{
69 for(StringArray::ConstIterator it = __listFileExtensions.begin();
70 it != __listFileExtensions.end(); it++
71 ) {
72 if (!((*it).compareNoCase(pszFileExt)))
73 return true;
74 }
75 return false;
76}
77
78bool DocSyntax::isLineComment(const wchar_t* pch, size_t nLength) const
79{
80 if (nLength == __strLineComment.length())
81 return __strLineComment.compare(pch, nLength) == 0;
82
83 return false;
84}
85
86bool DocSyntax::isCommentOn(const wchar_t* pch, size_t nLength) const
87{
88 if (nLength == __strCommentOn.length())
89 return __strCommentOn.compare(pch, nLength) == 0;
90
91 return false;
92}
93
94bool DocSyntax::isCommentOff(const wchar_t* pch, size_t nLength) const
95{
96 if (nLength >= __strCommentOff.length()) {
97 return __strCommentOff.compare(pch + nLength - __strCommentOff.length(),
98 __strCommentOff.length()) == 0;
99 }
100
101 return false;
102}
103
104bool DocSyntax::isReservedWord(const wchar_t* pch, size_t nLength) const
105{
106 if (__bCaseSensitive) {
107 for(StringArray::ConstIterator it = __listReservedWords.begin();
108 it != __listReservedWords.end(); it++
109 ) {
110 if ((*it).length() == nLength
111 && (*it).compare(pch, nLength) == 0) {
112 return true;
113 }
114 }
115 }
116 else {
117 for(StringArray::ConstIterator it = __listReservedWords.begin();
118 it != __listReservedWords.end(); it++
119 ) {
120 if ((*it).length() == nLength
121 && (*it).compareNoCase(pch, nLength) == 0
122 ) {
123 return true;
124 }
125 }
126 }
127
128 return false;
129}
130
131__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
wchar_t char_t
Definition Config.h:247
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
#define __T(str)
Definition Object.h:60
bool isReservedWord(const wchar_t *pch, size_t nLength) const
int __nTabWidth
Definition DocSyntax.h:31
StringArray __listReservedWords
Definition DocSyntax.h:32
String __strEscapeChars
Definition DocSyntax.h:29
bool isCommentOff(const wchar_t *pch, size_t nLength) const
Definition DocSyntax.cpp:94
bool load(const wchar_t *pszFileName)
Definition DocSyntax.cpp:36
virtual ~DocSyntax()
Definition DocSyntax.cpp:24
bool isValidExtension(const wchar_t *pszFileExt) const
Definition DocSyntax.cpp:67
bool isLineComment(const wchar_t *pch, size_t nLength) const
Definition DocSyntax.cpp:78
bool __bCaseSensitive
Definition DocSyntax.h:30
DocSyntax(const String &strLanguageTitle, const String &strExtensions)
Definition DocSyntax.cpp:18
String __strLineComment
Definition DocSyntax.h:26
String __strCommentOff
Definition DocSyntax.h:28
bool isCommentOn(const wchar_t *pch, size_t nLength) const
Definition DocSyntax.cpp:86
String __strLanguageTitle
Definition DocSyntax.h:21
String __strDelimeters
Definition DocSyntax.h:24
StringArray __listFileExtensions
Definition DocSyntax.h:22
String __strQuotations
Definition DocSyntax.h:25
String __strCommentOn
Definition DocSyntax.h:27
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45