Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
dffed6e3
Commit
dffed6e3
authored
Oct 13, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag/Id3Scan: add class Id3String
parent
bf656af5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
20 deletions
+74
-20
Id3Scan.cxx
src/tag/Id3Scan.cxx
+15
-20
Id3String.hxx
src/tag/Id3String.hxx
+59
-0
No files found.
src/tag/Id3Scan.cxx
View file @
dffed6e3
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*/
*/
#include "Id3Scan.hxx"
#include "Id3Scan.hxx"
#include "Id3String.hxx"
#include "Id3Load.hxx"
#include "Id3Load.hxx"
#include "Handler.hxx"
#include "Handler.hxx"
#include "Table.hxx"
#include "Table.hxx"
...
@@ -63,18 +64,18 @@
...
@@ -63,18 +64,18 @@
#endif
#endif
gcc_pure
gcc_pure
static
id3_utf8_t
*
static
Id3String
tag_id3_getstring
(
const
struct
id3_frame
*
frame
,
unsigned
i
)
noexcept
tag_id3_getstring
(
const
struct
id3_frame
*
frame
,
unsigned
i
)
noexcept
{
{
id3_field
*
field
=
id3_frame_field
(
frame
,
i
);
id3_field
*
field
=
id3_frame_field
(
frame
,
i
);
if
(
field
==
nullptr
)
if
(
field
==
nullptr
)
return
nullptr
;
return
{}
;
const
id3_ucs4_t
*
ucs4
=
id3_field_getstring
(
field
);
const
id3_ucs4_t
*
ucs4
=
id3_field_getstring
(
field
);
if
(
ucs4
==
nullptr
)
if
(
ucs4
==
nullptr
)
return
nullptr
;
return
{}
;
return
id3_ucs4_utf8duplicate
(
ucs4
);
return
Id3String
::
FromUCS4
(
ucs4
);
}
}
/* This will try to convert a string to utf-8,
/* This will try to convert a string to utf-8,
...
@@ -82,13 +83,11 @@ tag_id3_getstring(const struct id3_frame *frame, unsigned i) noexcept
...
@@ -82,13 +83,11 @@ tag_id3_getstring(const struct id3_frame *frame, unsigned i) noexcept
static
id3_utf8_t
*
static
id3_utf8_t
*
import_id3_string
(
const
id3_ucs4_t
*
ucs4
)
import_id3_string
(
const
id3_ucs4_t
*
ucs4
)
{
{
id3_utf8_t
*
utf8
=
id3_ucs4_utf8duplicate
(
ucs4
);
auto
utf8
=
Id3String
::
FromUCS4
(
ucs4
);
if
(
gcc_unlikely
(
utf8
==
nullptr
)
)
if
(
!
utf8
)
return
nullptr
;
return
nullptr
;
AtScopeExit
(
utf8
)
{
free
(
utf8
);
};
return
(
id3_utf8_t
*
)
xstrdup
(
Strip
(
utf8
.
c_str
()));
return
(
id3_utf8_t
*
)
xstrdup
(
Strip
((
char
*
)
utf8
));
}
}
/**
/**
...
@@ -226,24 +225,20 @@ tag_id3_import_musicbrainz(const struct id3_tag *id3_tag,
...
@@ -226,24 +225,20 @@ tag_id3_import_musicbrainz(const struct id3_tag *id3_tag,
if
(
frame
==
nullptr
)
if
(
frame
==
nullptr
)
break
;
break
;
id3_utf8_t
*
name
=
tag_id3_getstring
(
frame
,
1
);
const
auto
name
=
tag_id3_getstring
(
frame
,
1
);
if
(
name
==
nullptr
)
if
(
!
name
)
continue
;
continue
;
AtScopeExit
(
name
)
{
free
(
name
);
};
const
auto
value
=
tag_id3_getstring
(
frame
,
2
);
if
(
!
value
)
id3_utf8_t
*
value
=
tag_id3_getstring
(
frame
,
2
);
if
(
value
==
nullptr
)
continue
;
continue
;
AtScopeExit
(
value
)
{
free
(
value
);
};
handler
.
OnPair
(
name
.
c_str
(),
value
.
c_str
());
handler
.
OnPair
((
const
char
*
)
name
,
(
const
char
*
)
value
);
TagType
type
=
tag_id3_parse_txxx_name
(
(
const
char
*
)
name
);
TagType
type
=
tag_id3_parse_txxx_name
(
name
.
c_str
()
);
if
(
type
!=
TAG_NUM_OF_ITEM_TYPES
)
if
(
type
!=
TAG_NUM_OF_ITEM_TYPES
)
handler
.
OnTag
(
type
,
(
const
char
*
)
value
);
handler
.
OnTag
(
type
,
value
.
c_str
()
);
}
}
}
}
...
...
src/tag/Id3String.hxx
0 → 100644
View file @
dffed6e3
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <id3tag.h>
#include <stdlib.h>
/**
* A UTF-8 string allocated by libid3tag.
*/
class
Id3String
{
id3_utf8_t
*
p
=
nullptr
;
Id3String
(
id3_utf8_t
*
_p
)
noexcept
:
p
(
_p
)
{}
public
:
Id3String
()
noexcept
=
default
;
~
Id3String
()
noexcept
{
free
(
p
);
}
Id3String
(
const
Id3String
&
)
=
delete
;
Id3String
&
operator
=
(
const
Id3String
&
)
=
delete
;
static
Id3String
FromUCS4
(
const
id3_ucs4_t
*
ucs4
)
noexcept
{
return
id3_ucs4_utf8duplicate
(
ucs4
);
}
operator
bool
()
const
noexcept
{
return
p
!=
nullptr
;
}
char
*
c_str
()
noexcept
{
return
(
char
*
)
p
;
}
const
char
*
c_str
()
const
noexcept
{
return
(
const
char
*
)
p
;
}
};
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