Prepare extraction statement based on expression.

@param  string $escaped_field_name
@param  string $escaped_expression
@param  string $caster
@param  mixed  $escaped_default_value
@return string
421661
private function prepareGeneratedFieldExpression($escaped_field_name, $escaped_expression, $caster, $escaped_default_value)
    {
        $value_extractor_expression = "{$escaped_field_name}->>{$escaped_expression}";

        switch ($caster) {
            case ValueCasterInterface::CAST_BOOL:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, IF({$value_extractor_expression} = 'true' OR ({$value_extractor_expression} REGEXP '^-?[0-9]+$' AND CAST({$value_extractor_expression} AS SIGNED) != 0), 1, 0))";
            case ValueCasterInterface::CAST_DATE:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS DATE))";
            case ValueCasterInterface::CAST_DATETIME:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS DATETIME))";
            case ValueCasterInterface::CAST_INT:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS SIGNED INTEGER))";
            case ValueCasterInterface::CAST_FLOAT:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, CAST({$value_extractor_expression} AS DECIMAL(12, 2)))";
            default:
                return "IF({$value_extractor_expression} IS NULL, $escaped_default_value, {$value_extractor_expression})";
        }
    }
1250434
public static function quote($value)
    {
        $escapedValue = preg_quote($value);
        if (substr_count($escapedValue, '/') && !substr_count($escapedValue, '\/')) {
            $escapedValue = str_replace('/', '\/', $escapedValue);
        }

        return $escapedValue;
    }
604141
private function escapeCharacters(array $arr, $escapeValues)
    {
        $returnArr = [];

        foreach ($arr as $key => $value) {
            $returnArr[$this->addSlashes($key)] = $escapeValues ? $this->addSlashes($value) : $value;
        }

        return $returnArr;
    }
1290331
function(attr) {
      var html;
      if (html = this._escapedAttributes[attr]) return html;
      var val = this.attributes[attr];
      return this._escapedAttributes[attr] = escapeHTML(val == null ? '' : '' + val);
    }
1057294
function extract(scopes, parentStatement, expns, text, insertPosition) {
        var varType          = "var",
            varName          = RefactoringUtils.getUniqueIdentifierName(scopes, "extracted"),
            varDeclaration   = varType + " " + varName + " = " + text + ";\n",
            parentStatementStartPos = session.editor.posFromIndex(parentStatement.start),
            insertStartPos   = insertPosition || parentStatementStartPos,
            selections       = [],
            doc              = session.editor.document,
            replaceExpnIndex = 0,
            posToIndent,
            edits            = [];

        // If parent statement is expression statement, then just append var declaration
        // Ex: "add(1, 2)" will become "var extracted = add(1, 2)"
        if (parentStatement.type === "ExpressionStatement" &&
                RefactoringUtils.isEqual(parentStatement.expression, expns[0]) &&
                insertStartPos.line === parentStatementStartPos.line &&
                insertStartPos.ch === parentStatementStartPos.ch) {
            varDeclaration = varType + " " + varName + " = ";
            replaceExpnIndex = 1;
        }

        posToIndent = doc.adjustPosForChange(insertStartPos, varDeclaration.split("\n"), insertStartPos, insertStartPos);

        // adjust pos for change
        for (var i = replaceExpnIndex; i < expns.length; ++i) {
            expns[i].start  = session.editor.posFromIndex(expns[i].start);
            expns[i].end    = session.editor.posFromIndex(expns[i].end);
            expns[i].start  = doc.adjustPosForChange(expns[i].start, varDeclaration.split("\n"), insertStartPos, insertStartPos);
            expns[i].end    = doc.adjustPosForChange(expns[i].end, varDeclaration.split("\n"), insertStartPos, insertStartPos);

            edits.push({
                edit: {
                    text: varName,
                    start: expns[i].start,
                    end: expns[i].end
                },
                selection: {
                    start: expns[i].start,
                    end: {line: expns[i].start.line, ch: expns[i].start.ch + varName.length}
                }
            });
        }

        // Replace and multi-select
        doc.batchOperation(function() {
            doc.replaceRange(varDeclaration, insertStartPos);

            selections = doc.doMultipleEdits(edits);
            selections.push({
                start: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + 1},
                end:   {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + varName.length + 1},
                primary: true
            });
            session.editor.setSelections(selections);
            session.editor._codeMirror.indentLine(posToIndent.line, "smart");
        });
    }
