Trim

Trim all whitespacey bits from both ends.

@param string $str String.
@return void Nothing.
336227
public static function trim(&$str='') {
		if (\is_array($str)) {
			foreach ($str as $k=>$v) {
				static::trim($str[$k]);
			}
		}
		else {
			cast::string($str, true);
			$str = \preg_replace('/(^\s+|\s+$)/u', '', $str);
		}
	}
690745
public function prepend($str)
    {
        $value = $this->val();
        $this->val($str . $value);

        return $this;
    }
352850
public static function cleanTextarea($str)
  {
    $str = str_replace('&nbsp;', ' ', $str);
    $str = preg_replace("/[\r\n]{2,}/", "\n\n", $str);
    $str = preg_replace("/<br([^>]*)>/", "\n", $str);
    
    if ( !preg_match("/<(p|table|figure|div|h[1-6])>.+<\/$1>/", $str) ){
      $str = '<p>'.$str.'</p>';
    }
    $str = preg_replace("/\n\n/", "</p> <p>", $str);
    $str = trim($str);
    $str = preg_replace("/<p>\s*<\/p>/", "", $str);
    $str = preg_replace("/\n/", "<br />", $str);
    $str = trim($str);
    
    return $str;
  }
57968
public String trimLeading(String str) {
        if (str == null) {
            return null;
        }

        int length = str.length();
        for (int i=0; i<length; i++) {
            if (str.charAt(i) > ' ') {
                return str.substring(i);
            }
        }

        return "";
    }
1235430
static function Trim($string, $chars = null)
    {
        self::InitEncoding();
        if (!$chars)
            return trim($string);

        return trim($string, $chars);
    }
556696
public static function java_truncate(string $str): string
    {
        if (strlen($str) > 955) {
            return substr($str, 0, 475).'[...]'.substr($str, -475);
        }

        return $str;
    }
301766
private function parse($str)
    {
        $str = trim($str);
        $this->expression = $str;
        $strlen = strlen($str);
        $main_array = [];
        $count = 0;

        for ($i=0; $i<$strlen; $i++) {

            $str_i = $str[$i];
            $str_ip1 = (isset($str[$i+1])) ? $str[$i+1] : null;
            $str_ip2 = (isset($str[$i+2])) ? $str[$i+2] : null;
            $str_ip3 = (isset($str[$i+3])) ? $str[$i+3] : null;
            $str_ip4 = (isset($str[$i+4])) ? $str[$i+4] : null;
            $str_im1 = (isset($str[$i-1])) ? $str[$i-1] : null;
            $str_im2 = (isset($str[$i-2])) ? $str[$i-2] : null;

            // NaN
            if (stristr($str, 'NaN'))
                return NAN;
            // Spaces will be skipped
            if ($str_i == ' ') {
                $count++;
            // Number
            } elseif (is_numeric($str_i)) {
                $main_array[$count] = (isset($main_array[$count])) ?
                        $main_array[$count].$str_i : $str_i;
            // Constant pi
            } elseif ($str_im1.$str_i == 'pi') {
            } elseif (($str_i.$str_ip1 == 'pi')
            && (!$str_ip2 || strstr('+-*/^ ', $str_ip2))) {
                $count++;
                $main_array[$count] = M_PI;
            // Constant e
            } elseif (($str_i == 'e') && ($str_ip1 != 'x') && (!is_numeric($str_im1))
            && (!$str_ip1 || strstr('+-*/^ ', $str_ip1))) {
                $count++;
                $main_array[$count] = M_E;
            // Number in E notation
            } elseif ((strtolower($str_i) == 'e') && ($str_ip1 != 'x')
            && (is_numeric($str_im1))) {
                $main_array[$count] = $main_array[$count].'E';
            } elseif ((strstr('+-', $str_i)) && (strtolower($str_im1) == 'e')
            && (is_numeric($str_ip1)) && (is_numeric($str_im2))) {
                $main_array[$count] = $main_array[$count].$str_i;
            // Decimal point
            } elseif (($str_i == '.') && ((isset($str_im1) && is_numeric($str_im1)) 
            || (isset($str_ip1)) && is_numeric($str_ip1))) {
                $main_array[$count] = (isset($main_array[$count])) ? 
                        $main_array[$count].'.' : '.';
            // Function
            } elseif ((in_array($str_i.$str_ip1.$str_ip2, $this->valid_functions))
            || ($str_i.$str_ip1.$str_ip2.$str_ip3 == 'sqrt')) {
                if ($str_i.$str_ip1.$str_ip2.$str_ip3 == 'sqrt') {
                    if ($str_ip4 == ' ')
                        $this->calculateFunction('sqrt', $str, $strlen, $i);
                } else {
                    if ($str_ip3 == ' ')
                        $this->calculateFunction($str_i.$str_ip1.$str_ip2, $str, $strlen, $i);
                }
            // Variable
            } elseif (in_array($str_i, $this->valid_variables) && count($this->variables)) {
                if (array_key_exists($str_i, $this->variables)
                && is_numeric($this->variables[$str_i])) {
                    $main_array[$count] = (float) $this->variables[$str_i];
                    $count++;
                } else {
                    $this->correct = 0;
                    $this->error_type = 4;
                    break;
                }
            } else {
                // Operator
                $count++;
                if (strstr('+-*/^', $str_i)) {
                    if (!count($main_array) && $str_i == '+')
                        continue;
                    $main_array[$count] = $str_i;
                    $count++;
                } else {
                    // Constant Inf
                    if ($str_im2.$str_im1.$str_i == 'INF') {
                    } elseif ($str_im1.$str_i.$str_ip1 == 'INF') {
                    } elseif ($str_i.$str_ip1.$str_ip2 == 'INF') {
                        if ($str_im1 == '-' && !count($main_array)) {
                            $main_array[$count] = '-';
                            $count++;
                        }
                        $main_array[$count] = INF;
                        $count++;
                    } else {
                        // Nothing matches
                        $this->correct = 0;
                        if (!$this->validate())
                            $this->error_type = 1;
                        break;
                    }
                }
            }
        }

        if (!$this->correct)
            return 0;

        $main_array = array_values($main_array);

        if (isset($main_array[1])) {

            $main_array = $this->combine($main_array);
            $main_array = $this->calculate1($main_array);
            $main_array = $this->calculate2($main_array);
            $main_array = $this->calculate3($main_array);

            if (count($main_array) != 1)
                $this->correct = 0;
        }

        if (!isset($main_array[0]) || strstr('+-*/^', (string) $main_array[0])
        || substr_count((string) $main_array[0], '.') > 1) {
            $this->correct = 0;
            return 0;
        }

        return $this->return_($main_array[0]);
    }
