@@ -235,7 +235,7 @@ LgpToc::~LgpToc()
235235
236236bool LgpToc::addEntry (LgpHeaderEntry *entry)
237237{
238- qint32 v = lookupValue (entry->fileName ());
238+ qint16 v = lookupValue (entry->fileName ());
239239 if (v < 0 ) {
240240 return false ;
241241 }
@@ -244,20 +244,20 @@ bool LgpToc::addEntry(LgpHeaderEntry *entry)
244244 return false ;
245245 }
246246
247- _header.insert (v , entry);
247+ _header.insert (quint16 (v) , entry);
248248
249249 return true ;
250250}
251251
252252LgpHeaderEntry *LgpToc::entry (const QString &filePath) const
253253{
254- qint32 v = lookupValue (filePath);
254+ qint16 v = lookupValue (filePath);
255255 if (v < 0 ) {
256256 qDebug () << " LgpToc::entry invalid lookup" << filePath;
257257 return nullptr ; // invalid file name
258258 }
259-
260- return entry (filePath, v );
259+
260+ return entry (filePath, quint16 (v) );
261261}
262262
263263QList<LgpHeaderEntry *> LgpToc::entries (quint16 id) const
@@ -288,7 +288,7 @@ LgpHeaderEntry *LgpToc::entry(const QString &filePath, quint16 id) const
288288
289289bool LgpToc::removeEntry (const QString &filePath)
290290{
291- qint32 v = lookupValue (filePath);
291+ qint16 v = lookupValue (filePath);
292292 if (v < 0 ) {
293293 return false ; // invalid file name
294294 }
@@ -297,8 +297,8 @@ bool LgpToc::removeEntry(const QString &filePath)
297297 if (e == nullptr ) {
298298 return false ; // file not found
299299 }
300-
301- bool ok = _header.remove (v , e) > 0 ;
300+
301+ bool ok = _header.remove (quint16 (v) , e) > 0 ;
302302
303303 delete e;
304304
@@ -314,27 +314,27 @@ bool LgpToc::renameEntry(const QString &filePath, const QString &newFilePath)
314314{
315315 // Get file
316316
317- qint32 v = lookupValue (filePath);
317+ qint16 v = lookupValue (filePath);
318318 if (v < 0 ) {
319319 qWarning () << " LgpToc::renameEntry invalid filename" << filePath;
320320 return false ; // invalid file name
321321 }
322-
323- LgpHeaderEntry *e = entry (filePath, v );
322+
323+ LgpHeaderEntry *e = entry (filePath, quint16 (v) );
324324 if (e == nullptr ) {
325325 qWarning () << " LgpToc::renameEntry file not found" << filePath;
326326 return false ; // file not found
327327 }
328328
329329 // Get new file
330330
331- qint32 newV = lookupValue (newFilePath);
331+ qint16 newV = lookupValue (newFilePath);
332332 if (newV < 0 ) {
333333 qWarning () << " LgpToc::renameEntry invalid new filename" << newFilePath;
334334 return false ; // invalid file name
335335 }
336336
337- if (entry (newFilePath, newV) != nullptr ) {
337+ if (entry (newFilePath, quint16 ( newV) ) != nullptr ) {
338338 qWarning () << " LgpToc::renameEntry new file exists" << newFilePath;
339339 return false ; // file found
340340 }
@@ -397,7 +397,7 @@ LgpToc &LgpToc::operator=(const LgpToc &other)
397397 return *this ;
398398}
399399
400- qint32 LgpToc::lookupValue (const QString &filePath)
400+ qint16 LgpToc::lookupValue (const QString &filePath)
401401{
402402 int index = filePath.lastIndexOf (' /' );
403403
@@ -411,39 +411,31 @@ qint32 LgpToc::lookupValue(const QString &filePath)
411411 return -1 ;
412412 }
413413
414- char c1 = lookupValue (filePath.at (index));
415-
416- if (c1 > LOOKUP_VALUE_MAX) {
417- return -1 ;
418- }
414+ qint16 ret = lookupValue (filePath.at (index)) * LOOKUP_VALUE_MAX;
419415
420- char c2 = lookupValue ( filePath.at (index + 1 ) );
416+ QChar secondChar = filePath.at (index + 1 );
421417
422- if (c2 > LOOKUP_VALUE_MAX ) {
423- return - 1 ;
418+ if (secondChar != ' . ' ) {
419+ ret += lookupValue (secondChar) + 1 ;
424420 }
425421
426- return c1 * LOOKUP_VALUE_MAX + c2 + 1 ;
422+ return ret >= LOOKUP_TABLE_ENTRIES ? - 1 : ret ;
427423}
428424
429- quint8 LgpToc::lookupValue (const QChar &qc)
425+ qint8 LgpToc::lookupValue (const QChar &qc)
430426{
431427 char c = qc.toLower ().toLatin1 ();
432428
433- if (c == ' .' ) {
434- return 255 ;
435- }
436-
437429 if (c >= ' 0' && c <= ' 9' ) {
438- c += ' a ' - ' 0' ;
430+ return qint8 (c - ' 0' ); // Returns 0 to 9
439431 }
440-
441432 if (c == ' _' ) {
442- c = ' k ' ;
433+ return 10 ;
443434 }
444435 if (c == ' -' ) {
445- c = ' l ' ;
436+ return 11 ;
446437 }
447438
448- return c - ' a' ;
439+ // Returns -97 to 158, only 0 ('a') to 25 ('z') and 26 ('{'), 27 ('|'), 28 ('}') and 29 ('~') are valid
440+ return qint8 (c - ' a' );
449441}
0 commit comments