Check and split on single new line occurrences

@param string $insert
@param boolean $newlines Append multiple new lines

@return array
491951
public function splitOnSingleNewlineOccurrences(string $insert, bool $newlines = false): array
    {
        $new_deltas = [];

        $single_matches = preg_split("/[\n]{1,}/", $insert);

        foreach ($single_matches as $k => $sub_match) {

            $final_append = null;
            if ($k === count($single_matches) - 1 && $newlines === true) {
                $final_append = "\n\n";
            }

            $append = null;
            if ($k !== count($single_matches) - 1) {
                $append = "\n";
            }

            $new_deltas[] = [
                'insert' => $sub_match . ($final_append !== null ? $final_append : $append)
            ];
        }

        return $new_deltas;
    }
579848
public function insert($table, $data, $statements)
    {
        $input = [
            'columns' => '',
            'values' => ''
        ];

        $query = 'INSERT INTO `' . $table . '` ';

        foreach ($data as $column => $value) {
            $input['columns'] .= $column . ', ';

            $value = (is_null($statements) && is_string($value)) ? "'$value'" : $value;

            $input['values'] .= $value . ', ';
        }

        $query .= '(' . rtrim(trim($input['columns']), ',') . ') ';

        $query .= 'VALUES (' . rtrim(trim($input['values']), ',') . ')';

        return $this->query($query, 'INSERT');
    }
876014
protected function insertSingle(string $table, array $values): ?array {
		
		// this one is far less complex that our insertMultiple above.  we'll build our
		// statement and then pass control over to insertExecute which'll actually perform
		// our statement and return the appropriate results up the call stack.
		
		$statement = $this->insertBuild($table, $values);
		return $this->insertExecute($statement, $values);
	}
589834
public static function numberFormatGeral($n, $loop, $insert = 0)
    {
        // Removo os caracteras a mais do que o pad solicitado caso a string seja maior
        $n = mb_substr(self::onlyNumbers($n), 0, $loop);
        return str_pad($n, $loop, $insert, STR_PAD_LEFT);
    }
24358
protected function writeLines($lines, $newline = false) {
		$docblock = '';
		if ($newline) {
			$docblock .= " *\n";
		}

		foreach ($lines as $line) {
			if (strpos($line, "\n")) {
				$sublines = explode("\n", $line);
				$line = array_shift($sublines);
				$docblock .= ' * ' . $line . "\n";
				$docblock .= $this->writeLines($sublines);
			} else {
				$docblock .= ' * ' . $line . "\n";
			}
		}
		
		return $docblock;
	}
862312
public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if ($this->isNewRecord) {
                $this->key = get_current_cart_key();
                $check = Cart::find()
                    ->where(['product' => $this->product])
                    ->andWhere(['key' => $this->key])
                    ->one();
                if (!empty($check)) {
                    $this->quantity += $check->quantity;
                    Cart::deleteAll([
                        'key' => $this->key,
                        'product' => $this->product
                    ]);
                }
            }
            return true;
        }

        return false;
    }
387630
def go_to_new_line(self):
        """"""
        self.stdkey_end(False, False)
        self.insert_text(self.get_line_separator())
1223753
public function insertBlock($sLine, $sColumn, $eLine, $eColumn)
    {
        if ($sLine === $eLine) {
            if (isset($this->lines[$sLine])) {
                $this->lines[$sLine]->insertBlock($sColumn, $eColumn - $sColumn);
            }
        } else {
            $dLines = $eLine - $sLine;
            $shifts = [];
            foreach ($this->lines as $nl => $line) {
                if ($nl > $sLine) {
                    $newNL = $nl + $dLines;
                    $shifts[$newNL] = $line;
                    unset($this->lines[$nl]);
                    $line->setNum($newNL);
                }
            }
            if (!empty($shifts)) {
                $this->lines = array_replace($this->lines, $shifts);
            }
            if (isset($this->lines[$sLine])) {
                $line = $this->lines[$sLine];
                $newLine = $line->breakLine($sColumn, $eColumn - $sColumn, $eLine);
                if ($newLine !== null) {
                    $this->lines[$eLine] = $newLine;
                }
                if ($line->isEmpty()) {
                    unset($this->lines[$sLine]);
                }
            }
        }
        $this->sMappings = null;
    }
1200367
function _added( $lines, $encode = true ) {
		$r = '';
		foreach ($lines as $line) {
			if ( $encode )
				$line = htmlspecialchars( $line );
			$r .= '<tr>' . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
		}
		return $r;
	}
1348063
public function replaceLines($startOriginalLine, $endOriginalLine, array $newLines)
    {
        $this->buffer->replace($this->createLineRange($startOriginalLine, $endOriginalLine), $newLines);
    }
1284618
public function appendLines($lines, $indent = 0)
    {
        foreach ($lines as $line) {
            $this->appendLine($line, $indent);
        }
    }
741100
protected function newQuery($insert = false)
	{
		$query = $this->connection->table($this->table);

		if (!$insert) {
			foreach ($this->extraColumns as $key => $value) {
				$query->where($key, '=', $value);
			}
		}

		if ($this->queryConstraint !== null) {
			$callback = $this->queryConstraint;
			$callback($query, $insert);
		}

		return $query;
	}
99998
public function beforeSave($insert)
    {
        if(parent::beforeSave($insert))
        {
            if($this->isNewRecord)
            {
                $this->created_at = time();
            }
            return true;
        }
        else
            return false;
    }
54524
public function breakLine($sColumn, $length, $newNum)
    {
        $newPositions = [];
        foreach ($this->positions as $column => $position) {
            if ($column >= $sColumn) {
                $newColumn = $column + $length;
                $position->generated->line = $newNum;
                $position->generated->column = $newColumn;
                $newPositions[$newColumn] = $position;
                unset($this->positions[$column]);
            }
        }
        if (empty($newPositions)) {
            return null;
        }
        return new self($newNum, $newPositions);
    }
1004491
protected function _insertRoles(array $insert = [])
    {
        foreach ($insert as $roleId) {
            $record = new \Cms\Orm\CmsCategoryRoleRecord();
            $record->cmsCategoryId = $this->_category->getPk();
            $record->cmsRoleId = $roleId;
            $record->save();
        }
        return true;
    }
1311607
protected static function inserts_replacing_recursive ($data, $insert) {
		if (is_array($data)) {
			/** @noinspection ForeachSourceInspection */
			foreach ($data as &$d) {
				$d = static::inserts_replacing_recursive($d, $insert);
			}
			return $data;
		}
		foreach ($insert as $i => $d) {
			$data = str_replace("\$i[$i]", $d, $data);
		}
		return $data;
	}
237015
def insertLine(self, i) :
		""""""
		self.data.insert(i, CSVEntry(self))
		return self.lines[i]