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
33a4dbe1
Commit
33a4dbe1
authored
Apr 12, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Util: use class AllocatedArray
parent
60f32d0b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
27 deletions
+19
-27
Collate.cxx
src/lib/icu/Collate.cxx
+6
-12
Converter.cxx
src/lib/icu/Converter.cxx
+2
-3
Util.cxx
src/lib/icu/Util.cxx
+8
-8
Util.hxx
src/lib/icu/Util.hxx
+3
-4
No files found.
src/lib/icu/Collate.cxx
View file @
33a4dbe1
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
#ifdef HAVE_ICU
#ifdef HAVE_ICU
#include "Util.hxx"
#include "Util.hxx"
#include "Error.hxx"
#include "Error.hxx"
#include "util/
WritableBuffer
.hxx"
#include "util/
AllocatedArray
.hxx"
#include "util/ConstBuffer.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
...
@@ -99,15 +99,10 @@ IcuCollate(const char *a, const char *b)
...
@@ -99,15 +99,10 @@ IcuCollate(const char *a, const char *b)
const
auto
au
=
UCharFromUTF8
(
a
);
const
auto
au
=
UCharFromUTF8
(
a
);
const
auto
bu
=
UCharFromUTF8
(
b
);
const
auto
bu
=
UCharFromUTF8
(
b
);
int
result
=
!
au
.
IsNull
()
&&
!
bu
.
IsNull
()
return
!
au
.
IsNull
()
&&
!
bu
.
IsNull
()
?
(
int
)
ucol_strcoll
(
collator
,
au
.
data
,
au
.
size
,
?
(
int
)
ucol_strcoll
(
collator
,
au
.
begin
(),
au
.
size
()
,
bu
.
data
,
bu
.
size
)
bu
.
begin
(),
bu
.
size
()
)
:
strcasecmp
(
a
,
b
);
:
strcasecmp
(
a
,
b
);
delete
[]
au
.
data
;
delete
[]
bu
.
data
;
return
result
;
#endif
#endif
#elif defined(WIN32)
#elif defined(WIN32)
...
@@ -149,15 +144,14 @@ IcuCaseFold(const char *src)
...
@@ -149,15 +144,14 @@ IcuCaseFold(const char *src)
if
(
u
.
IsNull
())
if
(
u
.
IsNull
())
return
AllocatedString
<>::
Duplicate
(
src
);
return
AllocatedString
<>::
Duplicate
(
src
);
size_t
folded_capacity
=
u
.
size
*
2u
;
size_t
folded_capacity
=
u
.
size
()
*
2u
;
UChar
*
folded
=
new
UChar
[
folded_capacity
];
UChar
*
folded
=
new
UChar
[
folded_capacity
];
UErrorCode
error_code
=
U_ZERO_ERROR
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
size_t
folded_length
=
u_strFoldCase
(
folded
,
folded_capacity
,
size_t
folded_length
=
u_strFoldCase
(
folded
,
folded_capacity
,
u
.
data
,
u
.
size
,
u
.
begin
(),
u
.
size
()
,
U_FOLD_CASE_DEFAULT
,
U_FOLD_CASE_DEFAULT
,
&
error_code
);
&
error_code
);
delete
[]
u
.
data
;
if
(
folded_length
==
0
||
error_code
!=
U_ZERO_ERROR
)
{
if
(
folded_length
==
0
||
error_code
!=
U_ZERO_ERROR
)
{
delete
[]
folded
;
delete
[]
folded
;
return
AllocatedString
<>::
Duplicate
(
src
);
return
AllocatedString
<>::
Duplicate
(
src
);
...
...
src/lib/icu/Converter.cxx
View file @
33a4dbe1
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Macros.hxx"
#include "util/Macros.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedString.hxx"
#include "util/
WritableBuffer
.hxx"
#include "util/
AllocatedArray
.hxx"
#include "util/ConstBuffer.hxx"
#include "util/ConstBuffer.hxx"
#include <string.h>
#include <string.h>
...
@@ -142,13 +142,12 @@ IcuConverter::FromUTF8(const char *s) const
...
@@ -142,13 +142,12 @@ IcuConverter::FromUTF8(const char *s) const
// TODO: dynamic buffer?
// TODO: dynamic buffer?
char
buffer
[
4096
],
*
target
=
buffer
;
char
buffer
[
4096
],
*
target
=
buffer
;
const
UChar
*
source
=
u
.
data
;
const
UChar
*
source
=
u
.
begin
()
;
UErrorCode
code
=
U_ZERO_ERROR
;
UErrorCode
code
=
U_ZERO_ERROR
;
ucnv_fromUnicode
(
converter
,
&
target
,
buffer
+
ARRAY_SIZE
(
buffer
),
ucnv_fromUnicode
(
converter
,
&
target
,
buffer
+
ARRAY_SIZE
(
buffer
),
&
source
,
u
.
end
(),
&
source
,
u
.
end
(),
nullptr
,
true
,
&
code
);
nullptr
,
true
,
&
code
);
delete
[]
u
.
data
;
if
(
code
!=
U_ZERO_ERROR
)
if
(
code
!=
U_ZERO_ERROR
)
return
nullptr
;
return
nullptr
;
...
...
src/lib/icu/Util.cxx
View file @
33a4dbe1
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "config.h"
#include "Util.hxx"
#include "Util.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedArray.hxx"
#include "util/WritableBuffer.hxx"
#include "util/WritableBuffer.hxx"
#include "util/ConstBuffer.hxx"
#include "util/ConstBuffer.hxx"
...
@@ -28,26 +29,25 @@
...
@@ -28,26 +29,25 @@
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
WritableBuffer
<
UChar
>
AllocatedArray
<
UChar
>
UCharFromUTF8
(
const
char
*
src
)
UCharFromUTF8
(
const
char
*
src
)
{
{
assert
(
src
!=
nullptr
);
assert
(
src
!=
nullptr
);
const
size_t
src_length
=
strlen
(
src
);
const
size_t
src_length
=
strlen
(
src
);
const
size_t
dest_capacity
=
src_length
;
const
size_t
dest_capacity
=
src_length
;
UChar
*
dest
=
new
UChar
[
dest_capacity
]
;
AllocatedArray
<
UChar
>
dest
(
dest_capacity
)
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
int32_t
dest_length
;
int32_t
dest_length
;
u_strFromUTF8
(
dest
,
dest_capacity
,
&
dest_length
,
u_strFromUTF8
(
dest
.
begin
()
,
dest_capacity
,
&
dest_length
,
src
,
src_length
,
src
,
src_length
,
&
error_code
);
&
error_code
);
if
(
U_FAILURE
(
error_code
))
{
if
(
U_FAILURE
(
error_code
))
delete
[]
dest
;
return
{};
return
nullptr
;
}
return
{
dest
,
size_t
(
dest_length
)
};
dest
.
SetSize
(
dest_length
);
return
dest
;
}
}
AllocatedString
<>
AllocatedString
<>
...
...
src/lib/icu/Util.hxx
View file @
33a4dbe1
...
@@ -24,15 +24,14 @@
...
@@ -24,15 +24,14 @@
#include <unicode/utypes.h>
#include <unicode/utypes.h>
template
<
typename
T
>
struct
WritableBuffer
;
template
<
typename
T
>
struct
ConstBuffer
;
template
<
typename
T
>
struct
ConstBuffer
;
template
<
typename
T
>
class
AllocatedArray
;
template
<
typename
T
>
class
AllocatedString
;
template
<
typename
T
>
class
AllocatedString
;
/**
/**
* Wrapper for u_strFromUTF8(). The returned pointer must be freed
* Wrapper for u_strFromUTF8().
* with delete[].
*/
*/
WritableBuffer
<
UChar
>
AllocatedArray
<
UChar
>
UCharFromUTF8
(
const
char
*
src
);
UCharFromUTF8
(
const
char
*
src
);
/**
/**
...
...
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