318026
public function extractDefault(ColumnSchema $field, $defaultValue)
    {
        if ($field->dbType === 'timestamp' && $defaultValue === 'CURRENT_TIMESTAMP') {
            $defaultValue = null;
        } else {
            $defaultValue = strcasecmp($defaultValue, 'null') ? $defaultValue : null;
        }

        if (is_string($defaultValue)) // PHP 5.2.6 adds single quotes while 5.2.0 doesn't
        {
            $defaultValue = trim($defaultValue, "'\"");
        }

        parent::extractDefault($field, $defaultValue);
    }
868344
@VisibleForTesting
  static String icuEscape(String rawText) {

    Matcher matcher = ICU_SYNTAX_CHAR_NEEDING_ESCAPE_PATTERN.matcher(rawText);
    if (!matcher.find()) {
      return rawText;
    }

    StringBuffer escapedTextSb = new StringBuffer();
    do {
      String repl = ICU_SYNTAX_CHAR_ESCAPE_MAP.get(matcher.group());
      matcher.appendReplacement(escapedTextSb, repl);
    } while (matcher.find());
    matcher.appendTail(escapedTextSb);
    return escapedTextSb.toString();
  }
366511
public function getEscapedVar($name, $default = '', $verb = 'get', $options = array())
    {
        //FILTER_SANITIZE_MAGIC_QUOTES
        //FILTER_SANITIZE_SPECIAL_CHARS
        $filter = \IS\ESCAPED; //FILTER_SANITIZE_NUMBER_INT

        $escaped = $this->getVar($name, $filter, $default, $verb, $options);

        //@TODO validate is interger before return
        return $escaped;
    }
188495
function makeEntry(name, value) {
    var escaped = escapeDelimiter(value);

    return {
      name: name,
      escaped: escaped,
      test: new RegExp("^" + escaped)
    };
  }
547410
function(attr) {
      var html;
      if (html = this._escapedAttributes[attr]) return html;
      var val = this.get(attr);
      return this._escapedAttributes[attr] = _.escape(val == null ? '' : '' + val);
    }
899594
public function create_sql_update_string(array $fields, array $castFields = null) {
		$retval = "";
		if(count($fields)) {
			foreach($fields as $k=>$v) {
				//$retval = $k .'=:'. $v;
				//handle casting to a certain type, e.g. :session_id::varchar(40)
				$k2 = $k;
				if(isset($castFields[$k])) {
					$k2 = $k .'::'. $castFields[$k];
				}
				$retval = ToolBox::create_list($retval, $k .'=:'. $k2, ', ');
			}
			$retval = " ". $retval;
		}
		else {
			throw new Exception(__METHOD__ .": unable to create update string, no fields given");
		}
		
		return($retval);
	}
552148
public function escapeDateTime($dt, $EMPTY_NULL = true) {
		/*if(!is_string($s)){
			$s='';
			}*/
		if (($EMPTY_NULL) && (empty($dt))) {
			return 'NULL';
		}
		$str = '"' . $dt->format('Y-m-d H:i:s') . '"';
		return $str;
	}
593335
public static function unescape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8')
    {

        if (is_string($mixed)) {
            $mixed = str_replace('&amp;', '&', $mixed);
            $mixed = str_replace('&#039;', '\'', $mixed);
            $mixed = str_replace('&quot;', '"', $mixed);
            $mixed = str_replace('&lt;', '<', $mixed);
            $mixed = str_replace('&gt;', '>', $mixed);
        } elseif (is_object($mixed) || is_array($mixed)) {
            foreach ($mixed as $k => &$v) {
                if ($v) {
                    if (is_object($mixed)) {
                        $mixed->$k = self::unescape($v);
                    } else {
                        $mixed[$k] = self::unescape($v);
                    }
                }
            }
        }

        return $mixed;
    }
