Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
fa886ce8
S
scie
项目概览
Phodal
/
scie
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scie
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
fa886ce8
编写于
9月 10, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: refs scie modules
上级
42937fbd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
99 addition
and
5 deletion
+99
-5
scie-scanner/src/scanner/LICENSE
scie-scanner/src/scanner/LICENSE
+2
-0
scie-scanner/src/scanner/mod.rs
scie-scanner/src/scanner/mod.rs
+1
-0
scie-scanner/src/scanner/scie_error.rs
scie-scanner/src/scanner/scie_error.rs
+81
-0
scie-scanner/src/scanner/scie_onig.rs
scie-scanner/src/scanner/scie_onig.rs
+15
-5
未找到文件。
scie-scanner/src/scanner/LICENSE
浏览文件 @
fa886ce8
...
@@ -6,6 +6,8 @@ Copyright (c) Phodal Huang
...
@@ -6,6 +6,8 @@ Copyright (c) Phodal Huang
Copyright (c) Microsoft Corporation.
Copyright (c) Microsoft Corporation.
Copyright (c) 2015 Will Speak <will@willspeak.me>, Ivan Ivashchenko <defuz@me.com>, and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
in the Software without restriction, including without limitation the rights
...
...
scie-scanner/src/scanner/mod.rs
浏览文件 @
fa886ce8
pub
mod
scie_scanner
;
pub
mod
scie_scanner
;
pub
mod
scie_onig
;
pub
mod
scie_onig
;
pub
mod
scie_error
;
scie-scanner/src/scanner/scie_error.rs
0 → 100644
浏览文件 @
fa886ce8
// > The MIT License (MIT)
// >
// > Copyright (c) 2015 Will Speak <will@willspeak.me>, Ivan Ivashchenko
// > <defuz@me.com>, and contributors.
// >
// > Permission is hereby granted, free of charge, to any person obtaining a copy
// > of this software and associated documentation files (the "Software"), to deal
// > in the Software without restriction, including without limitation the rights
// > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// > copies of the Software, and to permit persons to whom the Software is
// > furnished to do so, subject to the following conditions:
// >
// > The above copyright notice and this permission notice shall be included in all
// > copies or substantial portions of the Software.
// >
// > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// > SOFTWARE.
use
std
::
os
::
raw
::
c_int
;
use
std
::
ptr
::
null
;
use
std
::{
error
,
fmt
,
str
};
/// This struture represents an error from the underlying Oniguruma libray.
pub
struct
ScieOnigError
{
code
:
c_int
,
description
:
String
,
}
impl
ScieOnigError
{
pub
fn
from_code_and_info
(
code
:
c_int
,
info
:
&
onig_sys
::
OnigErrorInfo
)
->
ScieOnigError
{
ScieOnigError
::
new
(
code
,
info
)
}
fn
from_code
(
code
:
c_int
)
->
ScieOnigError
{
ScieOnigError
::
new
(
code
,
null
())
}
fn
new
(
code
:
c_int
,
info
:
*
const
onig_sys
::
OnigErrorInfo
)
->
ScieOnigError
{
let
buff
=
&
mut
[
0
;
onig_sys
::
ONIG_MAX_ERROR_MESSAGE_LEN
as
usize
];
let
len
=
unsafe
{
onig_sys
::
onig_error_code_to_str
(
buff
.as_mut_ptr
(),
code
,
info
)
};
let
description
=
str
::
from_utf8
(
&
buff
[
..
len
as
usize
])
.unwrap
();
ScieOnigError
{
code
,
description
:
description
.to_owned
(),
}
}
/// Return Oniguruma engine error code.
pub
fn
code
(
&
self
)
->
i32
{
self
.code
}
/// Return error description provided by Oniguruma engine.
pub
fn
description
(
&
self
)
->
&
str
{
&
self
.description
}
}
impl
error
::
Error
for
ScieOnigError
{
fn
description
(
&
self
)
->
&
str
{
&
self
.description
}
}
impl
fmt
::
Display
for
ScieOnigError
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"Oniguruma error: {}"
,
self
.description
())
}
}
impl
fmt
::
Debug
for
ScieOnigError
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"Error({}, {})"
,
self
.code
,
self
.description
())
}
}
scie-scanner/src/scanner/scie_onig.rs
浏览文件 @
fa886ce8
//
//
use
std
::
ptr
::
null_mut
;
use
std
::
ptr
::
null_mut
;
use
onig
::{
Syntax
,
EncodedChars
};
use
onig
::{
Syntax
,
EncodedChars
};
use
std
::
sync
::
Mutex
;
use
std
::
sync
::
Mutex
;
use
crate
::
scanner
::
scie_error
::
ScieOnigError
;
lazy_static!
{
lazy_static!
{
static
ref
REGEX_NEW_MUTEX
:
Mutex
<
()
>
=
Mutex
::
new
(());
static
ref
REGEX_NEW_MUTEX
:
Mutex
<
()
>
=
Mutex
::
new
(());
...
@@ -14,10 +16,12 @@ bitflags! {
...
@@ -14,10 +16,12 @@ bitflags! {
}
}
}
}
pub
struct
ScieOnig
{}
pub
struct
ScieOnig
{
raw
:
onig_sys
::
OnigRegex
,
}
impl
ScieOnig
{
impl
ScieOnig
{
pub
fn
hello
(
pattern
:
&
str
)
{
pub
fn
hello
(
pattern
:
&
str
)
->
Result
<
Self
,
ScieOnigError
>
{
let
option
=
ScieOnigOptions
::
REGEX_OPTION_NONE
;
let
option
=
ScieOnigOptions
::
REGEX_OPTION_NONE
;
let
syntax
=
Syntax
::
default
();
let
syntax
=
Syntax
::
default
();
...
@@ -33,7 +37,7 @@ impl ScieOnig {
...
@@ -33,7 +37,7 @@ impl ScieOnig {
par_end
:
null_mut
(),
par_end
:
null_mut
(),
};
};
let
_
err
=
unsafe
{
let
err
=
unsafe
{
// Grab a lock to make sure that `onig_new` isn't called by
// Grab a lock to make sure that `onig_new` isn't called by
// more than one thread at a time.
// more than one thread at a time.
let
_
guard
=
REGEX_NEW_MUTEX
.lock
()
.unwrap
();
let
_
guard
=
REGEX_NEW_MUTEX
.lock
()
.unwrap
();
...
@@ -45,8 +49,14 @@ impl ScieOnig {
...
@@ -45,8 +49,14 @@ impl ScieOnig {
pattern
.encoding
(),
pattern
.encoding
(),
syntax
as
*
const
Syntax
as
*
mut
Syntax
as
*
mut
onig_sys
::
OnigSyntaxType
,
syntax
as
*
const
Syntax
as
*
mut
Syntax
as
*
mut
onig_sys
::
OnigSyntaxType
,
&
mut
error
,
&
mut
error
,
)
;
)
};
};
if
err
==
onig_sys
::
ONIG_NORMAL
as
i32
{
Ok
(
ScieOnig
{
raw
:
reg
})
}
else
{
Err
(
ScieOnigError
::
from_code_and_info
(
err
,
&
error
))
}
}
}
pub
fn
create_onig_scanner
(
_
sources
:
Vec
<
String
>
)
{}
pub
fn
create_onig_scanner
(
_
sources
:
Vec
<
String
>
)
{}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录