2021-08-17 19:25:27 +00:00
|
|
|
class SubjectParser
|
|
|
|
{
|
2021-08-17 19:38:20 +00:00
|
|
|
static create = () => new this();
|
|
|
|
|
|
|
|
|
2021-08-17 19:25:27 +00:00
|
|
|
parse(subject)
|
|
|
|
{
|
|
|
|
// Possible formats:
|
|
|
|
// Title
|
|
|
|
// |id| Title
|
|
|
|
// |id,sound| Title
|
|
|
|
// |,sound| Title
|
|
|
|
const match = subject.match(/^(?:\|([^,]*?)(?:,(.+?)){0,1}\|){0,1}\s*(.+?)$/m);
|
|
|
|
|
|
|
|
if (match == null)
|
|
|
|
return {
|
|
|
|
id: subject,
|
|
|
|
sound: null,
|
|
|
|
title: subject
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: match[1] || match[3],
|
|
|
|
sound: match[2] || null,
|
|
|
|
title: match[3]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = SubjectParser;
|