Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
rs-tiled
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
rs-tiled
Commits
ebf61a5e
Commit
ebf61a5e
authored
10 years ago
by
Matthew Hall
Browse files
Options
Downloads
Patches
Plain Diff
Add csv parsing
parent
5968d975
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/tiled_csv.tmx
+131
-0
131 additions, 0 deletions
assets/tiled_csv.tmx
src/lib.rs
+24
-1
24 additions, 1 deletion
src/lib.rs
tests/lib.rs
+1
-0
1 addition, 0 deletions
tests/lib.rs
with
156 additions
and
1 deletion
assets/tiled_csv.tmx
0 → 100644
+
131
−
0
View file @
ebf61a5e
This diff is collapsed.
Click to expand it.
src/lib.rs
+
24
−
1
View file @
ebf61a5e
...
...
@@ -475,7 +475,7 @@ fn parse_data<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>
(
Some
(
e
),
None
)
=>
match
e
.as_slice
()
{
"base64"
=>
return
parse_base64
(
parser
)
.map
(|
v
|
convert_to_u32
(
&
v
,
width
)),
"csv"
=>
return
Err
(
TiledError
::
Other
(
"csv encoding is currently not supported"
.to_string
())
),
"csv"
=>
return
decode_csv
(
parser
),
e
=>
return
Err
(
TiledError
::
Other
(
format!
(
"Unknown encoding format {}"
,
e
))),
},
(
Some
(
e
),
Some
(
c
))
=>
...
...
@@ -527,6 +527,29 @@ fn decode_gzip(data : Vec<u8>) -> Result<Vec<u8>, TiledError> {
Ok
(
data
)
}
fn
decode_csv
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
)
->
Result
<
Vec
<
Vec
<
u32
>>
,
TiledError
>
{
loop
{
match
parser
.next
()
{
Characters
(
s
)
=>
{
let
mut
rows
:
Vec
<
Vec
<
u32
>>
=
Vec
::
new
();
for
row
in
s
.split
(
'\n'
)
{
if
row
.trim
()
==
""
{
continue
;
}
rows
.push
(
row
.split
(
','
)
.filter
(|
v
|
v
.trim
()
!=
""
)
.map
(|
v
|
v
.parse
()
.unwrap
())
.collect
());
}
return
Ok
(
rows
);
}
EndElement
{
name
,
..
}
=>
{
if
name
.local_name
==
"data"
{
return
Ok
(
Vec
::
new
());
}
}
_
=>
{}
}
}
}
fn
convert_to_u32
(
all
:
&
Vec
<
u8
>
,
width
:
u32
)
->
Vec
<
Vec
<
u32
>>
{
let
mut
data
=
Vec
::
new
();
for
chunk
in
all
.chunks
((
width
*
4
)
as
usize
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib.rs
+
1
−
0
View file @
ebf61a5e
...
...
@@ -14,6 +14,7 @@ fn test_gzip_and_zlib_encoded_and_raw_are_the_same() {
let
z
=
read_from_file
(
&
Path
::
new
(
"assets/tiled_base64_zlib.tmx"
))
.unwrap
();
let
g
=
read_from_file
(
&
Path
::
new
(
"assets/tiled_base64_gzip.tmx"
))
.unwrap
();
let
r
=
read_from_file
(
&
Path
::
new
(
"assets/tiled_base64.tmx"
))
.unwrap
();
let
c
=
read_from_file
(
&
Path
::
new
(
"assets/tiled_csv.tmx"
))
.unwrap
();
assert_eq!
(
z
,
g
);
assert_eq!
(
z
,
r
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment