/* Javascript list insert
482666
public function insertScripts($list)
    {
        if (!is_array($list)) {
            $list = [$list];
        }
        $this->scripts = $list;
        return $this;
    }
1085078
protected void insert(List<Widget> widgets) {
        switch (type) {
            case DETACH:
                for (Widget widget : widgets) {
                    int index = widgets.indexOf(widget);
                    parent.insert(widget, index);
                }

                break;
            case DISPLAY:
                widgets.forEach(widget -> widget.getElement().getStyle().setDisplay(Style.Display.BLOCK));
                break;
        }
    }
1277325
function insert(arr, index, values) {
  [].splice.apply(arr, [index, 0].concat(values));
}
1207842
function addToList(i, L, R) {
    R[L[i + 1]] = R[i];
    L[R[i]] = L[i + 1];
    R[i] = i + 1;
    L[i + 1] = i;
}
881269
function insert(val) {
      var l = last.call(this);
      l.replace = l.attribute;
      l.dataKey = val;
      return last.call(this) && this;
    }
1135216
public static String listInsertAt(String list, int pos, String value, String delimiter, boolean ignoreEmpty) throws ExpressionException {
	if (pos < 1) throw new ExpressionException("invalid string list index [" + (pos) + "]");

	char[] del = delimiter.toCharArray();
	char c;
	StringBuilder result = new StringBuilder();
	String end = "";
	int len;

	// remove at start
	if (ignoreEmpty) {
	    outer: while (list.length() > 0) {
		c = list.charAt(0);
		for (int i = 0; i < del.length; i++) {
		    if (c == del[i]) {
			list = list.substring(1);
			result.append(c);
			continue outer;
		    }
		}
		break;
	    }
	}

	// remove at end
	if (ignoreEmpty) {
	    outer: while (list.length() > 0) {
		c = list.charAt(list.length() - 1);
		for (int i = 0; i < del.length; i++) {
		    if (c == del[i]) {
			len = list.length();
			list = list.substring(0, len - 1 < 0 ? 0 : len - 1);
			end = c + end;
			continue outer;
		    }

		}
		break;
	    }
	}

	len = list.length();
	int last = 0;

	int count = 0;
	outer: for (int i = 0; i < len; i++) {
	    c = list.charAt(i);
	    for (int y = 0; y < del.length; y++) {
		if (c == del[y]) {

		    if (!ignoreEmpty || last < i) {
			if (pos == ++count) {
			    result.append(value);
			    result.append(del[0]);
			}
		    }
		    result.append(list.substring(last, i));
		    result.append(c);
		    last = i + 1;
		    continue outer;
		}
	    }
	}
	count++;
	if (last <= len) {
	    if (pos == count) {
		result.append(value);
		result.append(del[0]);
	    }

	    result.append(list.substring(last));
	}
	if (pos > count) {
	    throw new ExpressionException("invalid string list index [" + (pos) + "], indexes go from 1 to " + (count));

	}

	return result + end;
    }
919754
function fieldInsert(elem, field, val) {
        try {
            $(exports).triggerHandler('fieldInsert', [elem, field, val]);
        } catch (err) {
            console.error(err);
        }
        var array = _getArray(elem, field);
        array.push(val);
        _currentOperation.ops.push({
            op: OP_FIELD_INSERT,
            arg: {
                _id: elem._id,
                f: field,
                e: val._id,
                i: array.indexOf(val)
            }
        });
    }
708952
function createListBlock(block, listItems) {
  var listItemContent = listItems.map(function(listItemNode) {
    var content = listItemNode.innerHTML.substr(2);
    return {content: content};
  });
  var listData = {
    format: 'html',
    listItems: listItemContent.reverse()
  };
  block.mediator.trigger("block:create", 'List', listData, block.el, { autoFocus: true });
}
533776
function (list) {
	
	for (var i=0; i < list.length; i++) {
		for (var j=0; j < l_entries.length; j++) {
			if (list[i] === l_entries[j]) {
				l_entries.splice(j, 1);
				break;
			}
		}	
	}
}
674455
function(aContexts, oBindingInfo, bSuppressInvalidate) {
			for (var i = 0; i < aContexts.length; i++) {
				this.addListItem(aContexts[i], oBindingInfo, bSuppressInvalidate);
			}
		}
545645
public static <T extends IHasIntegerId> void insertFlatList( List<T> list, TableCollectionManager<T> mng, Func1<T, Integer> parentIdGetter )
	{
		HashSet<Integer> inserted = new HashSet<>();
		
		List<T> toInsert = new ArrayList<>( list );
		List<T> postPoned = new ArrayList<>();
		List<T> inOrder = new ArrayList<>();
		
		int nbInserted;
		
		while( ! toInsert.isEmpty() )
		{
			nbInserted = 0;
			while( ! toInsert.isEmpty() )
			{
				T a = toInsert.remove( 0 );
				Integer parentId = parentIdGetter.exec( a );
				
				if( parentId==null || parentId<=0 || inserted.contains( parentId ) || mng.getRowForRecordId( parentId )!=null )
				{
					inOrder.add( a );
					inserted.add( a.getId() );
					
					nbInserted++;
				}
				else
				{
					postPoned.add( a );
				}
			}
			toInsert = postPoned;
			postPoned = new ArrayList<>();
			
			if( nbInserted == 0 && ! toInsert.isEmpty() )
			{
				GWT.log("Cannot construct full tree !");
				throw new RuntimeException( "Cannot construct full tree !" );
			}
		}
		
		for( T t : inOrder )
			mng.getDataPlug().updated( t );
	}
823566
def insert_line lineno=@current_index
      prompt = "Insert: "
      maxlen = 80
      #config={}; 
      #config[:default] = line
      #ret, str = rb_getstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
      ret, str = input_string prompt
      #ret, str = rb_getstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config)
      $log.debug " rb_getstr returned #{ret} , #{str} "
      return if ret != 0

      # pad based expect @content not list
      # remove list after a while FIXME
      @list ||= @content
      @list.insert lineno, str
      ## added handler on 2010-05-23 11:46 - undo works - tested in testlistbox.rb
      fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
      fire_dimension_changed
    end
134617
function(list, value) {
      if (_.isArray(list)) {
        for (var i = 0; i < list.length; i++) {
          var listItem = list[i];
          if (listItem.indexOf(value) === 0) {
            return true;
          }
        }
      } else {
        if (list.indexOf(value) === 0) {
          return true;
        }
      }
      return false;
    }
981955
def create_insert():
    
    insert = upkey("insert").setResultsName("action")

    # VALUES
    attrs = Group(delimitedList(var)).setResultsName("attrs")
    value_group = Group(Suppress("(") + delimitedList(value) + Suppress(")"))
    values = Group(delimitedList(value_group)).setResultsName("list_values")
    values_insert = Suppress("(") + attrs + Suppress(")") + upkey("values") + values

    # KEYWORDS
    keyword = Group(var + Suppress("=") + value)
    item = Group(Suppress("(") + delimitedList(keyword) + Suppress(")"))
    keyword_insert = delimitedList(item).setResultsName("map_values")

    return insert + into + table + (values_insert | keyword_insert) + Optional(throttle)
915704
void insert_in_list(final WorkItem new_work) {
	int i;
	boolean done = false;
	for (i = 0; i < works.size() && !done; i++) {
	    final WorkItem item = (WorkItem) works.elementAt(i);
	    if (item.wake_up_date.tv_sec < new_work.wake_up_date.tv_sec) {
		continue;
	    } else if (item.wake_up_date.tv_sec == new_work.wake_up_date.tv_sec) {
		if (item.wake_up_date.tv_usec < new_work.wake_up_date.tv_usec) {
		    continue;
		} else {
		    works.insertElementAt(new_work, i);
		    done = true;
		}
	    } else {
		works.insertElementAt(new_work, i);
		done = true;
	    }
	}
	if (i == works.size()) {
	    works.add(new_work);
	}
    }
680379
function inarray (list, item) {
  list = Object.prototype.toString.call(list) === '[object Array]' ? list : []

  var idx = -1
  var end = list.length

  while (++idx < end) {
    if (list[idx] === item) return true
  }

  return false
}
417570
def insertUnorderedList(self):
        
        cursor = self.editor().textCursor()
        currlist = cursor.currentList()
        new_style = QTextListFormat.ListDisc
        indent = 1
        
        if currlist:
            format = currlist.format()
            indent = format.indent() + 1
            style  = format.style()
            
            if style == QTextListFormat.ListDisc:
                new_style = QTextListFormat.ListCircle
            elif style == QTextListFormat.ListCircle:
                new_style = QTextListFormat.ListSquare
        
        new_format = QTextListFormat()
        new_format.setStyle(new_style)
        new_format.setIndent(indent)
        new_list = cursor.createList(new_format)
        
        self.editor().setFocus()
        
        return new_list