Rename the isSpace helper function to isWhiteSpace

Trying to enable the ESLint rule `no-shadow`, against the `master` branch, would result in a fair number of errors in the `Glyph` class in `src/core/fonts.js`.
Since the glyphs are exposed through the API, we can't very well change the `isSpace` property on `Glyph` instances. Thus the best approach seems, at least to me, to simply rename the `isSpace` helper function to `isWhiteSpace` which shouldn't cause any issues given that it's only used in the `src/core/` folder.
This commit is contained in:
Jonas Jenwald 2020-02-10 09:38:57 +01:00
parent e4758beaaa
commit c5f67300e9
8 changed files with 32 additions and 28 deletions

View File

@ -161,7 +161,7 @@ function readUint32(data, offset) {
} }
// Checks if ch is one of the following characters: SPACE, TAB, CR or LF. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
function isSpace(ch) { function isWhiteSpace(ch) {
return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a; return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
} }
@ -176,5 +176,5 @@ export {
readInt8, readInt8,
readUint16, readUint16,
readUint32, readUint32,
isSpace, isWhiteSpace,
}; };

View File

@ -42,7 +42,7 @@ import {
} from "./primitives.js"; } from "./primitives.js";
import { import {
getInheritableProperty, getInheritableProperty,
isSpace, isWhiteSpace,
MissingDataException, MissingDataException,
XRefEntryException, XRefEntryException,
XRefParseException, XRefParseException,
@ -598,7 +598,7 @@ class PDFDocument {
let ch; let ch;
do { do {
ch = stream.getByte(); ch = stream.getByte();
} while (isSpace(ch)); } while (isWhiteSpace(ch));
let str = ""; let str = "";
while (ch >= /* Space = */ 0x20 && ch <= /* '9' = */ 0x39) { while (ch >= /* Space = */ 0x20 && ch <= /* '9' = */ 0x39) {
str += String.fromCharCode(ch); str += String.fromCharCode(ch);

View File

@ -58,7 +58,11 @@ import {
getUnicodeRangeFor, getUnicodeRangeFor,
mapSpecialUnicodeValues, mapSpecialUnicodeValues,
} from "./unicode.js"; } from "./unicode.js";
import { isSpace, MissingDataException, readUint32 } from "./core_utils.js"; import {
isWhiteSpace,
MissingDataException,
readUint32,
} from "./core_utils.js";
import { FontRendererFactory } from "./font_renderer.js"; import { FontRendererFactory } from "./font_renderer.js";
import { IdentityCMap } from "./cmap.js"; import { IdentityCMap } from "./cmap.js";
import { Stream } from "./stream.js"; import { Stream } from "./stream.js";
@ -3413,7 +3417,7 @@ var Type1Font = (function Type1FontClosure() {
if (j >= signatureLength) { if (j >= signatureLength) {
// `signature` found, skip over whitespace. // `signature` found, skip over whitespace.
i += j; i += j;
while (i < streamBytesLength && isSpace(streamBytes[i])) { while (i < streamBytesLength && isWhiteSpace(streamBytes[i])) {
i++; i++;
} }
found = true; found = true;

View File

@ -43,7 +43,7 @@ import {
Name, Name,
Ref, Ref,
} from "./primitives.js"; } from "./primitives.js";
import { isSpace, MissingDataException } from "./core_utils.js"; import { isWhiteSpace, MissingDataException } from "./core_utils.js";
import { CCITTFaxStream } from "./ccitt_stream.js"; import { CCITTFaxStream } from "./ccitt_stream.js";
import { Jbig2Stream } from "./jbig2_stream.js"; import { Jbig2Stream } from "./jbig2_stream.js";
import { JpegStream } from "./jpeg_stream.js"; import { JpegStream } from "./jpeg_stream.js";
@ -270,7 +270,7 @@ class Parser {
// Ensure that we don't accidentally truncate the inline image, when the // Ensure that we don't accidentally truncate the inline image, when the
// data is immediately followed by the "EI" marker (fixes issue10388.pdf). // data is immediately followed by the "EI" marker (fixes issue10388.pdf).
if (!isSpace(ch)) { if (!isWhiteSpace(ch)) {
endOffset--; endOffset--;
} }
return stream.pos - endOffset - startPos; return stream.pos - endOffset - startPos;
@ -394,7 +394,7 @@ class Parser {
ch = stream.peekByte(); ch = stream.peekByte();
// Handle corrupt PDF documents which contains whitespace "inside" of // Handle corrupt PDF documents which contains whitespace "inside" of
// the EOD marker (fixes issue10614.pdf). // the EOD marker (fixes issue10614.pdf).
while (isSpace(ch)) { while (isWhiteSpace(ch)) {
stream.skip(); stream.skip();
ch = stream.peekByte(); ch = stream.peekByte();
} }
@ -640,7 +640,7 @@ class Parser {
// Ensure that the byte immediately following the truncated // Ensure that the byte immediately following the truncated
// endstream command is a space, to prevent false positives. // endstream command is a space, to prevent false positives.
const lastByte = stream.peekBytes(end + 1)[end]; const lastByte = stream.peekBytes(end + 1)[end];
if (!isSpace(lastByte)) { if (!isWhiteSpace(lastByte)) {
break; break;
} }
info( info(
@ -886,7 +886,7 @@ class Lexer {
if ( if (
divideBy === 10 && divideBy === 10 &&
sign === 0 && sign === 0 &&
(isSpace(ch) || ch === /* EOF = */ -1) (isWhiteSpace(ch) || ch === /* EOF = */ -1)
) { ) {
// This is consistent with Adobe Reader (fixes issue9252.pdf). // This is consistent with Adobe Reader (fixes issue9252.pdf).
warn("Lexer.getNumber - treating a single decimal point as zero."); warn("Lexer.getNumber - treating a single decimal point as zero.");

View File

@ -16,7 +16,7 @@
import { FormatError, shadow } from "../shared/util.js"; import { FormatError, shadow } from "../shared/util.js";
import { EOF } from "./primitives.js"; import { EOF } from "./primitives.js";
import { isSpace } from "./core_utils.js"; import { isWhiteSpace } from "./core_utils.js";
class PostScriptParser { class PostScriptParser {
constructor(lexer) { constructor(lexer) {
@ -193,7 +193,7 @@ class PostScriptLexer {
} }
} else if (ch === /* '%' = */ 0x25) { } else if (ch === /* '%' = */ 0x25) {
comment = true; comment = true;
} else if (!isSpace(ch)) { } else if (!isWhiteSpace(ch)) {
break; break;
} }
ch = this.nextChar(); ch = this.nextChar();

View File

@ -21,7 +21,7 @@
import { FormatError, stringToBytes, unreachable } from "../shared/util.js"; import { FormatError, stringToBytes, unreachable } from "../shared/util.js";
import { isDict } from "./primitives.js"; import { isDict } from "./primitives.js";
import { isSpace } from "./core_utils.js"; import { isWhiteSpace } from "./core_utils.js";
var Stream = (function StreamClosure() { var Stream = (function StreamClosure() {
function Stream(arrayBuffer, start, length, dict) { function Stream(arrayBuffer, start, length, dict) {
@ -1001,7 +1001,7 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
var str = this.str; var str = this.str;
var c = str.getByte(); var c = str.getByte();
while (isSpace(c)) { while (isWhiteSpace(c)) {
c = str.getByte(); c = str.getByte();
} }
@ -1026,7 +1026,7 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
input[0] = c; input[0] = c;
for (i = 1; i < 5; ++i) { for (i = 1; i < 5; ++i) {
c = str.getByte(); c = str.getByte();
while (isSpace(c)) { while (isWhiteSpace(c)) {
c = str.getByte(); c = str.getByte();
} }

View File

@ -14,7 +14,7 @@
*/ */
import { getEncoding } from "./encodings.js"; import { getEncoding } from "./encodings.js";
import { isSpace } from "./core_utils.js"; import { isWhiteSpace } from "./core_utils.js";
import { Stream } from "./stream.js"; import { Stream } from "./stream.js";
import { warn } from "../shared/util.js"; import { warn } from "../shared/util.js";
@ -524,7 +524,7 @@ var Type1Parser = (function Type1ParserClosure() {
} }
} else if (ch === /* '%' = */ 0x25) { } else if (ch === /* '%' = */ 0x25) {
comment = true; comment = true;
} else if (!isSpace(ch)) { } else if (!isWhiteSpace(ch)) {
break; break;
} }
ch = this.nextChar(); ch = this.nextChar();
@ -537,7 +537,7 @@ var Type1Parser = (function Type1ParserClosure() {
do { do {
token += String.fromCharCode(ch); token += String.fromCharCode(ch);
ch = this.nextChar(); ch = this.nextChar();
} while (ch >= 0 && !isSpace(ch) && !isSpecial(ch)); } while (ch >= 0 && !isWhiteSpace(ch) && !isSpecial(ch));
return token; return token;
}, },

View File

@ -16,7 +16,7 @@
import { Dict, Ref } from "../../src/core/primitives.js"; import { Dict, Ref } from "../../src/core/primitives.js";
import { import {
getInheritableProperty, getInheritableProperty,
isSpace, isWhiteSpace,
log2, log2,
toRomanNumerals, toRomanNumerals,
} from "../../src/core/core_utils.js"; } from "../../src/core/core_utils.js";
@ -197,18 +197,18 @@ describe("core_utils", function() {
}); });
}); });
describe("isSpace", function() { describe("isWhiteSpace", function() {
it("handles space characters", function() { it("handles space characters", function() {
expect(isSpace(0x20)).toEqual(true); expect(isWhiteSpace(0x20)).toEqual(true);
expect(isSpace(0x09)).toEqual(true); expect(isWhiteSpace(0x09)).toEqual(true);
expect(isSpace(0x0d)).toEqual(true); expect(isWhiteSpace(0x0d)).toEqual(true);
expect(isSpace(0x0a)).toEqual(true); expect(isWhiteSpace(0x0a)).toEqual(true);
}); });
it("handles non-space characters", function() { it("handles non-space characters", function() {
expect(isSpace(0x0b)).toEqual(false); expect(isWhiteSpace(0x0b)).toEqual(false);
expect(isSpace(null)).toEqual(false); expect(isWhiteSpace(null)).toEqual(false);
expect(isSpace(undefined)).toEqual(false); expect(isWhiteSpace(undefined)).toEqual(false);
}); });
}); });
}); });