Column.parse constructor

Column.parse(
  1. String column, {
  2. bool ordinalOnly = false,
})

A column string is formed as:

[ordinal]<type><direction>

[ordinal] - the column no. base 1
<type>=<s|S|n|m>
s - case sensitive string sort - the default
S - case insensitive string sort
n - numeric sort
m - month name sort

If the [direction] is specified then you must also specifiy the type
[direction]=<a|d>
a - ascending - the default
d - descending

Implementation

Column.parse(String column, {bool ordinalOnly = false}) {
  final digits = _countDigits(column);

  ordinal = int.parse(column.substring(0, digits));

  if (ordinalOnly && digits < column.length) {
    throw InvalidArgumentException(
        'Expected only a column no but found: $column');
  }

  var type = 's';

  if (column.length > digits) {
    type = column.substring(digits, digits + 1);
  }

  _comparator = _typeMap[type];

  if (_comparator == null) {
    throw InvalidArgumentException('The sort type $type is not valid');
  }

  var direction = 'a';

  if (column.length > digits + 1) {
    direction = column.substring(digits + 1, digits + 2);
  }
  _sortDirection = _directionMap[direction];

  if (_sortDirection == null) {
    throw InvalidArgumentException(
        'The sort direction $direction is not valid');
  }
}