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
c70b63c1
Commit
c70b63c1
authored
Jan 14, 2021
by
Max Kellermann
Committed by
Max Kellermann
Jan 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/AllocatedString: rename to BasicAllocatedString
To make things simpler, AllocatedString is now a non-template class.
parent
1b89b4ef
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
73 additions
and
64 deletions
+73
-64
SidplayDecoderPlugin.cxx
src/decoder/plugins/SidplayDecoderPlugin.cxx
+8
-8
NarrowPath.hxx
src/fs/NarrowPath.hxx
+1
-1
CaseFold.cxx
src/lib/icu/CaseFold.cxx
+4
-4
CaseFold.hxx
src/lib/icu/CaseFold.hxx
+2
-2
Collate.cxx
src/lib/icu/Collate.cxx
+1
-1
Compare.cxx
src/lib/icu/Compare.cxx
+1
-1
Compare.hxx
src/lib/icu/Compare.hxx
+2
-2
Converter.cxx
src/lib/icu/Converter.cxx
+5
-5
Converter.hxx
src/lib/icu/Converter.hxx
+3
-3
Util.cxx
src/lib/icu/Util.cxx
+2
-2
Util.hxx
src/lib/icu/Util.hxx
+2
-2
Win32.cxx
src/lib/icu/Win32.cxx
+4
-4
Win32.hxx
src/lib/icu/Win32.hxx
+4
-3
WasapiOutputPlugin.cxx
src/output/plugins/WasapiOutputPlugin.cxx
+1
-1
HttpdClient.cxx
src/output/plugins/httpd/HttpdClient.cxx
+1
-1
IcyMetaDataServer.cxx
src/output/plugins/httpd/IcyMetaDataServer.cxx
+2
-2
IcyMetaDataServer.hxx
src/output/plugins/httpd/IcyMetaDataServer.hxx
+2
-2
AllocatedString.hxx
src/util/AllocatedString.hxx
+22
-14
FormatString.cxx
src/util/FormatString.cxx
+3
-3
FormatString.hxx
src/util/FormatString.hxx
+3
-3
No files found.
src/decoder/plugins/SidplayDecoderPlugin.cxx
View file @
c70b63c1
...
...
@@ -456,7 +456,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
}
while
(
cmd
!=
DecoderCommand
::
STOP
);
}
static
AllocatedString
<
char
>
static
AllocatedString
Windows1252ToUTF8
(
const
char
*
s
)
noexcept
{
#ifdef HAVE_ICU_CONVERTER
...
...
@@ -469,9 +469,9 @@ Windows1252ToUTF8(const char *s) noexcept
* Fallback to not transcoding windows-1252 to utf-8, that may result
* in invalid utf-8 unless nonprintable characters are replaced.
*/
auto
t
=
AllocatedString
<
char
>
::
Duplicate
(
s
);
auto
t
=
AllocatedString
::
Duplicate
(
s
);
for
(
size_t
i
=
0
;
t
[
i
]
!=
AllocatedString
<
char
>
::
SENTINEL
;
i
++
)
for
(
size_t
i
=
0
;
t
[
i
]
!=
AllocatedString
::
SENTINEL
;
i
++
)
if
(
!
IsPrintableASCII
(
t
[
i
]))
t
[
i
]
=
'?'
;
...
...
@@ -479,7 +479,7 @@ Windows1252ToUTF8(const char *s) noexcept
}
gcc_pure
static
AllocatedString
<
char
>
static
AllocatedString
GetInfoString
(
const
SidTuneInfo
&
info
,
unsigned
i
)
noexcept
{
#ifdef HAVE_SIDPLAYFP
...
...
@@ -496,7 +496,7 @@ GetInfoString(const SidTuneInfo &info, unsigned i) noexcept
}
gcc_pure
static
AllocatedString
<
char
>
static
AllocatedString
GetDateString
(
const
SidTuneInfo
&
info
)
noexcept
{
/*
...
...
@@ -507,12 +507,12 @@ GetDateString(const SidTuneInfo &info) noexcept
* author or group> may be for example Rob Hubbard. A full field
* may be for example "1987 Rob Hubbard".
*/
AllocatedString
<
char
>
release
=
GetInfoString
(
info
,
2
);
AllocatedString
release
=
GetInfoString
(
info
,
2
);
/* Keep the <year> part only for the date. */
for
(
size_t
i
=
0
;
release
[
i
]
!=
AllocatedString
<
char
>
::
SENTINEL
;
i
++
)
for
(
size_t
i
=
0
;
release
[
i
]
!=
AllocatedString
::
SENTINEL
;
i
++
)
if
(
std
::
isspace
(
release
[
i
]))
{
release
[
i
]
=
AllocatedString
<
char
>
::
SENTINEL
;
release
[
i
]
=
AllocatedString
::
SENTINEL
;
break
;
}
...
...
src/fs/NarrowPath.hxx
View file @
c70b63c1
...
...
@@ -36,7 +36,7 @@
*/
class
NarrowPath
{
#ifdef _UNICODE
using
Value
=
AllocatedString
<>
;
using
Value
=
AllocatedString
;
#else
using
Value
=
StringPointer
<>
;
#endif
...
...
src/lib/icu/CaseFold.cxx
View file @
c70b63c1
...
...
@@ -38,13 +38,13 @@
#include <string.h>
AllocatedString
<>
AllocatedString
IcuCaseFold
(
std
::
string_view
src
)
noexcept
try
{
#ifdef HAVE_ICU
const
auto
u
=
UCharFromUTF8
(
src
);
if
(
u
.
IsNull
())
return
AllocatedString
<>
::
Duplicate
(
src
);
return
AllocatedString
::
Duplicate
(
src
);
AllocatedArray
<
UChar
>
folded
(
u
.
size
()
*
2U
);
...
...
@@ -54,7 +54,7 @@ try {
U_FOLD_CASE_DEFAULT
,
&
error_code
);
if
(
folded_length
==
0
||
error_code
!=
U_ZERO_ERROR
)
return
AllocatedString
<>
::
Duplicate
(
src
);
return
AllocatedString
::
Duplicate
(
src
);
folded
.
SetSize
(
folded_length
);
return
UCharToUTF8
({
folded
.
begin
(),
folded
.
size
()});
...
...
@@ -63,7 +63,7 @@ try {
#error not implemented
#endif
}
catch
(...)
{
return
AllocatedString
<>
::
Duplicate
(
src
);
return
AllocatedString
::
Duplicate
(
src
);
}
#endif
/* HAVE_ICU_CASE_FOLD */
src/lib/icu/CaseFold.hxx
View file @
c70b63c1
...
...
@@ -27,9 +27,9 @@
#include <string_view>
template
<
typename
T
>
class
AllocatedString
;
class
AllocatedString
;
AllocatedString
<
char
>
AllocatedString
IcuCaseFold
(
std
::
string_view
src
)
noexcept
;
#endif
...
...
src/lib/icu/Collate.cxx
View file @
c70b63c1
...
...
@@ -88,7 +88,7 @@ IcuCollate(std::string_view a, std::string_view b) noexcept
b
.
data
(),
b
.
size
(),
&
code
);
#elif defined(_WIN32)
AllocatedString
<
wchar_t
>
wa
=
nullptr
,
wb
=
nullptr
;
Basic
AllocatedString
<
wchar_t
>
wa
=
nullptr
,
wb
=
nullptr
;
try
{
wa
=
MultiByteToWideChar
(
CP_UTF8
,
a
);
...
...
src/lib/icu/Compare.cxx
View file @
c70b63c1
...
...
@@ -46,7 +46,7 @@ IcuCompare::IcuCompare(std::string_view _needle) noexcept
#else
IcuCompare
::
IcuCompare
(
std
::
string_view
_needle
)
noexcept
:
needle
(
AllocatedString
<>
::
Duplicate
(
_needle
))
{}
:
needle
(
AllocatedString
::
Duplicate
(
_needle
))
{}
#endif
...
...
src/lib/icu/Compare.hxx
View file @
c70b63c1
...
...
@@ -38,9 +38,9 @@ class IcuCompare {
#ifdef _WIN32
/* Windows API functions work with wchar_t strings, so let's
cache the MultiByteToWideChar() result for performance */
AllocatedString
<
wchar_t
>
needle
;
Basic
AllocatedString
<
wchar_t
>
needle
;
#else
AllocatedString
<>
needle
;
AllocatedString
needle
;
#endif
public
:
...
...
src/lib/icu/Converter.cxx
View file @
c70b63c1
...
...
@@ -77,7 +77,7 @@ IcuConverter::Create(const char *charset)
#ifdef HAVE_ICU
#elif defined(HAVE_ICONV)
static
AllocatedString
<
char
>
static
AllocatedString
DoConvert
(
iconv_t
conv
,
std
::
string_view
src
)
{
// TODO: dynamic buffer?
...
...
@@ -95,12 +95,12 @@ DoConvert(iconv_t conv, std::string_view src)
if
(
in_left
>
0
)
throw
std
::
runtime_error
(
"Charset conversion failed"
);
return
AllocatedString
<>
::
Duplicate
({
buffer
,
sizeof
(
buffer
)
-
out_left
});
return
AllocatedString
::
Duplicate
({
buffer
,
sizeof
(
buffer
)
-
out_left
});
}
#endif
AllocatedString
<
char
>
AllocatedString
IcuConverter
::
ToUTF8
(
std
::
string_view
s
)
const
{
#ifdef HAVE_ICU
...
...
@@ -128,7 +128,7 @@ IcuConverter::ToUTF8(std::string_view s) const
#endif
}
AllocatedString
<
char
>
AllocatedString
IcuConverter
::
FromUTF8
(
std
::
string_view
s
)
const
{
#ifdef HAVE_ICU
...
...
@@ -151,7 +151,7 @@ IcuConverter::FromUTF8(std::string_view s) const
throw
std
::
runtime_error
(
FormatString
(
"Failed to convert from Unicode: %s"
,
u_errorName
(
code
)).
c_str
());
return
AllocatedString
<>
::
Duplicate
({
buffer
,
size_t
(
target
-
buffer
)});
return
AllocatedString
::
Duplicate
({
buffer
,
size_t
(
target
-
buffer
)});
#elif defined(HAVE_ICONV)
return
DoConvert
(
from_utf8
,
s
);
...
...
src/lib/icu/Converter.hxx
View file @
c70b63c1
...
...
@@ -40,7 +40,7 @@
struct
UConverter
;
#endif
template
<
typename
T
>
class
AllocatedString
;
class
AllocatedString
;
/**
* This class can convert strings with a certain character set to and
...
...
@@ -85,7 +85,7 @@ public:
* Throws std::runtime_error on error.
*/
gcc_nonnull_all
AllocatedString
<
char
>
ToUTF8
(
std
::
string_view
s
)
const
;
AllocatedString
ToUTF8
(
std
::
string_view
s
)
const
;
/**
* Convert the string from UTF-8.
...
...
@@ -93,7 +93,7 @@ public:
* Throws std::runtime_error on error.
*/
gcc_nonnull_all
AllocatedString
<
char
>
FromUTF8
(
std
::
string_view
s
)
const
;
AllocatedString
FromUTF8
(
std
::
string_view
s
)
const
;
};
#endif
...
...
src/lib/icu/Util.cxx
View file @
c70b63c1
...
...
@@ -48,7 +48,7 @@ UCharFromUTF8(std::string_view src)
return
dest
;
}
AllocatedString
<>
AllocatedString
UCharToUTF8
(
std
::
basic_string_view
<
UChar
>
src
)
{
/* worst-case estimate */
...
...
@@ -65,5 +65,5 @@ UCharToUTF8(std::basic_string_view<UChar> src)
throw
std
::
runtime_error
(
u_errorName
(
error_code
));
dest
[
dest_length
]
=
0
;
return
AllocatedString
<>
::
Donate
(
dest
.
release
());
return
AllocatedString
::
Donate
(
dest
.
release
());
}
src/lib/icu/Util.hxx
View file @
c70b63c1
...
...
@@ -25,7 +25,7 @@
#include <string_view>
template
<
typename
T
>
class
AllocatedArray
;
template
<
typename
T
>
class
AllocatedString
;
class
AllocatedString
;
/**
* Wrapper for u_strFromUTF8().
...
...
@@ -40,7 +40,7 @@ UCharFromUTF8(std::string_view src);
*
* Throws std::runtime_error on error.
*/
AllocatedString
<
char
>
AllocatedString
UCharToUTF8
(
std
::
basic_string_view
<
UChar
>
src
);
#endif
src/lib/icu/Win32.cxx
View file @
c70b63c1
...
...
@@ -25,7 +25,7 @@
#include <windows.h>
AllocatedString
<
char
>
AllocatedString
WideCharToMultiByte
(
unsigned
code_page
,
std
::
wstring_view
src
)
{
int
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
.
data
(),
src
.
size
(),
...
...
@@ -42,10 +42,10 @@ WideCharToMultiByte(unsigned code_page, std::wstring_view src)
throw
MakeLastError
(
"Failed to convert from Unicode"
);
buffer
[
length
]
=
'\0'
;
return
AllocatedString
<
char
>
::
Donate
(
buffer
.
release
());
return
AllocatedString
::
Donate
(
buffer
.
release
());
}
AllocatedString
<
wchar_t
>
Basic
AllocatedString
<
wchar_t
>
MultiByteToWideChar
(
unsigned
code_page
,
std
::
string_view
src
)
{
int
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
.
data
(),
src
.
size
(),
...
...
@@ -60,5 +60,5 @@ MultiByteToWideChar(unsigned code_page, std::string_view src)
throw
MakeLastError
(
"Failed to convert to Unicode"
);
buffer
[
length
]
=
L'\0'
;
return
AllocatedString
<
wchar_t
>::
Donate
(
buffer
.
release
());
return
Basic
AllocatedString
<
wchar_t
>::
Donate
(
buffer
.
release
());
}
src/lib/icu/Win32.hxx
View file @
c70b63c1
...
...
@@ -24,20 +24,21 @@
#include <string_view>
template
<
typename
T
>
class
AllocatedString
;
class
AllocatedString
;
template
<
typename
T
>
class
BasicAllocatedString
;
/**
* Throws std::system_error on error.
*/
gcc_pure
gcc_nonnull_all
AllocatedString
<
char
>
AllocatedString
WideCharToMultiByte
(
unsigned
code_page
,
std
::
wstring_view
src
);
/**
* Throws std::system_error on error.
*/
gcc_pure
gcc_nonnull_all
AllocatedString
<
wchar_t
>
Basic
AllocatedString
<
wchar_t
>
MultiByteToWideChar
(
unsigned
code_page
,
std
::
string_view
src
);
#endif
src/output/plugins/WasapiOutputPlugin.cxx
View file @
c70b63c1
...
...
@@ -193,7 +193,7 @@ private:
bool
is_exclusive
;
bool
enumerate_devices
;
std
::
string
device_config
;
std
::
vector
<
std
::
pair
<
unsigned
int
,
AllocatedString
<
char
>
>>
device_desc
;
std
::
vector
<
std
::
pair
<
unsigned
int
,
AllocatedString
>>
device_desc
;
std
::
shared_ptr
<
WinEvent
>
event
;
std
::
optional
<
COM
>
com
;
ComPtr
<
IMMDeviceEnumerator
>
enumerator
;
...
...
src/output/plugins/httpd/HttpdClient.cxx
View file @
c70b63c1
...
...
@@ -136,7 +136,7 @@ bool
HttpdClient
::
SendResponse
()
noexcept
{
char
buffer
[
1024
];
AllocatedString
<>
allocated
=
nullptr
;
AllocatedString
allocated
=
nullptr
;
const
char
*
response
;
assert
(
state
==
State
::
RESPONSE
);
...
...
src/output/plugins/httpd/IcyMetaDataServer.cxx
View file @
c70b63c1
...
...
@@ -27,7 +27,7 @@
#include <string.h>
AllocatedString
<>
AllocatedString
icy_server_metadata_header
(
const
char
*
name
,
const
char
*
genre
,
const
char
*
url
,
const
char
*
content_type
,
int
metaint
)
noexcept
...
...
@@ -54,7 +54,7 @@ icy_server_metadata_header(const char *name,
content_type
);
}
static
AllocatedString
<>
static
AllocatedString
icy_server_metadata_string
(
const
char
*
stream_title
,
const
char
*
stream_url
)
noexcept
{
...
...
src/output/plugins/httpd/IcyMetaDataServer.hxx
View file @
c70b63c1
...
...
@@ -24,9 +24,9 @@
#include "tag/Type.h"
struct
Tag
;
template
<
typename
T
>
class
AllocatedString
;
class
AllocatedString
;
AllocatedString
<
char
>
AllocatedString
icy_server_metadata_header
(
const
char
*
name
,
const
char
*
genre
,
const
char
*
url
,
const
char
*
content_type
,
int
metaint
)
noexcept
;
...
...
src/util/AllocatedString.hxx
View file @
c70b63c1
/*
* Copyright 2015-202
0
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2015-202
1
Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -41,8 +41,8 @@
*
* Unlike std::string, this object can hold a "nullptr" special value.
*/
template
<
typename
T
=
char
>
class
AllocatedString
{
template
<
typename
T
>
class
Basic
AllocatedString
{
public
:
using
value_type
=
typename
StringPointer
<
T
>::
value_type
;
using
reference
=
typename
StringPointer
<
T
>::
reference
;
...
...
@@ -57,41 +57,41 @@ public:
private
:
pointer
value
;
explicit
AllocatedString
(
pointer
_value
)
noexcept
explicit
Basic
AllocatedString
(
pointer
_value
)
noexcept
:
value
(
_value
)
{}
public
:
AllocatedString
(
std
::
nullptr_t
n
)
noexcept
Basic
AllocatedString
(
std
::
nullptr_t
n
)
noexcept
:
value
(
n
)
{}
AllocatedString
(
AllocatedString
&&
src
)
noexcept
BasicAllocatedString
(
Basic
AllocatedString
&&
src
)
noexcept
:
value
(
src
.
Steal
())
{}
~
AllocatedString
()
noexcept
{
~
Basic
AllocatedString
()
noexcept
{
delete
[]
value
;
}
static
AllocatedString
Donate
(
pointer
value
)
noexcept
{
return
AllocatedString
(
value
);
static
Basic
AllocatedString
Donate
(
pointer
value
)
noexcept
{
return
Basic
AllocatedString
(
value
);
}
static
AllocatedString
Null
()
noexcept
{
static
Basic
AllocatedString
Null
()
noexcept
{
return
nullptr
;
}
static
AllocatedString
Empty
()
{
static
Basic
AllocatedString
Empty
()
{
auto
p
=
new
value_type
[
1
];
p
[
0
]
=
SENTINEL
;
return
Donate
(
p
);
}
static
AllocatedString
Duplicate
(
string_view
src
)
{
static
Basic
AllocatedString
Duplicate
(
string_view
src
)
{
auto
p
=
new
value_type
[
src
.
size
()
+
1
];
*
std
::
copy_n
(
src
.
data
(),
src
.
size
(),
p
)
=
SENTINEL
;
return
Donate
(
p
);
}
AllocatedString
&
operator
=
(
AllocatedString
&&
src
)
noexcept
{
BasicAllocatedString
&
operator
=
(
Basic
AllocatedString
&&
src
)
noexcept
{
std
::
swap
(
value
,
src
.
value
);
return
*
this
;
}
...
...
@@ -136,9 +136,17 @@ public:
return
std
::
exchange
(
value
,
nullptr
);
}
AllocatedString
Clone
()
const
{
Basic
AllocatedString
Clone
()
const
{
return
Duplicate
(
*
this
);
}
};
class
AllocatedString
:
public
BasicAllocatedString
<
char
>
{
public
:
using
BasicAllocatedString
::
BasicAllocatedString
;
AllocatedString
(
BasicAllocatedString
<
value_type
>
&&
src
)
noexcept
:
BasicAllocatedString
(
std
::
move
(
src
))
{}
};
#endif
src/util/FormatString.cxx
View file @
c70b63c1
...
...
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
AllocatedString
<>
AllocatedString
FormatStringV
(
const
char
*
fmt
,
std
::
va_list
args
)
noexcept
{
std
::
va_list
tmp
;
...
...
@@ -37,10 +37,10 @@ FormatStringV(const char *fmt, std::va_list args) noexcept
char
*
buffer
=
new
char
[
length
+
1
];
vsnprintf
(
buffer
,
length
+
1
,
fmt
,
args
);
return
AllocatedString
<>
::
Donate
(
buffer
);
return
AllocatedString
::
Donate
(
buffer
);
}
AllocatedString
<>
AllocatedString
FormatString
(
const
char
*
fmt
,
...)
noexcept
{
std
::
va_list
args
;
...
...
src/util/FormatString.hxx
View file @
c70b63c1
...
...
@@ -24,20 +24,20 @@
#include <cstdarg>
template
<
typename
T
>
class
AllocatedString
;
class
AllocatedString
;
/**
* Format into an #AllocatedString.
*/
gcc_nonnull_all
AllocatedString
<
char
>
AllocatedString
FormatStringV
(
const
char
*
fmt
,
std
::
va_list
args
)
noexcept
;
/**
* Format into an #AllocatedString.
*/
gcc_nonnull
(
1
)
gcc_printf
(
1
,
2
)
AllocatedString
<
char
>
AllocatedString
FormatString
(
const
char
*
fmt
,
...)
noexcept
;
#endif
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