513641
private function lexExpression()
    {
        $statementMethods = $this->getStatementLexingMethods();

        while (!$this->atEof()) {
            reset($statementMethods);
            $matchedStatement = false;

            // This is essentially a foreach loop that can be reset
            while (list($statementOpenDelimiter, $methodName) = each($statementMethods)) {
                if ($this->matches($statementOpenDelimiter)) {
                    // This is an unescaped statement
                    $matchedStatement = true;
                    $this->{$methodName}();

                    // Now that we've matched, we want to reset the loop so that longest delimiters are matched first
                    reset($statementMethods);
                } elseif ($this->getCurrentChar() === '\\') {
                    // Now that we know we're on an escape character, spend the resources to check for a match
                    if ($this->matches("\\$statementOpenDelimiter")) {
                        // This is an escaped statement
                        $this->expressionBuffer .= $statementOpenDelimiter;
                    }
                }
            }

            // Handle any text outside statements
            if (!$matchedStatement && !$this->atEof()) {
                $currentChar = $this->getCurrentChar();
                $this->expressionBuffer .= $currentChar;
                $this->cursor++;

                // Keep on going if we're seeing alphanumeric text
                while (ctype_alnum($this->getCurrentChar())) {
                    $currentChar = $this->getCurrentChar();
                    $this->expressionBuffer .= $currentChar;
                    $this->cursor++;
                }
            } else {
                $this->flushExpressionBuffer();
            }
        }

        // Flush anything left over in the buffer
        $this->flushExpressionBuffer();
    }
856951
private function resolveCasterClassName($type) {
        foreach($this->casters as $typeNames => $casterClass) {
            $names = explode('|', $typeNames);

            if(!in_array($type, $names)) {
                continue;
            }

            return $casterClass;
        }
        
        throw CasterException::unresolvableType($type);
    }
661596
private String escapeForPOFile(final String input, boolean fix) {
        if (input == null) return "";

        String escapedString = input;

        // Publican escapes greater/lesser than to XML entities
        if (fix && (input.contains(" < ") || input.contains(" > "))) {
            // Loop over and find all the XML Elements as they should remain untouched.
            final LinkedList<String> elements = new LinkedList<String>();
            if (input.indexOf('<') != -1) {
                int index = -1;
                while ((index = input.indexOf('<', index + 1)) != -1) {
                    int endIndex = input.indexOf('>', index);
                    int nextIndex = input.indexOf('<', index + 1);

                    /*
                      * If the next opening tag is less than the next ending tag, than the current opening tag isn't a match for the next
                      * ending tag, so continue to the next one
                      */
                    if (endIndex == -1 || (nextIndex != -1 && nextIndex < endIndex)) {
                        continue;
                    } else if (index + 1 == endIndex) {
                        // This is a <> sequence, so it should be ignored as well.
                        continue;
                    } else {
                        elements.add(input.substring(index, endIndex + 1));
                    }

                }
            }

            // Find all the elements and replace them with a marker
            for (int count = 0; count < elements.size(); count++) {
                escapedString = escapedString.replace(elements.get(count), "###" + count + "###");
            }

            // Perform the replacements on what's left
            escapedString = escapedString.replace("<", "&lt;").replace(">", "&gt;");

            // Replace the markers
            for (int count = 0; count < elements.size(); count++) {
                escapedString = escapedString.replace("###" + count + "###", elements.get(count));
            }
        }

        return escapedString.replace("\\", "\\\\")
                .replace("\"", "\\\"")
                .replace("\n", "\\n")
                .replace("\r", "\\r");
    }
407902
function escapedValue (data, info, str) {
    return he.escape(getValue(data, info, str) + '')
  }