Trim whitespaces and other special chars

@param string $value
@param bool   $extendMode
@return string
331304
public static function trim($value, $extendMode = false): string
    {
        $result = (string)trim($value);

        if ($extendMode) {
            $result = trim($result, chr(0xE3) . chr(0x80) . chr(0x80));
            $result = trim($result, chr(0xC2) . chr(0xA0));
            $result = trim($result);
        }

        return $result;
    }
1033474
public static String trim(final String value, final Optional<XlsTrim> trimAnno) {

        if(!trimAnno.isPresent() || value == null) {
            return value;
        }

        return value.trim();

    }
1009225
public function sanitize($value)
    {
        $value = JApplicationHelper::stringURLSafe($value);

        //limit length
        if (mb_strlen($value) > $this->_length) {
            $value = mb_substr($value, 0, $this->_length);
        }

        return $value;
    }
56120
protected function sanitizeNodeToValue($value)
    {
        $first = strpos($value, '>')+1;
        $last = strrpos($value, '<')-$first;
        $value = substr($value, $first, $last);
        $value = str_replace('"', "'", $value);
        return trim($value);
    }
215343
protected function getFullClassToExtend($extend)
    {
        if (empty($extend)) {
            return '';
        }
        $appNamespace = Helpers::getAppNamespace();

        if (starts_with($extend, $appNamespace)) {
            $extend = str_replace($appNamespace, '', $extend);
        }

        return $appNamespace . trim($extend, '\\');
    }
723525
protected static function highlightBoundary($value)
    {
        if ($value==='(' || $value===')') return $value;

        if (self::is_cli()) {
            return self::$cli_boundary . $value . "\x1b[0m";
        } else {
            return '<span ' . self::$boundary_attributes . '>' . $value . '</span>';
        }
    }
796265
public static function convertFromWhiteSpace($value)
    {
        //check for inline linebreaks
        $search = array('\r', '\n', '\f', '\t', '\v');
        $value  = str_replace($search, ';', $value);

        // replace replacement characters regular spaces
        $value = str_replace('�', ' ', $value);

        //convert real linebreaks
        return preg_replace('/(?:\n|\r|\v)/m', '  ', $value);
    }
556189
public String normalizeWhitespace(String value) {
        String result = null;
        if (value != null) {
            value = value.trim();
            result = replaceAllInWith("\\s+", value, " ");
        }
        return result;
    }
1217307
public function sanitize($value)
    {
        $value = trim($value);

        $parts  = explode('-', $value, 2);
        if(2 != count($parts)) {
            return null;
        }

        $parts[0]   = substr(preg_replace('/[^a-z]*/', '', $parts[0]), 0, 2);
        $parts[1]   = substr(preg_replace('/[^A-Z]*/', '', $parts[1]), 0, 2);
        $result = implode('-', $parts);

        // just making sure :-)
        if($this->validate($result)) {
            return $result;
        }

        return null;
    }
411216
private function trimLeftEnclosure($value, $enclosure)
    {
        if (substr($value, 0, 1) == $enclosure) {
            $value = substr($value, 1);
        }

        return $value;
    }
1165265
private function trimEnclosure($value, $enclosure)
    {
        $value = $this->trimLeftEnclosure($value, $enclosure);
        $value = $this->trimRightEnclosure($value, $enclosure);

        return $value;
    }
1158745
public static function prep_value($value) {
		if (\is_array($value)) {
			$value=implode(",", $value);
		}
		if (self::containsCode($value)===false) {
			$value=\str_replace(["\\","\""], ["\\\\","\\\""], $value);
			$value='"'.$value.'"';
		}
		return trim($value,"%");
	}
784876
def escape_extension_value(val)
        escapes = {
          %r{=}  => '\=',
          %r{\n} => ' ',
          %r{\\} => '\\'
        }
        escapes.reduce(val) do |memo,replace|
          memo=memo.gsub(*replace)
        end
      end
1090012
public static String stripDelimiters(final String value) {
        if (value != null && value.length() > 1) {
            if (value.charAt(0) == value.charAt(value.length() - 1)
                    && (value.charAt(0) == '\'')) {
                return value.substring(1, value.length() - 1);
            }
            if (value.charAt(0) == value.charAt(value.length() - 1)
                    && (value.charAt(0) == '\"')) {
                return value.substring(1, value.length() - 1);
            }
        }
        return value;
    }
904165
public function clean($value)
  {
    // First prune whitespace.
    $value = PruneWhitespaceCleaner::get()->clean($value);

    // If the value is empty return immediately.
    if ($value==='' || $value===null || $value===false)
    {
      return $this->openDate;
    }

    // First validate against ISO 8601.
    $match = preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $value, $parts);
    $valid = ($match && checkdate((int)$parts[2], (int)$parts[3], (int)$parts[1]));
    if ($valid)
    {
      $date = new \DateTime($value);

      return $date->format('Y-m-d');
    }

    // Replace alternative separators with the expected separator.
    if ($this->separator!==null && $this->alternativeSeparators!==null)
    {
      $value = strtr($value,
                     $this->alternativeSeparators,
                     str_repeat($this->separator[0], strlen($this->alternativeSeparators)));
    }

    // Validate against $format.
    $date = \DateTime::createFromFormat($this->format, $value);
    if ($date)
    {
      // Note: String '2000-02-30' will transformed to date '2000-03-01' with a warning. We consider this as an
      // invalid date.
      $tmp = $date::getLastErrors();
      if ($tmp['warning_count']==0) return $date->format('Y-m-d');
    }

    return $value;
  }
171456
protected function _validate_ext($value, $parameter)
    {
        if ($value === '') {
            return '';
        }

        $ext = pathinfo($value, PATHINFO_EXTENSION);
        return in_array(strtolower($ext), preg_split('#[\s,]+#', $parameter, -1, PREG_SPLIT_NO_EMPTY), true) ? $value : null;
    }
424228
public static function fixStringLength($value, $length, $endChars = '...')
    {
        if (!empty($value) and !empty($length)) {
            $cutLen = (int) $length - (int) strlen($endChars);
            if (strlen($value) > $length) {
                $strCut = substr($value, 0, $cutLen);
                $value = $strCut . $endChars;
            }
        }
        return $value;
    }