468447
public static String trim(String str, String defaultValue) {
	if (str == null) return defaultValue;
	return str.trim();
    }
1008629
public function out($str)
    {
        $str = Color::convert($str);
        if ($this->useAnsiColors() === false) {
            $str = Color::strip($str);
        }
        $this->getOutputter()->stdout($str, '');
        if (count(\ob_get_status()) !== 0) {
            ob_flush();
        }
    }
1161991
public function preProcessString($str)
    {
        $str = str_replace("<?php", "", $str);
        $str = str_replace("<?", "", $str);
        $str = str_replace("?>", "", $str);
        $str = str_replace("'", "\x22", $str);

        $str = trim($str);

        return $str;
    }
975327
function trim(str) {
  var input = str.replace(/\s\s+/g, ' ').trim();

  var words = input.split(' ');
  if (_.contains(LANG_WORDS, _.first(words))) {
    return words.slice(1).join(' ');
  }
  return input;
}
734167
public static function IsEmpty($str, $trim = false) {
		return is_null($str) || static::STRING_EMPTY === ((!$trim) ? $str : trim($str, $trim));
	}
276133
public static function stripAll($str)
    {
        $str = stripslashes($str);
        $str = strip_tags($str);
        $str = \sb\Strings::unicodeUrldecode($str);
        $str = self::stripBling($str);
        $str = \sb\Strings::stripMicrosoftChars($str);
        return $str;
    }
568000
public static function cleanForOrder(string $str): string
  {
    $str = self::removeAccents($str);
    $str = preg_replace("/^[^a-z0-9 ]/i", "", $str);
    $str = trim($str);
    return $str;
  }
189327
protected function skipToString($str)
	{
		while (++$this->i < $this->cnt && $this->tokens[$this->i] !== $str);
	}
157202
public static function strExists($str, $string)
    {
        $string = (string) $string;
        $str    = (string) $str;
        return strstr($string, $str) === false ? false : true;
    }
245013
public static String trimAllWhitespace(final String str) {
    if (!StringUtils.hasLength(str)) {
      return str;
    }

    final int len = str.length();
    final StringBuilder sb = new StringBuilder(str.length());
    for (int i = 0; i < len; i++) {
      final char c = str.charAt(i);
      if (!Character.isWhitespace(c)) {
        sb.append(c);
      }
    }
    return sb.toString();
  }