@@ -91,11 +91,7 @@ function readEntityExp(xmlData, i) {
91
91
entityName += xmlData [ i ] ;
92
92
i ++ ;
93
93
}
94
-
95
- // Validate entity name
96
- if ( ! validateEntityName ( entityName ) ) {
97
- throw new Error ( `Invalid entity name: "${ entityName } "` ) ;
98
- }
94
+ validateEntityName ( entityName ) ;
99
95
100
96
// Skip whitespace after entity name
101
97
i = skipWhitespace ( xmlData , i ) ;
@@ -108,22 +104,9 @@ function readEntityExp(xmlData, i) {
108
104
}
109
105
110
106
// Read entity value (internal entity)
111
- const quoteChar = xmlData [ i ] ;
112
- if ( quoteChar !== '"' && quoteChar !== "'" ) {
113
- throw new Error ( `Expected quoted string, found "${ quoteChar } "` ) ;
114
- }
115
- i ++ ;
116
-
117
107
let entityValue = "" ;
118
- while ( i < xmlData . length && xmlData [ i ] !== quoteChar ) {
119
- entityValue += xmlData [ i ] ;
120
- i ++ ;
121
- }
122
-
123
- if ( xmlData [ i ] !== quoteChar ) {
124
- throw new Error ( "Unterminated entity value" ) ;
125
- }
126
-
108
+ [ i , entityValue ] = readIdentifierVal ( xmlData , i , "entity" ) ;
109
+ i -- ;
127
110
return [ entityName , entityValue , i ] ;
128
111
}
129
112
@@ -137,11 +120,7 @@ function readNotationExp(xmlData, i) {
137
120
notationName += xmlData [ i ] ;
138
121
i ++ ;
139
122
}
140
-
141
- // Validate notation name
142
- if ( ! validateEntityName ( notationName ) ) {
143
- throw new Error ( `Invalid notation name: "${ notationName } "` ) ;
144
- }
123
+ validateEntityName ( notationName ) ;
145
124
146
125
// Skip whitespace after notation name
147
126
i = skipWhitespace ( xmlData , i ) ;
@@ -161,18 +140,18 @@ function readNotationExp(xmlData, i) {
161
140
let systemIdentifier = null ;
162
141
163
142
if ( identifierType === "PUBLIC" ) {
164
- [ i , publicIdentifier ] = readIdentifierVal ( xmlData , i ) ;
143
+ [ i , publicIdentifier ] = readIdentifierVal ( xmlData , i , "publicIdentifier" ) ;
165
144
166
145
// Skip whitespace after public identifier
167
146
i = skipWhitespace ( xmlData , i ) ;
168
147
169
148
// Optionally read system identifier
170
149
if ( xmlData [ i ] === '"' || xmlData [ i ] === "'" ) {
171
- [ i , systemIdentifier ] = readIdentifierVal ( xmlData , i ) ;
150
+ [ i , systemIdentifier ] = readIdentifierVal ( xmlData , i , "systemIdentifier" ) ;
172
151
}
173
152
} else if ( identifierType === "SYSTEM" ) {
174
153
// Read system identifier (mandatory for SYSTEM)
175
- [ i , systemIdentifier ] = readIdentifierVal ( xmlData , i ) ;
154
+ [ i , systemIdentifier ] = readIdentifierVal ( xmlData , i , "systemIdentifier" ) ;
176
155
177
156
if ( ! systemIdentifier ) {
178
157
throw new Error ( "Missing mandatory system identifier for SYSTEM notation" ) ;
@@ -182,7 +161,7 @@ function readNotationExp(xmlData, i) {
182
161
return { notationName, publicIdentifier, systemIdentifier, index : -- i } ;
183
162
}
184
163
185
- function readIdentifierVal ( xmlData , i ) {
164
+ function readIdentifierVal ( xmlData , i , type ) {
186
165
let identifierVal = "" ;
187
166
const startChar = xmlData [ i ] ;
188
167
if ( startChar !== '"' && startChar !== "'" ) {
@@ -196,7 +175,7 @@ function readIdentifierVal(xmlData, i) {
196
175
}
197
176
198
177
if ( xmlData [ i ] !== startChar ) {
199
- throw new Error ( " Unterminated identifier" ) ;
178
+ throw new Error ( ` Unterminated ${ type } value` ) ;
200
179
}
201
180
i ++ ;
202
181
return [ i , identifierVal ] ;
0 commit comments