Skip to content

Commit

Permalink
Have a separate testing regex for JavaScript engines that retain matc…
Browse files Browse the repository at this point in the history
…h location.
  • Loading branch information
RubenVerborgh committed Dec 3, 2013
1 parent f6b7233 commit 61ef416
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/N3Writer.js
Expand Up @@ -8,16 +8,10 @@ var RDF_PREFIX = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
RDF_TYPE = RDF_PREFIX + 'type';

// Characters in literals that require escaping
var literalEscape = /["\\\t\n\r\b\f]/g;
var literalReplacements = {
'\\': '\\\\',
'"' : '\\"',
'\t': '\\t',
'\n': '\\n',
'\r': '\\r',
'\b': '\\b',
'\f': '\\f',
};
var literalEscape = /["\\\t\n\r\b\f]/,
literalEscapeAll = /["\\\t\n\r\b\f]/g,
literalReplacements = { '\\': '\\\\', '"': '\\"', '\t': '\\t',
'\n': '\\n', '\r': '\\r', '\b': '\\b', '\f': '\\f' };

// ## Constructor
function N3Writer(outputStream, prefixes) {
Expand Down Expand Up @@ -70,7 +64,7 @@ N3Writer.prototype = {
// ### `_writeLiteral` writes a literal to the output stream
_writeLiteral: function (value, type, language, done) {
if (literalEscape.test(value)) {
value = value.replace(literalEscape, function (match) {
value = value.replace(literalEscapeAll, function (match) {
return literalReplacements[match];
});
}
Expand Down

0 comments on commit 61ef416

Please sign in to comment.