- function getValues(param) {
- var nextQuote = /^[^"]*"/g;
- var values = [];
- nextQuote.lastIndex = 0;
- while (nextQuote.exec(param) != null) {
- var nextIndex = param.indexOf('"', nextQuote.lastIndex); // For emacs " to balance the quotes.
- values.push(param.substring(nextQuote.lastIndex, nextIndex));
- param = param.substring(nextIndex + 1);
- nextQuote.lastIndex = 0;
- }
- return values;
- }
-
- function parseRecord(key, record) {
- var keyIndex = record.indexOf(key);
- if (keyIndex < 0)
- return null;
- record = record.substring(keyIndex + key.length);
-
- var firstParen = /^\s*\(\s*/g;
- firstParen.lastIndex = 0;
- if (!firstParen.exec(record))
- return null;
- record = record.substring(firstParen.lastIndex);
-
- var parsedResult = {};
-
- // full name
- var param = /^\s*((\[[^\]]+\])|(u?)("[^"]+"))\s*/g; // For emacs " to balance the quotes.
- param.lastIndex = 0;
- var nameParam = param.exec(record);
- if (!nameParam)
- return null;
- record = record.substring(param.lastIndex);
-
- // Save the name without the quotes.
- var name = nameParam[4].slice(1, nameParam[4].length - 1);
-
- // Convert unicode characters
- if (nameParam[3] == 'u') {
- var unicode = /\\u([a-f\d]{4})/i;
- var match = unicode.exec(name);
- while (match) {
- name = name.replace(match[0], String.fromCharCode(parseInt(match[1], 16)));
- match = unicode.exec(name);
- }
- }
-
- parsedResult.name = name;
-
- var paramSeparator = /^\s*,\s*/g;
- paramSeparator.lastIndex = 0;
- if (!paramSeparator.exec(record))
- return null;
- record = record.substring(paramSeparator.lastIndex);
-
- // email
- param.lastIndex = 0;
- emailParam = param.exec(record);
- if (!emailParam)
- return null;
-
- emails = getValues(emailParam[0]);
- parsedResult.emails = emails;
- record = record.substring(param.lastIndex);
-
- paramSeparator.lastIndex = 0;
- if (!paramSeparator.exec(record))
- return parsedResult;
- record = record.substring(paramSeparator.lastIndex);
-
- // irc
- param.lastIndex = 0;
- ircParam = param.exec(record);
- if (!ircParam)
- return parsedResult;
- record = record.substring(param.lastIndex);
-
- irc = getValues(ircParam[0]);
- parsedResult.irc = irc;
- return parsedResult;
- }
-