UNPKG

molstar

Version:

A comprehensive macromolecular library.

47 lines (46 loc) 1.82 kB
/** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { ColumnHelpers } from '../../../../../mol-data/db'; import { trimStr } from '../tokenizer'; import { parseIntSkipLeadingWhitespace, parseFloatSkipLeadingWhitespace } from '../number-parser'; export function FixedColumnProvider(lines) { return function (offset, width, type) { return FixedColumn(lines, offset, width, type); }; } export function FixedColumn(lines, offset, width, schema) { var data = lines.data, indices = lines.indices, rowCount = lines.count; var type = schema.valueType; var value = type === 'str' ? function (row) { var s = indices[2 * row] + offset, le = indices[2 * row + 1]; if (s >= le) return ''; var e = s + width; if (e > le) e = le; return trimStr(data, s, e); } : type === 'int' ? function (row) { var s = indices[2 * row] + offset; if (s > indices[2 * row + 1]) return 0; return parseIntSkipLeadingWhitespace(data, s, s + width); } : function (row) { var s = indices[2 * row] + offset; if (s > indices[2 * row + 1]) return 0; return parseFloatSkipLeadingWhitespace(data, s, s + width); }; return { schema: schema, __array: void 0, isDefined: true, rowCount: rowCount, value: value, valueKind: function (row) { return 0 /* Column.ValueKind.Present */; }, toArray: function (params) { return ColumnHelpers.createAndFillArray(rowCount, value, params); }, areValuesEqual: function (rowA, rowB) { return value(rowA) === value(rowB); } }; }