function normalize($str) { if ($str instanceof Modyllic_Token_Reserved) { return $str->value(); } else { if ($str instanceof Modyllic_Token_String) { $value = $str->unquote(); } else { if ($str instanceof Modyllic_Token_Num) { $value = $str->value(); } else { if (!is_object($str)) { $value = $str; } else { throw new Exception("Expected a valid string, got: {$str}"); } } } } if (isset($this->length)) { $value = substr($value, 0, $this->length); } return Modyllic_SQL::quote_str($value); }
/** * Our string parser, this expects strings to look like <CHR>stuff<CHR> * where <CHR> is a quote character. <CHR> can be escaped by either * doubling it or by preceding it with a backslash. Any character * proceeded by a backslash will be included literally. * For example, the string: foo's test * Could be: 'foo''s test' * Or: 'foo\'s test' * If the quote character is ` then it will return a quoted ident * token rather then a string token. */ private function next_string() { $quote = $this->cmdstr[$this->pos]; $this->pos++; $str = $quote; while ($this->pos < $this->len) { $chr = $this->cmdstr[$this->pos++]; if ($chr == '\\') { $str .= $chr . $this->cmdstr[$this->pos++]; } else { if ($chr == $quote and $this->pos < $this->len and $this->cmdstr[$this->pos] == $quote) { $str .= $chr . $this->cmdstr[$this->pos++]; } else { if ($chr == $quote) { $str .= $chr; break; } else { $str .= $chr; } } } } if ($quote == '`') { return new Modyllic_Token_Ident_Quoted($this->pos, $str); } else { $token = new Modyllic_Token_String($this->pos, $str); // If we're followed by whitespace and a string, then concatenate the string if ($this->peek_next(true) instanceof Modyllic_Token_Whitespace) { $ws = $this->next(true); if ($this->peek_next(true) instanceof Modyllic_Token_String) { $token = new Modyllic_Token_String($this->pos, Modyllic_SQL::quote_str($token->unquote() . $this->next(false)->unquote())); } else { $this->inject($ws); } } return $token; } }
protected function _format_replace($matches) { switch ($matches[1]) { case 'id': $result = Modyllic_SQL::quote_ident(array_shift($this->_format_args)); break; case 'str': $result = Modyllic_SQL::quote_str(array_shift($this->_format_args)); break; case 'lit': $result = array_shift($this->_format_args); break; default: $result = '%' . $matches[1]; } return $result; return $this; }