1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Simplify some regular expressions

There's a fair number of regular expressions througout the code-base which are slightly more verbose than strictly necessary, in particular:
 - We have a lot of regular expressions that use `[0-9]` explicitly, and those can be simplified to use `\d` instead.
 - We have one instance of a regular expression containing a `A-Za-z0-9_` sequence, which can be simplified to use `\w` instead.
This commit is contained in:
Jonas Jenwald 2021-09-02 11:41:20 +02:00
parent 0a366dda6a
commit c42887221a
8 changed files with 35 additions and 38 deletions

View file

@ -117,8 +117,8 @@ const TOKEN = {
};
const hexPattern = /^[uU]([0-9a-fA-F]{4,8})/;
const numberPattern = /^[0-9]*(?:\.[0-9]*)?(?:[Ee][+-]?[0-9]+)?/;
const dotNumberPattern = /^[0-9]*(?:[Ee][+-]?[0-9]+)?/;
const numberPattern = /^\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?/;
const dotNumberPattern = /^\d*(?:[Ee][+-]?\d+)?/;
const eolPattern = /[\r\n]+/;
const identifierPattern = new RegExp("^[\\p{L}_$!][\\p{L}\\p{N}_$]*", "u");

View file

@ -657,7 +657,7 @@ class Barcode extends XFAObject {
"shift-jis",
"ucs-2",
"utf-16",
].includes(k) || k.match(/iso-8859-[0-9]{2}/),
].includes(k) || k.match(/iso-8859-\d{2}/),
});
this.checksum = getStringOption(attributes.checksum, [
"none",
@ -5274,7 +5274,7 @@ class Submit extends XFAObject {
"shift-jis",
"ucs-2",
"utf-16",
].includes(k) || k.match(/iso-8859-[0-9]{2}/),
].includes(k) || k.match(/iso-8859-\d{2}/),
});
this.use = attributes.use || "";
this.usehref = attributes.usehref || "";

View file

@ -22,7 +22,7 @@ const dimConverters = {
in: x => x * 72,
px: x => x,
};
const measurementPattern = /([+-]?[0-9]+\.?[0-9]*)(.*)/;
const measurementPattern = /([+-]?\d+\.?\d*)(.*)/;
function stripQuotes(str) {
if (str.startsWith("'") || str.startsWith('"')) {