| 1 | /*! |
| 2 | * VisualEditor DataString class. |
| 3 | * |
| 4 | * @copyright See AUTHORS.txt |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * Wrapper class to read document data as a plain text string. |
| 9 | * |
| 10 | * @class |
| 11 | * @extends unicodeJS.TextString |
| 12 | * @constructor |
| 13 | * @param {Array} data Document data |
| 14 | */ |
| 15 | ve.dm.DataString = function VeDmDataString( data ) { |
| 16 | this.data = data; |
| 17 | }; |
| 18 | |
| 19 | /* Inheritance */ |
| 20 | |
| 21 | OO.inheritClass( ve.dm.DataString, unicodeJS.TextString ); |
| 22 | |
| 23 | /** |
| 24 | * Reads the character from the specified position in the data. |
| 25 | * |
| 26 | * @param {number} position Position in data to read from |
| 27 | * @return {string|null} Character at position, or null if not text |
| 28 | */ |
| 29 | ve.dm.DataString.prototype.read = function ( position ) { |
| 30 | const dataAt = this.data[ position ]; |
| 31 | // Check data is present at position and is not an element |
| 32 | if ( dataAt !== undefined && dataAt.type === undefined ) { |
| 33 | return typeof dataAt === 'string' ? dataAt : dataAt[ 0 ]; |
| 34 | } else { |
| 35 | return null; |
| 36 | } |
| 37 | }; |