Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos-rs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos-rs
Commits
84ee3188
Commit
84ee3188
authored
Dec 22, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add strings_conf_reader
parent
a0b01b0c
Pipeline
#18769
failed with stages
in 2 minutes and 55 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
7 deletions
+46
-7
src/main.rs
src/main.rs
+5
-2
src/service/mod.rs
src/service/mod.rs
+1
-1
src/service/strings.rs
src/service/strings.rs
+40
-4
No files found.
src/main.rs
View file @
84ee3188
use
std
::{
collections
::
HashMap
,
net
::
SocketAddr
,
str
::
FromStr
};
use
std
::{
net
::
SocketAddr
,
str
::
FromStr
};
use
warp
::
Filter
;
use
warp
::
Filter
;
mod
infra
;
mod
infra
;
...
@@ -11,7 +11,10 @@ const SERVE_ADDR: &str = "127.0.0.1:3030";
...
@@ -11,7 +11,10 @@ const SERVE_ADDR: &str = "127.0.0.1:3030";
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
pretty_env_logger
::
try_init
()
?
;
pretty_env_logger
::
try_init
()
?
;
let
strings_manager
=
HashMap
::
new
();
let
workspace
=
env!
(
"CARGO_MANIFEST_DIR"
);
let
strings_manager
=
service
::
strings_conf_reader
(
format!
(
"{workspace}/ygopro-database/locales/zh-CN/strings.conf"
))
?
;
// TODO: use CORS correctly
// TODO: use CORS correctly
let
cors
=
warp
::
cors
()
let
cors
=
warp
::
cors
()
...
...
src/service/mod.rs
View file @
84ee3188
...
@@ -4,4 +4,4 @@ mod strings;
...
@@ -4,4 +4,4 @@ mod strings;
pub
use
cards
::
service
as
cards_service
;
pub
use
cards
::
service
as
cards_service
;
pub
use
deck
::
service
as
deck_service
;
pub
use
deck
::
service
as
deck_service
;
pub
use
strings
::
service_maker
as
strings_service
;
pub
use
strings
::
{
service_maker
as
strings_service
,
strings_conf_reader
}
;
src/service/strings.rs
View file @
84ee3188
use
std
::
collections
::
HashMap
;
use
std
::{
collections
::
HashMap
,
fs
::
File
,
io
::{
BufRead
,
BufReader
},
path
::
Path
,
};
type
StringsManager
=
HashMap
<
String
,
HashMap
<
i64
,
String
>>
;
// TODO: `strings_manager`应该做好持久化存储
// TODO: `strings_manager`应该做好持久化存储
pub
fn
service_maker
(
pub
fn
service_maker
(
strings_manager
:
StringsManager
)
->
impl
Fn
(
String
)
->
String
+
Clone
{
strings_manager
:
HashMap
<
String
,
HashMap
<
i64
,
String
>>
,
)
->
impl
Fn
(
String
)
->
String
+
Clone
{
move
|
param
|
{
move
|
param
|
{
// TODO:应该做好错误处理
// TODO:应该做好错误处理
let
(
r
#
type
,
code
)
=
param
.split_once
(
'_'
)
.unwrap_or_default
();
let
(
r
#
type
,
code
)
=
param
.split_once
(
'_'
)
.unwrap_or_default
();
...
@@ -15,3 +20,34 @@ pub fn service_maker(
...
@@ -15,3 +20,34 @@ pub fn service_maker(
.unwrap_or_default
()
.unwrap_or_default
()
}
}
}
}
pub
fn
strings_conf_reader
(
path
:
impl
AsRef
<
Path
>
)
->
anyhow
::
Result
<
StringsManager
>
{
let
f
=
File
::
open
(
path
)
?
;
let
reader
=
BufReader
::
new
(
f
);
let
mut
results
:
StringsManager
=
HashMap
::
new
();
for
line
in
reader
.lines
()
{
let
line
=
line
?
;
if
!
line
.starts_with
(
"#"
)
{
if
let
Some
((
r
#
type
,
left
))
=
line
.split_once
(
' '
)
{
if
let
Some
((
code
,
s
))
=
left
.split_once
(
' '
)
{
results
.entry
(
r
#
type
.to_string
())
.or_default
()
.insert
(
parse_code
(
code
)
?
,
s
.to_string
());
}
}
}
}
Ok
(
results
)
}
fn
parse_code
(
code
:
&
str
)
->
anyhow
::
Result
<
i64
>
{
if
code
.starts_with
(
"0x"
)
{
let
without_prefix
=
code
.trim_start_matches
(
"0x"
);
Ok
(
i64
::
from_str_radix
(
without_prefix
,
16
)
?
)
}
else
{
Ok
(
code
.parse
()
?
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment