Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
47f6d37c
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47f6d37c
编写于
7月 30, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11606 from vipulnsward/refactor_array_parser
Refactor `ArrayParser`
上级
0cdac3e0
a03cfded
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
15 deletion
+22
-15
activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb
...ive_record/connection_adapters/postgresql/array_parser.rb
+22
-15
未找到文件。
activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb
浏览文件 @
47f6d37c
...
@@ -2,6 +2,13 @@ module ActiveRecord
...
@@ -2,6 +2,13 @@ module ActiveRecord
module
ConnectionAdapters
module
ConnectionAdapters
class
PostgreSQLColumn
<
Column
class
PostgreSQLColumn
<
Column
module
ArrayParser
module
ArrayParser
DOUBLE_QUOTE
=
'"'
BACKSLASH
=
"
\\
"
COMMA
=
','
BRACKET_OPEN
=
'{'
BRACKET_CLOSE
=
'}'
private
private
# Loads pg_array_parser if available. String parsing can be
# Loads pg_array_parser if available. String parsing can be
# performed quicker by a native extension, which will not create
# performed quicker by a native extension, which will not create
...
@@ -12,18 +19,18 @@ module ArrayParser
...
@@ -12,18 +19,18 @@ module ArrayParser
include
PgArrayParser
include
PgArrayParser
rescue
LoadError
rescue
LoadError
def
parse_pg_array
(
string
)
def
parse_pg_array
(
string
)
parse_data
(
string
,
0
)
parse_data
(
string
)
end
end
end
end
def
parse_data
(
string
,
index
)
def
parse_data
(
string
)
local_index
=
index
local_index
=
0
array
=
[]
array
=
[]
while
(
local_index
<
string
.
length
)
while
(
local_index
<
string
.
length
)
case
string
[
local_index
]
case
string
[
local_index
]
when
'{'
when
BRACKET_OPEN
local_index
,
array
=
parse_array_contents
(
array
,
string
,
local_index
+
1
)
local_index
,
array
=
parse_array_contents
(
array
,
string
,
local_index
+
1
)
when
'}'
when
BRACKET_CLOSE
return
array
return
array
end
end
local_index
+=
1
local_index
+=
1
...
@@ -33,9 +40,9 @@ def parse_data(string, index)
...
@@ -33,9 +40,9 @@ def parse_data(string, index)
end
end
def
parse_array_contents
(
array
,
string
,
index
)
def
parse_array_contents
(
array
,
string
,
index
)
is_escaping
=
false
is_escaping
=
false
is_quoted
=
false
is_quoted
=
false
was_quoted
=
false
was_quoted
=
false
current_item
=
''
current_item
=
''
local_index
=
index
local_index
=
index
...
@@ -47,29 +54,29 @@ def parse_array_contents(array, string, index)
...
@@ -47,29 +54,29 @@ def parse_array_contents(array, string, index)
else
else
if
is_quoted
if
is_quoted
case
token
case
token
when
'"'
when
DOUBLE_QUOTE
is_quoted
=
false
is_quoted
=
false
was_quoted
=
true
was_quoted
=
true
when
"
\\
"
when
BACKSLASH
is_escaping
=
true
is_escaping
=
true
else
else
current_item
<<
token
current_item
<<
token
end
end
else
else
case
token
case
token
when
"
\\
"
when
BACKSLASH
is_escaping
=
true
is_escaping
=
true
when
','
when
COMMA
add_item_to_array
(
array
,
current_item
,
was_quoted
)
add_item_to_array
(
array
,
current_item
,
was_quoted
)
current_item
=
''
current_item
=
''
was_quoted
=
false
was_quoted
=
false
when
'"'
when
DOUBLE_QUOTE
is_quoted
=
true
is_quoted
=
true
when
'{'
when
BRACKET_OPEN
internal_items
=
[]
internal_items
=
[]
local_index
,
internal_items
=
parse_array_contents
(
internal_items
,
string
,
local_index
+
1
)
local_index
,
internal_items
=
parse_array_contents
(
internal_items
,
string
,
local_index
+
1
)
array
.
push
(
internal_items
)
array
.
push
(
internal_items
)
when
'}'
when
BRACKET_CLOSE
add_item_to_array
(
array
,
current_item
,
was_quoted
)
add_item_to_array
(
array
,
current_item
,
was_quoted
)
return
local_index
,
array
return
local_index
,
array
else
else
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录