Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2024-10-30 12:13:11 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-10-30 12:13:11 +0800
Commit
9fa3bc40d7c0f6a5adce79824ae11a28279b19e3
9fa3bc40
1 parent
d9f65c98
Fix reading tokens.txt on Windows. (#1497)
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
24 行增加
和
0 行删除
sherpa-onnx/csrc/symbol-table.cc
sherpa-onnx/csrc/symbol-table.cc
查看文件 @
9fa3bc4
...
...
@@ -23,6 +23,29 @@
namespace
sherpa_onnx
{
namespace
{
// copied from
// https://stackoverflow.com/questions/216823/how-to-trim-a-stdstring
const
char
*
ws
=
"
\t\n\r\f\v
"
;
// trim from end of string (right)
inline
std
::
string
&
TrimRight
(
std
::
string
&
s
,
const
char
*
t
=
ws
)
{
s
.
erase
(
s
.
find_last_not_of
(
t
)
+
1
);
return
s
;
}
// trim from beginning of string (left)
inline
std
::
string
&
TrimLeft
(
std
::
string
&
s
,
const
char
*
t
=
ws
)
{
s
.
erase
(
0
,
s
.
find_first_not_of
(
t
));
return
s
;
}
// trim from both ends of string (right then left)
inline
std
::
string
&
Trim
(
std
::
string
&
s
,
const
char
*
t
=
ws
)
{
return
TrimLeft
(
TrimRight
(
s
,
t
),
t
);
}
}
// namespace
std
::
unordered_map
<
std
::
string
,
int32_t
>
ReadTokens
(
std
::
istream
&
is
,
std
::
unordered_map
<
int32_t
,
std
::
string
>
*
id2token
/*= nullptr*/
)
{
...
...
@@ -33,6 +56,7 @@ std::unordered_map<std::string, int32_t> ReadTokens(
std
::
string
sym
;
int32_t
id
=
-
1
;
while
(
std
::
getline
(
is
,
line
))
{
Trim
(
line
);
std
::
istringstream
iss
(
line
);
iss
>>
sym
;
if
(
iss
.
eof
())
{
...
...
请
注册
或
登录
后发表评论