summaryrefslogtreecommitdiffstats
path: root/lib/SqlFormatter.php
diff options
context:
space:
mode:
authorJeremy <jeremy@jeremydorn.com>2014-04-16 18:55:36 -0700
committerJeremy <jeremy@jeremydorn.com>2014-04-16 18:55:36 -0700
commitffd2441bc082ab5aaf07be5676bfb1eadaeef77d (patch)
tree3da8de6cabeff816e72e40063d3d7d98136d53b6 /lib/SqlFormatter.php
parent9fcbe73681954170de7425dbcb24c83ecdd925aa (diff)
downloadsql-formatter-ffd2441bc082ab5aaf07be5676bfb1eadaeef77d.zip
sql-formatter-ffd2441bc082ab5aaf07be5676bfb1eadaeef77d.tar.gz
sql-formatter-ffd2441bc082ab5aaf07be5676bfb1eadaeef77d.tar.bz2
Add proper formatting for square bracket quoted strings (SQL Server style).
For #63
Diffstat (limited to 'lib/SqlFormatter.php')
-rw-r--r--lib/SqlFormatter.php15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php
index 24f2968..82927e4 100644
--- a/lib/SqlFormatter.php
+++ b/lib/SqlFormatter.php
@@ -9,7 +9,7 @@
* @copyright 2013 Jeremy Dorn
* @license http://opensource.org/licenses/MIT
* @link http://github.com/jdorn/sql-formatter
- * @version 1.2.17
+ * @version 1.2.18
*/
class SqlFormatter
{
@@ -102,7 +102,7 @@ class SqlFormatter
);
// Punctuation that can be used as a boundary between other tokens
- protected static $boundaries = array(',', ';',':', ']', '[', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
+ protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
// For HTML syntax highlighting
// Styles applied to different token types
@@ -235,9 +235,9 @@ class SqlFormatter
}
// Quoted String
- if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`') {
+ if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`' || $string[0]==='[') {
$return = array(
- self::TOKEN_TYPE => ($string[0]==='`'? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
+ self::TOKEN_TYPE => (($string[0]==='`' || $string[0]==='[')? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
self::TOKEN_VALUE => self::getQuotedString($string)
);
@@ -335,9 +335,10 @@ class SqlFormatter
// This checks for the following patterns:
// 1. backtick quoted string using `` to escape
- // 2. double quoted string using "" or \" to escape
- // 3. single quoted string using '' or \' to escape
- if ( preg_match('/^(((`[^`]*($|`))+)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) {
+ // 2. square bracket quoted string (SQL Server) using ]] to escape
+ // 3. double quoted string using "" or \" to escape
+ // 4. single quoted string using '' or \' to escape
+ if ( preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) {
$ret = $matches[1];
}