You are here

function coder_br in Coder 6.2

Same name and namespace in other branches
  1. 5.2 scripts/coder_format/coder_format.inc \coder_br()
  2. 5 scripts/coder_format/coder_format.inc \coder_br()
  3. 6 scripts/coder_format/coder_format.inc \coder_br()
  4. 7.2 scripts/coder_format/coder_format.inc \coder_br()
  5. 7 scripts/coder_format/coder_format.inc \coder_br()

Generate a line feed including current line indent.

This function will also remove all line indentation from the previous line if no text was added.

Parameters

&$result: Result variable to append break and indent to, passed by reference.

$parenthesis: Optional integer of parentheses level for extra indents.

$add_indent: Whether to add current line indent after line feed.

1 call to coder_br()
coder_format_string in scripts/coder_format/coder_format.inc
Format the source code according to Drupal coding style guidelines.

File

scripts/coder_format/coder_format.inc, line 983
Coder format helper functions.

Code

function coder_br(&$result, $parenthesis = FALSE, $add_indent = TRUE) {
  global $_coder_indent;

  // Scan result backwards for whitespace.
  for ($i = strlen($result) - 1; $i >= 0; $i--) {
    if ($result[$i] == ' ') {
      continue;
    }
    if ($result[$i] == "\n") {
      $result = rtrim($result, ' ');
      break;
    }

    // Non-whitespace was encountered, no changes necessary.
    break;
  }
  if ($parenthesis) {

    // Add extra indent for each parenthesis in multiline definitions (f.e. arrays).
    $_coder_indent = $_coder_indent + $parenthesis;
    $result = rtrim($result);

    // This recursive call will only be done once, as $parenthesis is
    // set to false.
    coder_br($result, FALSE, $add_indent);
    $_coder_indent = $_coder_indent - $parenthesis;
  }
  else {
    $output = "\n";
    if ($add_indent && $_coder_indent >= 0) {
      $output .= str_repeat('  ', $_coder_indent);
    }
    $result .= $output;
  }
}