123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var error_1 = require("../error");
- var validate_1 = require("../validate");
- var XmlCharRef = (function () {
- function XmlCharRef(parent, validation, options) {
- this._hex = false;
- this._validation = validation;
- this._parent = parent;
- this.char = options.char;
- if (!(0, validate_1.isUndefined)(options.hex)) {
- this.hex = options.hex;
- }
- }
- Object.defineProperty(XmlCharRef.prototype, "char", {
-
- get: function () {
- return this._char;
- },
-
- set: function (char) {
- if (this._validation && !(0, validate_1.validateSingleChar)(char)) {
- throw new Error((0, error_1.getContext)(this.up()) + ": character reference"
- + (" \"" + char + "\" should reference a single character,")
- + " and this character should be allowed in XML");
- }
- this._char = char;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(XmlCharRef.prototype, "hex", {
-
- get: function () {
- return this._hex;
- },
-
- set: function (hex) {
- this._hex = hex;
- },
- enumerable: false,
- configurable: true
- });
-
- XmlCharRef.prototype.toString = function () {
- var char;
- if (this._char.length === 1) {
- char = this._char.charCodeAt(0);
- }
- else {
- var first = this._char.charCodeAt(0);
- if (first >= 0xD800 && first <= 0xDBFF && this._char.length > 1) {
- var second = this._char.charCodeAt(1);
- if (second >= 0xDC00 && second <= 0xDFFF) {
- char = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
- }
- else {
- throw new Error((0, error_1.getContext)(this.up()) + ": character"
- + (" reference \"" + this.char + "\" should")
- + " reference a valid Unicode character");
- }
- }
- else {
- char = first;
- }
- }
- if (this._hex) {
- return "&#x" + char.toString(16) + ";";
- }
- else {
- return "&#" + char + ";";
- }
- };
-
- XmlCharRef.prototype.up = function () {
- return this._parent;
- };
- return XmlCharRef;
- }());
- exports.default = XmlCharRef;
|