/*
A helper function to return a mapping {line, column} object for a given input
line and column, and optionally a module ID.
15496
function getOriginalPositionFor(lineNumber, columnNumber, moduleIds, context) {
  const position = getOriginalPositionDetailsFor(
    lineNumber,
    columnNumber,
    moduleIds,
    context,
  );
  if (position.functionName) {
    position.name = position.functionName;
  }
  delete position.functionName;
  return position;
}
1140146
function mappingToTable(mapping) {
  const mp = mapping.hasOwnProperty('field') ? singleToMulti(mapping) : mapping;
  const keyField = {key: mp.key, format: 'text'};
  const data = {
    fields: [keyField].concat(mp.fields),
    records: Object.entries(mp.mapping).map(entry => {
      const rcd = {};
      rcd[mp.key] = entry[0];
      mp.fields.forEach((f, i) => {
        rcd[f.key] = entry[1][i];
      });
      return rcd;
    })
  };
  return data;
}
339013
function columnToSQL(col) {
	var sql = "`" + col.name + "` ";

	sql += nrutil.typeToSQL(col.type);

	if (col['additional']) {
		sql += ' ' + col['additional'];
	}

	if (!col['allow_null']) {
		sql += " NOT NULL";
	}

	if (col['default_value'] !== undefined) {
		var def = col['default_value']

		sql += " DEFAULT " + nrutil.serialize(def);
	}

	if (col.type == 'primary_key') {
		sql += " PRIMARY KEY AUTO_INCREMENT";
	}

	return sql;
}
827989
function columnsToSQL(columns) {
    return columns
        .map(column => {
            let str = exprToSQL(column.expr);

            if (column.as !== null) {
                str += ' AS ';
                if (column.as.match(/^[a-z_][0-9a-z_]*$/i)) str += identifierToSql(column.as);
                else str += '"' + column.as + '"';
            }

            return str;
        })
        .join(', ');
}
120903
private Object extractValue(String line, int lineNumber, ColumnInfo<Object> columnInfo, String columnStr,
			int linePos, Object target, ParseError parseError) {

		Converter<Object, ?> converter = columnInfo.getConverter();
		if (alwaysTrimInput || columnInfo.isTrimInput() || converter.isAlwaysTrimInput()) {
			columnStr = columnStr.trim();
		}
		if (columnStr.isEmpty() && columnInfo.getDefaultValue() != null) {
			columnStr = columnInfo.getDefaultValue();
		}
		if (columnStr.isEmpty() && columnInfo.isMustNotBeBlank()) {
			parseError.setErrorType(ErrorType.MUST_NOT_BE_BLANK);
			parseError.setMessage("field '" + columnInfo.getFieldName() + "' must not be blank");
			assignParseErrorFields(parseError, columnInfo, columnStr);
			parseError.setLinePos(linePos);
			return null;
		}

		try {
			return converter.stringToJava(line, lineNumber, linePos, columnInfo, columnStr, parseError);
		} catch (ParseException e) {
			parseError.setErrorType(ErrorType.INVALID_FORMAT);
			parseError.setMessage("field '" + columnInfo.getFieldName() + "' parse-error: " + e.getMessage());
			parseError.setLinePos(linePos);
			return null;
		} catch (Exception e) {
			parseError.setErrorType(ErrorType.INTERNAL_ERROR);
			parseError.setMessage("field '" + columnInfo.getFieldName() + "' error: " + e.getMessage());
			parseError.setLinePos(linePos);
			return null;
		}
	}
189533
function buildRowMapping(mapping, columns, yOffset) {
  for (let i = 0; i < columns.length; i++) {
    const {icon, xOffset} = columns[i];
    const id = getIconId(icon);
    mapping[id] = Object.assign({}, icon, {
      x: xOffset,
      y: yOffset
    });
  }
}
319565
def mapToAbsPosition(self, line, column):
        
        block = self.document().findBlockByNumber(line)
        if not block.isValid():
            raise IndexError("Invalid line index %d" % line)
        if column >= block.length():
            raise IndexError("Invalid column index %d" % column)
        return block.position() + column
987172
@Override
    public Object map(Object input) {
        List<Object> ret = new ArrayList<>();
        Long l = (Long) input;
        for (DerivedColumn d : derivedColumns) {
            switch (d.columnType) {
                case String:
                    ret.add(d.dateTimeFormatter.print(l));
                    break;
                case Integer:
                    DateTime dt = new DateTime(l, inputTimeZone);
                    ret.add(dt.get(d.fieldType));
                    break;
                default:
                    throw new IllegalStateException("Unexpected column type: " + d.columnType);
            }
        }

        return ret;
    }
1319532
def ColumnItem(name='', key=None, **kwargs):
    ''
    return Column(name,
            expr=key if key is not None else name,
            getter=lambda col,row: getitemdef(row, col.expr),
            setter=lambda col,row,val: setitem(row, col.expr, val),
            **kwargs)
1038786
function(line) {
        var newLine;

        // ex: [foo <- 1,2,3]
        // [        opening array
        //   (.*)   $1 array to concat into
        //   (<-)   $2
        //   (.*)   $3 content to be merged
        // ]        closing array
        var regexArr = /\[(.*)(\<\-)(.*)\]/;

        // ex: {foo <- foo: true, bar: 2}
        // {        opening object
        //   (.*)   $1 obj to merge into
        //   (<-)   $2
        //   (.*)   $3 content to be merged
        // }        closing object
        var regexObj = /\{(.*)(\<\-)(.*)\}/;

        newLine = line.replace(regexArr, function($0, $1, $2, $3) {
            return $1.trim() + '.concat([' + $3 + ']);';
        });

        return newLine.replace(regexObj, function($0, $1, $2, $3) {
            return $1.trim() + '.merge({' + $3 + '});';
        });
    }
78024
def applyKeyMapping(self, mapping):
		
		for coltype, colname in zip(self.columntypes, self.columnnames):
			if coltype in ligolwtypes.IDTypes and (self.next_id is None or colname != self.next_id.column_name):
				column = self.getColumnByName(colname)
				for i, old in enumerate(column):
					try:
						column[i] = mapping[old]
					except KeyError:
						pass
555788
function parseSnmpLine(line) {
        if (typeof line !== 'string') {
            throw new Error("Data is not in string format");
        }

        var data = line.trim();
        var errString = 'No Such Object available on this agent at this OID';

        if (data.indexOf(errString) >= 0) {
            throw new Error(data);
        }

        // Messages that occur as a result of doing MIB translation on output
        // We exclude "Cannot find module" and "Did not find *" messages because
        // in some cases we walk the whole tree and there are may be vendor-specific
        // mibs that we don't have installed.
        if (data.indexOf('MIB search path') >= 0 ||
            data.indexOf('Cannot find module') >= 0 ||
            data.indexOf('Did not find') >= 0) {

            return;
        }

        var parsed = data.split(' ');

        return {
            oid: parsed.shift(),
            value: parsed.join(' ').replace(/["']/g, '')   //remove "" in '"name"'
        };
    }
297539
function(str){
    var lines = str.match(/\n/g)
      , idx = str.lastIndexOf('\n');

    if (lines) this.lineno += lines.length;
    this.column = ~idx
      ? str.length - idx
      : this.column + str.length;
  }
922437
public JdbcMapperBuilder<T> addMapping(final String column, final int index, final int sqlType) {
        addMapping(column, index, sqlType, FieldMapperColumnDefinition.<JdbcColumnKey>identity());
        return this;
    }
1038346
def map_input_output(item, api):
    
    if isinstance(item, list):
        return [map_input_output(it, api) for it in item]

    elif isinstance(item, dict) and 'class' in item:
        if item['class'].lower() == 'file':
            return File(id=item['path'], api=api)

    else:
        return item
211363
function injectLineNumbers(tokens, idx, options, env, slf) {
    var line;
    if (tokens[idx].map && tokens[idx].level === 0) {
      line = tokens[idx].map[0];
      tokens[idx].attrJoin('class', 'line');
      tokens[idx].attrSet('data-line', String(line));
    }
    return slf.renderToken(tokens, idx, options, env, slf);
  }
11473
function columnsToSQL(columns, tables) {
  if (!columns) return
  const baseTable = Array.isArray(tables) && tables[0]
  let isDual = false
  if (baseTable && baseTable.type === 'dual') isDual = true
  return columns
    .map(column => {
      const { expr } = column
      if (isDual) expr.isDual = isDual
      let str = exprToSQL(expr)
      if (column.as !== null) {
        str = `${str} AS `
        if (column.as.match(/^[a-z_][0-9a-z_]*$/i)) str = `${str}${identifierToSql(column.as)}`

        else str = `${str}\`${column.as}\``
      }

      return str
    })
    .join(', ')
}