diff --git a/lib/po.js b/lib/po.js index 2bfc3e6..a337063 100644 --- a/lib/po.js +++ b/lib/po.js @@ -119,8 +119,32 @@ PO.parse = function (data) { function extract(string) { string = trim(string); string = string.replace(/^[^"]*"|"$/g, ''); - string = string.replace(/\\"/g, '"'); - string = string.replace(/\\\\/g, '\\'); + string = string.replace(/\\([abtnvfr'"\\?]|([0-7]{3})|x([0-9a-fA-F]{2}))/g, function (match, esc, oct, hex) { + if (oct) { + return String.fromCharCode(parseInt(oct, 8)); + } + if (hex) { + return String.fromCharCode(parseInt(hex, 16)); + } + switch (esc) { + case 'a': + return '\x07'; + case 'b': + return '\b'; + case 't': + return '\t'; + case 'n': + return '\n'; + case 'v': + return '\v'; + case 'f': + return '\f'; + case 'r': + return '\r'; + default: + return esc; + } + }); return string; }